diff options
| author | Dave Chapman <dave@dchapman.com> | 2005-06-10 18:08:08 +0000 |
|---|---|---|
| committer | Dave Chapman <dave@dchapman.com> | 2005-06-10 18:08:08 +0000 |
| commit | 3c2c2f59f4578c41d591f0e8e88a07103cee499b (patch) | |
| tree | 9c05d5eaf112b5852b39532c420195df913a8637 /apps/playback.c | |
| parent | d30f1100ec8d74f3c187271590b03d589ad4b7dc (diff) | |
| download | rockbox-3c2c2f59f4578c41d591f0e8e88a07103cee499b.zip rockbox-3c2c2f59f4578c41d591f0e8e88a07103cee499b.tar.gz rockbox-3c2c2f59f4578c41d591f0e8e88a07103cee499b.tar.bz2 rockbox-3c2c2f59f4578c41d591f0e8e88a07103cee499b.tar.xz | |
Add first version of WAV playback to iRiver - only 16-bit Stereo 44.1KHz files supported.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@6654 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/playback.c')
| -rw-r--r-- | apps/playback.c | 53 |
1 files changed, 52 insertions, 1 deletions
diff --git a/apps/playback.c b/apps/playback.c index 71cb479..4cefed2 100644 --- a/apps/playback.c +++ b/apps/playback.c @@ -598,7 +598,7 @@ bool audio_load_track(int offset, bool start_play, int peek_offset) int rc, i; int copy_n; /* Used by the FLAC metadata parser */ - unsigned long totalsamples; + unsigned long totalsamples,bytespersample,channels,bitspersample,numbytes; unsigned char* buf; if (track_count >= MAX_TRACK) @@ -677,6 +677,57 @@ bool audio_load_track(int offset, bool start_play, int peek_offset) tracks[track_widx].taginfo_ready = true; break ; + case AFMT_PCM_WAV: + /* 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, 44); + if (rc < 44) { + close(fd); + return false; + } + + if ((memcmp(buf,"RIFF",4)!=0) || + (memcmp(&buf[8],"WAVEfmt",7)!=0)) { + logf("%s is not a WAV file\n",trackname); + close(fd); + return(false); + } + + /* FIX: Correctly parse WAV header - we assume canonical + 44-byte header */ + + bitspersample=buf[34]; + channels=buf[22]; + + if ((bitspersample!=16) || (channels != 2)) { + logf("Unsupported WAV file - %d bitspersample, %d channels\n", + bitspersample,channels); + close(fd); + return(false); + } + + bytespersample=((bitspersample/8)*channels); + numbytes=(buf[40]|(buf[41]<<8)|(buf[42]<<16)|(buf[43]<<24)); + totalsamples=numbytes/bytespersample; + + tracks[track_widx].id3.vbr=false; /* All WAV files are CBR */ + tracks[track_widx].id3.filesize=filesize(fd); + tracks[track_widx].id3.frequency=buf[24]|(buf[25]<<8)|(buf[26]<<16)|(buf[27]<<24); + + /* Calculate track length (in ms) and estimate the bitrate (in kbit/s) */ + tracks[track_widx].id3.length=(totalsamples/tracks[track_widx].id3.frequency)*1000; + tracks[track_widx].id3.bitrate=(tracks[track_widx].id3.frequency*bytespersample)/1024; + + 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; + + case AFMT_FLAC: /* A simple parser to read vital metadata from a FLAC file - length, frequency, bitrate etc. */ /* This code should either be moved to a seperate file, or discarded in favour of the libFLAC code */ |