summaryrefslogtreecommitdiff
path: root/apps/playback.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/playback.c')
-rw-r--r--apps/playback.c53
1 files changed, 52 insertions, 1 deletions
diff --git a/apps/playback.c b/apps/playback.c
index 71cb479059..4cefed20c2 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)
598 int rc, i; 598 int rc, i;
599 int copy_n; 599 int copy_n;
600 /* Used by the FLAC metadata parser */ 600 /* Used by the FLAC metadata parser */
601 unsigned long totalsamples; 601 unsigned long totalsamples,bytespersample,channels,bitspersample,numbytes;
602 unsigned char* buf; 602 unsigned char* buf;
603 603
604 if (track_count >= MAX_TRACK) 604 if (track_count >= MAX_TRACK)
@@ -677,6 +677,57 @@ bool audio_load_track(int offset, bool start_play, int peek_offset)
677 tracks[track_widx].taginfo_ready = true; 677 tracks[track_widx].taginfo_ready = true;
678 break ; 678 break ;
679 679
680 case AFMT_PCM_WAV:
681 /* Use the trackname part of the id3 structure as a temporary buffer */
682 buf=tracks[track_widx].id3.path;
683
684 lseek(fd, 0, SEEK_SET);
685
686 rc = read(fd, buf, 44);
687 if (rc < 44) {
688 close(fd);
689 return false;
690 }
691
692 if ((memcmp(buf,"RIFF",4)!=0) ||
693 (memcmp(&buf[8],"WAVEfmt",7)!=0)) {
694 logf("%s is not a WAV file\n",trackname);
695 close(fd);
696 return(false);
697 }
698
699 /* FIX: Correctly parse WAV header - we assume canonical
700 44-byte header */
701
702 bitspersample=buf[34];
703 channels=buf[22];
704
705 if ((bitspersample!=16) || (channels != 2)) {
706 logf("Unsupported WAV file - %d bitspersample, %d channels\n",
707 bitspersample,channels);
708 close(fd);
709 return(false);
710 }
711
712 bytespersample=((bitspersample/8)*channels);
713 numbytes=(buf[40]|(buf[41]<<8)|(buf[42]<<16)|(buf[43]<<24));
714 totalsamples=numbytes/bytespersample;
715
716 tracks[track_widx].id3.vbr=false; /* All WAV files are CBR */
717 tracks[track_widx].id3.filesize=filesize(fd);
718 tracks[track_widx].id3.frequency=buf[24]|(buf[25]<<8)|(buf[26]<<16)|(buf[27]<<24);
719
720 /* Calculate track length (in ms) and estimate the bitrate (in kbit/s) */
721 tracks[track_widx].id3.length=(totalsamples/tracks[track_widx].id3.frequency)*1000;
722 tracks[track_widx].id3.bitrate=(tracks[track_widx].id3.frequency*bytespersample)/1024;
723
724 lseek(fd, 0, SEEK_SET);
725 strncpy(tracks[track_widx].id3.path,trackname,sizeof(tracks[track_widx].id3.path));
726 tracks[track_widx].taginfo_ready = true;
727
728 break;
729
730
680 case AFMT_FLAC: 731 case AFMT_FLAC:
681 /* A simple parser to read vital metadata from a FLAC file - length, frequency, bitrate etc. */ 732 /* A simple parser to read vital metadata from a FLAC file - length, frequency, bitrate etc. */
682 /* This code should either be moved to a seperate file, or discarded in favour of the libFLAC code */ 733 /* This code should either be moved to a seperate file, or discarded in favour of the libFLAC code */