forked from len0rd/rockbox
Move WavPack metadata parsing to its own file and add handling of non-standard sampling rates
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@14289 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
53095684f7
commit
bcf97a4801
8 changed files with 148 additions and 61 deletions
|
@ -121,6 +121,7 @@ metadata/sid.c
|
||||||
metadata/spc.c
|
metadata/spc.c
|
||||||
metadata/vorbis.c
|
metadata/vorbis.c
|
||||||
metadata/wave.c
|
metadata/wave.c
|
||||||
|
metadata/wavpack.c
|
||||||
#endif
|
#endif
|
||||||
#ifdef HAVE_TAGCACHE
|
#ifdef HAVE_TAGCACHE
|
||||||
tagcache.c
|
tagcache.c
|
||||||
|
|
|
@ -102,6 +102,9 @@ int process_metadata (WavpackContext *wpc, WavpackMetadata *wpmd)
|
||||||
case ID_CHANNEL_INFO:
|
case ID_CHANNEL_INFO:
|
||||||
return read_channel_info (wpc, wpmd);
|
return read_channel_info (wpc, wpmd);
|
||||||
|
|
||||||
|
case ID_SAMPLE_RATE:
|
||||||
|
return read_sample_rate (wpc, wpmd);
|
||||||
|
|
||||||
case ID_CONFIG_BLOCK:
|
case ID_CONFIG_BLOCK:
|
||||||
return read_config_info (wpc, wpmd);
|
return read_config_info (wpc, wpmd);
|
||||||
|
|
||||||
|
|
|
@ -270,6 +270,22 @@ int read_config_info (WavpackContext *wpc, WavpackMetadata *wpmd)
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Read non-standard sampling rate from metadata.
|
||||||
|
|
||||||
|
int read_sample_rate (WavpackContext *wpc, WavpackMetadata *wpmd)
|
||||||
|
{
|
||||||
|
int bytecnt = wpmd->byte_length;
|
||||||
|
uchar *byteptr = wpmd->data;
|
||||||
|
|
||||||
|
if (bytecnt == 3) {
|
||||||
|
wpc->config.sample_rate = (int32_t) *byteptr++;
|
||||||
|
wpc->config.sample_rate |= (int32_t) *byteptr++ << 8;
|
||||||
|
wpc->config.sample_rate |= (int32_t) *byteptr++ << 16;
|
||||||
|
}
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
// This monster actually unpacks the WavPack bitstream(s) into the specified
|
// This monster actually unpacks the WavPack bitstream(s) into the specified
|
||||||
// buffer as 32-bit integers or floats (depending on orignal data). Lossy
|
// buffer as 32-bit integers or floats (depending on orignal data). Lossy
|
||||||
// samples will be clipped to their original limits (i.e. 8-bit samples are
|
// samples will be clipped to their original limits (i.e. 8-bit samples are
|
||||||
|
|
|
@ -114,6 +114,7 @@ typedef struct {
|
||||||
#define ID_CUESHEET (ID_OPTIONAL_DATA | 0x4)
|
#define ID_CUESHEET (ID_OPTIONAL_DATA | 0x4)
|
||||||
#define ID_CONFIG_BLOCK (ID_OPTIONAL_DATA | 0x5)
|
#define ID_CONFIG_BLOCK (ID_OPTIONAL_DATA | 0x5)
|
||||||
#define ID_MD5_CHECKSUM (ID_OPTIONAL_DATA | 0x6)
|
#define ID_MD5_CHECKSUM (ID_OPTIONAL_DATA | 0x6)
|
||||||
|
#define ID_SAMPLE_RATE (ID_OPTIONAL_DATA | 0x7)
|
||||||
|
|
||||||
///////////////////////// WavPack Configuration ///////////////////////////////
|
///////////////////////// WavPack Configuration ///////////////////////////////
|
||||||
|
|
||||||
|
@ -364,6 +365,7 @@ int read_float_info (WavpackStream *wps, WavpackMetadata *wpmd);
|
||||||
int read_int32_info (WavpackStream *wps, WavpackMetadata *wpmd);
|
int read_int32_info (WavpackStream *wps, WavpackMetadata *wpmd);
|
||||||
int read_channel_info (WavpackContext *wpc, WavpackMetadata *wpmd);
|
int read_channel_info (WavpackContext *wpc, WavpackMetadata *wpmd);
|
||||||
int read_config_info (WavpackContext *wpc, WavpackMetadata *wpmd);
|
int read_config_info (WavpackContext *wpc, WavpackMetadata *wpmd);
|
||||||
|
int read_sample_rate (WavpackContext *wpc, WavpackMetadata *wpmd);
|
||||||
int32_t unpack_samples (WavpackContext *wpc, int32_t *buffer, uint32_t sample_count);
|
int32_t unpack_samples (WavpackContext *wpc, int32_t *buffer, uint32_t sample_count);
|
||||||
int check_crc_error (WavpackContext *wpc);
|
int check_crc_error (WavpackContext *wpc);
|
||||||
|
|
||||||
|
|
|
@ -57,9 +57,6 @@ enum codec_status codec_main(void)
|
||||||
while (!*ci->taginfo_ready && !ci->stop_codec)
|
while (!*ci->taginfo_ready && !ci->stop_codec)
|
||||||
ci->sleep(1);
|
ci->sleep(1);
|
||||||
|
|
||||||
ci->configure(DSP_SWITCH_FREQUENCY, ci->id3->frequency);
|
|
||||||
codec_set_replaygain(ci->id3);
|
|
||||||
|
|
||||||
/* Create a decoder instance */
|
/* Create a decoder instance */
|
||||||
wpc = WavpackOpenFileInput (read_callback, error);
|
wpc = WavpackOpenFileInput (read_callback, error);
|
||||||
|
|
||||||
|
@ -68,6 +65,8 @@ enum codec_status codec_main(void)
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ci->configure(DSP_SWITCH_FREQUENCY, WavpackGetSampleRate (wpc));
|
||||||
|
codec_set_replaygain(ci->id3);
|
||||||
bps = WavpackGetBytesPerSample (wpc);
|
bps = WavpackGetBytesPerSample (wpc);
|
||||||
nchans = WavpackGetReducedChannels (wpc);
|
nchans = WavpackGetReducedChannels (wpc);
|
||||||
ci->configure(DSP_SET_STEREO_MODE, nchans == 2 ? STEREO_INTERLEAVED : STEREO_MONO);
|
ci->configure(DSP_SET_STEREO_MODE, nchans == 2 ? STEREO_INTERLEAVED : STEREO_MONO);
|
||||||
|
|
|
@ -51,12 +51,6 @@ static const unsigned short a52_441framesizes[] =
|
||||||
1254 * 2, 1393 * 2, 1394 * 2
|
1254 * 2, 1393 * 2, 1394 * 2
|
||||||
};
|
};
|
||||||
|
|
||||||
static const long wavpack_sample_rates [] =
|
|
||||||
{
|
|
||||||
6000, 8000, 9600, 11025, 12000, 16000, 22050, 24000,
|
|
||||||
32000, 44100, 48000, 64000, 88200, 96000, 192000
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif /* CONFIG_CODEC == SWCODEC */
|
#endif /* CONFIG_CODEC == SWCODEC */
|
||||||
|
|
||||||
|
|
||||||
|
@ -179,59 +173,8 @@ bool get_metadata(struct track_info* track, int fd, const char* trackname,
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case AFMT_WAVPACK:
|
case AFMT_WAVPACK:
|
||||||
/* A simple parser to read basic information from a WavPack file. This
|
if (!get_wavpack_metadata(fd, &(track->id3)))
|
||||||
* now works with self-extrating WavPack files. This no longer fails on
|
|
||||||
* WavPack files containing floating-point audio data because these are
|
|
||||||
* now converted to standard Rockbox format in the decoder.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* Use the trackname part of the id3 structure as a temporary buffer */
|
|
||||||
buf = (unsigned char *)track->id3.path;
|
|
||||||
|
|
||||||
for (i = 0; i < 256; ++i) {
|
|
||||||
|
|
||||||
/* at every 256 bytes into file, try to read a WavPack header */
|
|
||||||
|
|
||||||
if ((lseek(fd, i * 256, SEEK_SET) < 0) || (read(fd, buf, 32) < 32))
|
|
||||||
{
|
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
/* if valid WavPack 4 header version & not floating data, break */
|
|
||||||
|
|
||||||
if (memcmp (buf, "wvpk", 4) == 0 && buf [9] == 4 &&
|
|
||||||
(buf [8] >= 2 && buf [8] <= 0x10))
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (i == 256) {
|
|
||||||
logf ("%s is not a WavPack file\n", trackname);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
track->id3.vbr = true; /* All WavPack files are VBR */
|
|
||||||
track->id3.filesize = filesize (fd);
|
|
||||||
|
|
||||||
if ((buf [20] | buf [21] | buf [22] | buf [23]) &&
|
|
||||||
(buf [12] & buf [13] & buf [14] & buf [15]) != 0xff)
|
|
||||||
{
|
|
||||||
int srindx = ((buf [26] >> 7) & 1) + ((buf [27] << 1) & 14);
|
|
||||||
|
|
||||||
if (srindx == 15)
|
|
||||||
{
|
|
||||||
track->id3.frequency = 44100;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
track->id3.frequency = wavpack_sample_rates[srindx];
|
|
||||||
}
|
|
||||||
|
|
||||||
totalsamples = get_long_le(&buf[12]);
|
|
||||||
track->id3.length = totalsamples / (track->id3.frequency / 100) * 10;
|
|
||||||
track->id3.bitrate = filesize (fd) / (track->id3.length / 8);
|
|
||||||
}
|
|
||||||
|
|
||||||
read_ape_tags(fd, &track->id3); /* use any apetag info we find */
|
read_ape_tags(fd, &track->id3); /* use any apetag info we find */
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -29,4 +29,5 @@ bool get_spc_metadata(int fd, struct mp3entry* id3);
|
||||||
bool get_speex_metadata(int fd, struct mp3entry* id3);
|
bool get_speex_metadata(int fd, struct mp3entry* id3);
|
||||||
bool get_vorbis_metadata(int fd, struct mp3entry* id3);
|
bool get_vorbis_metadata(int fd, struct mp3entry* id3);
|
||||||
bool get_wave_metadata(int fd, struct mp3entry* id3);
|
bool get_wave_metadata(int fd, struct mp3entry* id3);
|
||||||
|
bool get_wavpack_metadata(int fd, struct mp3entry* id3);
|
||||||
bool get_asf_metadata(int fd, struct mp3entry* id3);
|
bool get_asf_metadata(int fd, struct mp3entry* id3);
|
||||||
|
|
122
apps/metadata/wavpack.c
Normal file
122
apps/metadata/wavpack.c
Normal file
|
@ -0,0 +1,122 @@
|
||||||
|
/***************************************************************************
|
||||||
|
* __________ __ ___.
|
||||||
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
||||||
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
||||||
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
||||||
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
||||||
|
* \/ \/ \/ \/ \/
|
||||||
|
* $Id:$
|
||||||
|
*
|
||||||
|
* Copyright (C) 2007 David Bryant
|
||||||
|
*
|
||||||
|
* All files in this archive are subject to the GNU General Public License.
|
||||||
|
* See the file COPYING in the source tree root for full license agreement.
|
||||||
|
*
|
||||||
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||||
|
* KIND, either express or implied.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <ctype.h>
|
||||||
|
#include <inttypes.h>
|
||||||
|
|
||||||
|
#include "system.h"
|
||||||
|
#include "id3.h"
|
||||||
|
#include "metadata_common.h"
|
||||||
|
#include "logf.h"
|
||||||
|
|
||||||
|
#define ID_UNIQUE 0x3f
|
||||||
|
#define ID_LARGE 0x80
|
||||||
|
#define ID_SAMPLE_RATE 0x27
|
||||||
|
|
||||||
|
static const long wavpack_sample_rates [] =
|
||||||
|
{
|
||||||
|
6000, 8000, 9600, 11025, 12000, 16000, 22050, 24000,
|
||||||
|
32000, 44100, 48000, 64000, 88200, 96000, 192000
|
||||||
|
};
|
||||||
|
|
||||||
|
/* A simple parser to read basic information from a WavPack file. This
|
||||||
|
* now works with self-extrating WavPack files and also will scan the
|
||||||
|
* metadata for non-standard sampling rates. This no longer fails on
|
||||||
|
* WavPack files containing floating-point audio data because these are
|
||||||
|
* now converted to standard Rockbox format in the decoder.
|
||||||
|
*/
|
||||||
|
|
||||||
|
bool get_wavpack_metadata(int fd, struct mp3entry* id3)
|
||||||
|
{
|
||||||
|
/* Use the trackname part of the id3 structure as a temporary buffer */
|
||||||
|
unsigned char* buf = (unsigned char *)id3->path;
|
||||||
|
uint32_t totalsamples, blocksamples;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i = 0; i < 256; ++i) {
|
||||||
|
|
||||||
|
/* at every 256 bytes into file, try to read a WavPack header */
|
||||||
|
|
||||||
|
if ((lseek(fd, i * 256, SEEK_SET) < 0) || (read(fd, buf, 32) < 32))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
/* if valid WavPack 4 header version, break */
|
||||||
|
|
||||||
|
if (memcmp (buf, "wvpk", 4) == 0 && buf [9] == 4 &&
|
||||||
|
(buf [8] >= 2 && buf [8] <= 0x10))
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (i == 256) {
|
||||||
|
logf ("Not a WavPack file");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
id3->vbr = true; /* All WavPack files are VBR */
|
||||||
|
id3->filesize = filesize (fd);
|
||||||
|
totalsamples = get_long_le(&buf[12]);
|
||||||
|
blocksamples = get_long_le(&buf[20]);
|
||||||
|
|
||||||
|
if (blocksamples && totalsamples != (uint32_t) -1) {
|
||||||
|
int srindx = ((buf [26] >> 7) & 1) + ((buf [27] << 1) & 14);
|
||||||
|
|
||||||
|
if (srindx == 15) {
|
||||||
|
uint32_t meta_bytes = buf [4] + (buf [5] << 8) + (buf [6] << 16) - 24;
|
||||||
|
uint32_t meta_size;
|
||||||
|
|
||||||
|
id3->frequency = 44100;
|
||||||
|
|
||||||
|
while (meta_bytes >= 6) {
|
||||||
|
if (read(fd, buf, 2) < 2)
|
||||||
|
break;
|
||||||
|
|
||||||
|
if (buf [0] & ID_LARGE) {
|
||||||
|
if (read(fd, buf + 2, 2) < 2)
|
||||||
|
break;
|
||||||
|
|
||||||
|
meta_size = (buf [1] << 1) + (buf [2] << 9) + (buf [3] << 17);
|
||||||
|
meta_bytes -= meta_size + 4;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
meta_size = buf [1] << 1;
|
||||||
|
meta_bytes -= meta_size + 2;
|
||||||
|
|
||||||
|
if ((buf [0] & ID_UNIQUE) == ID_SAMPLE_RATE) {
|
||||||
|
if (meta_size == 4 && read(fd, buf + 2, 4) == 4)
|
||||||
|
id3->frequency = buf [2] + (buf [3] << 8) + (buf [4] << 16);
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (meta_size > 0 && lseek(fd, meta_size, SEEK_CUR) < 0)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
id3->frequency = wavpack_sample_rates[srindx];
|
||||||
|
|
||||||
|
id3->length = ((int64_t) totalsamples * 1000) / id3->frequency;
|
||||||
|
id3->bitrate = filesize (fd) / (id3->length / 8);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue