Initial pass at WavPack codec playback support (and my first commit...)

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@6698 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Dave Bryant 2005-06-13 06:00:35 +00:00
parent 7ac0b350b8
commit 57c6f6e57e
4 changed files with 52 additions and 1 deletions

View file

@ -68,6 +68,7 @@ static volatile bool paused;
#define CODEC_WAV "/.rockbox/codecs/codecwav.rock";
#define CODEC_A52 "/.rockbox/codecs/codeca52.rock";
#define CODEC_MPC "/.rockbox/codecs/codecmpc.rock";
#define CODEC_WAVPACK "/.rockbox/codecs/codecwavpack.rock";
#define AUDIO_DEFAULT_WATERMARK (1024*256)
#define AUDIO_DEFAULT_FILECHUNK (1024*32)
@ -417,6 +418,8 @@ int probe_file_format(const char *filename)
return AFMT_A52;
else if (!strcasecmp("rm", suffix))
return AFMT_REAL;
else if (!strcasecmp("wv", suffix))
return AFMT_WAVPACK;
return AFMT_UNKNOWN;
@ -521,6 +524,10 @@ bool loadcodec(const char *trackname, bool start_play)
logf("Codec: Musepack");
codec_path = CODEC_MPC;
break;
case AFMT_WAVPACK:
logf("Codec: WAVPACK");
codec_path = CODEC_WAVPACK;
break;
default:
logf("Codec: Unsupported");
snprintf(msgbuf, sizeof(msgbuf)-1, "No codec for: %s", trackname);
@ -735,7 +742,6 @@ bool audio_load_track(int offset, bool start_play, int peek_offset)
tracks[track_widx].taginfo_ready = true;
break;
case AFMT_FLAC:
/* A simple parser to read vital metadata from a FLAC file - length, frequency, bitrate etc. */
@ -886,6 +892,48 @@ bool audio_load_track(int offset, bool start_play, int peek_offset)
tracks[track_widx].taginfo_ready = true;
break;
case AFMT_WAVPACK:
/* A simple parser to read basic information from a WavPack file.
* This will fail on WavPack files that don't have the WavPack header
* as the first thing (i.e. self-extracting WavPack files) or WavPack
* files that have so much extra RIFF data stored in the first block
* that they don't have samples (very rare, I would think).
*/
/* Use the trackname part of the id3 structure as a temporary buffer */
buf=tracks[track_widx].id3.path;
lseek(fd, 0, SEEK_SET);
rc = read(fd, buf, 32);
if (rc < 32) {
close(fd);
return false;
}
if (memcmp (buf, "wvpk", 4) != 0 || buf [9] != 4 || buf [8] < 2) {
logf ("%s is not a WavPack file\n", trackname);
close (fd);
return (false);
}
tracks[track_widx].id3.vbr = true; /* All WavPack files are VBR */
tracks[track_widx].id3.filesize = filesize (fd);
tracks[track_widx].id3.frequency = 44100;
if ((buf [20] | buf [21] | buf [22] | buf [23]) &&
(buf [12] & buf [13] & buf [14] & buf [15]) != 0xff) {
totalsamples = (buf[15] << 24) | (buf[14] << 16) | (buf[13] << 8) | buf[12];
tracks[track_widx].id3.length = (totalsamples + 220) / 441 * 10;
tracks[track_widx].id3.bitrate = filesize (fd) /
(tracks[track_widx].id3.length / 8);
}
lseek (fd, 0, SEEK_SET);
strncpy (tracks[track_widx].id3.path, trackname, sizeof (tracks[track_widx].id3.path));
tracks[track_widx].taginfo_ready = true;
break;
/* If we don't know how to read the metadata, just store the filename */
default:
strncpy(tracks[track_widx].id3.path,trackname,sizeof(tracks[track_widx].id3.path));

View file

@ -34,6 +34,7 @@
#define AFMT_A52 0x0400 // A/52 (aka AC3) audio
#define AFMT_REAL 0x0800 // Realaudio
#define AFMT_UNKNOWN 0x1000 // Unknown file format
#define AFMT_WAVPACK 0x2000 // WavPack
#define CODEC_SET_FILEBUF_WATERMARK 1
#define CODEC_SET_FILEBUF_CHUNKSIZE 2

View file

@ -78,6 +78,7 @@ codecflac.c
codecwav.c
codeca52.c
codecmpc.c
codecwavpack.c
#endif
wv2wav.c
mpc2wav.c

View file

@ -80,6 +80,7 @@ const struct filetype filetypes[] = {
{ ".ac3", TREE_ATTR_MPA, File, VOICE_EXT_MPA },
{ ".a52", TREE_ATTR_MPA, File, VOICE_EXT_MPA },
{ ".mpc", TREE_ATTR_MPA, File, VOICE_EXT_MPA },
{ ".wv", TREE_ATTR_MPA, File, VOICE_EXT_MPA },
#endif
{ ".m3u", TREE_ATTR_M3U, Playlist, LANG_PLAYLIST },
{ ".cfg", TREE_ATTR_CFG, Config, VOICE_EXT_CFG },