diff options
Diffstat (limited to 'firmware/mpeg.c')
-rw-r--r-- | firmware/mpeg.c | 39 |
1 files changed, 38 insertions, 1 deletions
diff --git a/firmware/mpeg.c b/firmware/mpeg.c index a49f444dc2..a02654bfa5 100644 --- a/firmware/mpeg.c +++ b/firmware/mpeg.c | |||
@@ -246,6 +246,39 @@ static void remove_all_tags(void) | |||
246 | } | 246 | } |
247 | #endif | 247 | #endif |
248 | 248 | ||
249 | static void set_elapsed(struct mp3entry* id3) | ||
250 | { | ||
251 | if ( id3->vbr ) { | ||
252 | if ( id3->vbrflags & VBR_TOC_FLAG ) { | ||
253 | /* calculate elapsed time using TOC */ | ||
254 | int i, remainder, plen, relpos; | ||
255 | |||
256 | relpos = id3->offset * 256 / id3->filesize; | ||
257 | remainder = id3->offset - (relpos * id3->filesize / 256); | ||
258 | |||
259 | /* find wich percent we're at */ | ||
260 | for (i=0; i<100; i++ ) | ||
261 | if ( relpos < id3->toc[i] ) | ||
262 | break; | ||
263 | |||
264 | /* set time for this percent */ | ||
265 | id3->elapsed = (i-1) * id3->length / 100; | ||
266 | |||
267 | /* calculate remainder time */ | ||
268 | plen = (id3->toc[i] - id3->toc[i-1]) * id3->filesize / 256; | ||
269 | id3->elapsed += remainder * 1000 / plen ; | ||
270 | } | ||
271 | else { | ||
272 | /* no TOC exists. set a rough estimate using average bitrate */ | ||
273 | int tpk = (id3->filesize / 1024) / id3->length; | ||
274 | id3->elapsed = id3->offset * tpk / 1024; | ||
275 | } | ||
276 | } | ||
277 | else | ||
278 | /* constant bitrate == simple frame calculation */ | ||
279 | id3->elapsed = id3->offset / id3->bpf * id3->tpf; | ||
280 | } | ||
281 | |||
249 | static bool paused; /* playback is paused */ | 282 | static bool paused; /* playback is paused */ |
250 | #ifdef SIMULATOR | 283 | #ifdef SIMULATOR |
251 | static bool playing = false; | 284 | static bool playing = false; |
@@ -688,9 +721,13 @@ static void mpeg_thread(void) | |||
688 | return; | 721 | return; |
689 | 722 | ||
690 | start_offset = (int)ev.data; | 723 | start_offset = (int)ev.data; |
724 | |||
725 | /* mid-song resume? */ | ||
691 | if (start_offset) { | 726 | if (start_offset) { |
727 | struct mp3entry* id3 = &id3tags[tag_read_idx]->id3; | ||
692 | lseek(mpeg_file, start_offset, SEEK_SET); | 728 | lseek(mpeg_file, start_offset, SEEK_SET); |
693 | id3tags[tag_read_idx]->id3.offset = start_offset; | 729 | id3->offset = start_offset; |
730 | set_elapsed(id3); | ||
694 | } | 731 | } |
695 | else { | 732 | else { |
696 | /* skip past id3v2 tag (to an even byte) */ | 733 | /* skip past id3v2 tag (to an even byte) */ |