Estimate (poorly) the duration of an Ogg track, and display elapsed time in WPS

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@6681 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Dave Chapman 2005-06-11 19:14:40 +00:00
parent 94b917e9ee
commit 8f0a0fed4e
2 changed files with 10 additions and 6 deletions

View file

@ -831,11 +831,13 @@ bool audio_load_track(int offset, bool start_play, int peek_offset)
tracks[track_widx].id3.bitrate=(buf[48]|(buf[49]<<8)|(buf[50]<<16)|(buf[51]<<24))/1000; tracks[track_widx].id3.bitrate=(buf[48]|(buf[49]<<8)|(buf[50]<<16)|(buf[51]<<24))/1000;
tracks[track_widx].id3.vbr=true; tracks[track_widx].id3.vbr=true;
/* I don't yet know how to calculate the totalsamples */ if (tracks[track_widx].id3.bitrate!=0) {
totalsamples=0; /* A _really_ stupid and inaccurate calculation, but the best
I can do at the moment. */
/* Calculate the length in ms */ tracks[track_widx].id3.length=(tracks[track_widx].filesize)/(tracks[track_widx].id3.bitrate/8);
tracks[track_widx].id3.length=(totalsamples/tracks[track_widx].id3.frequency)*1000; } else {
tracks[track_widx].id3.length=0;
}
lseek(fd, 0, SEEK_SET); lseek(fd, 0, SEEK_SET);
strncpy(tracks[track_widx].id3.path,trackname,sizeof(tracks[track_widx].id3.path)); strncpy(tracks[track_widx].id3.path,trackname,sizeof(tracks[track_widx].id3.path));

View file

@ -148,6 +148,8 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parm)
while (!ci->audiobuffer_insert(pcmbuf, n)) while (!ci->audiobuffer_insert(pcmbuf, n))
rb->yield(); rb->yield();
ci->set_elapsed(ov_time_tell(&vf));
#if BYTE_ORDER == BIG_ENDIAN #if BYTE_ORDER == BIG_ENDIAN
for (i=0;i<n;i+=2) { for (i=0;i<n;i+=2) {
x=pcmbuf[i]; pcmbuf[i]=pcmbuf[i+1]; pcmbuf[i+1]=x; x=pcmbuf[i]; pcmbuf[i]=pcmbuf[i+1]; pcmbuf[i+1]=x;