summaryrefslogtreecommitdiff
path: root/apps/playback.c
diff options
context:
space:
mode:
authorMagnus Holmgren <magnushol@gmail.com>2006-10-30 20:19:21 +0000
committerMagnus Holmgren <magnushol@gmail.com>2006-10-30 20:19:21 +0000
commit39fe51e88d4b9680b49d93b19308d72998fd5e48 (patch)
tree5f58658b82190d3ac6da24514e13a2c8324143ec /apps/playback.c
parent02da4e6130cebed9915b7eb5caedf2632b8ee5ba (diff)
downloadrockbox-39fe51e88d4b9680b49d93b19308d72998fd5e48.tar.gz
rockbox-39fe51e88d4b9680b49d93b19308d72998fd5e48.zip
Improve accuracy a little when seeking and resuming MP3 files. Mainly noticable for low-bitrate files with large ID3V2 tags, and no effect if no ID3V2 tag. Should be ported to hwcodec targets. :)
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@11402 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/playback.c')
-rw-r--r--apps/playback.c20
1 files changed, 12 insertions, 8 deletions
diff --git a/apps/playback.c b/apps/playback.c
index de6646a232..13d2bd6b02 100644
--- a/apps/playback.c
+++ b/apps/playback.c
@@ -1452,13 +1452,12 @@ static int codec_get_file_pos(void)
1452 else 1452 else
1453 return -1; 1453 return -1;
1454 1454
1455 pos += id3->first_frame_offset;
1456
1455 /* Don't seek right to the end of the file so that we can 1457 /* Don't seek right to the end of the file so that we can
1456 transition properly to the next song */ 1458 transition properly to the next song */
1457 if (pos >= (int)(id3->filesize - id3->id3v1len)) 1459 if (pos >= (int)(id3->filesize - id3->id3v1len))
1458 pos = id3->filesize - id3->id3v1len - 1; 1460 pos = id3->filesize - id3->id3v1len - 1;
1459 /* skip past id3v2 tag and other leading garbage */
1460 else if (pos < (int)id3->first_frame_offset)
1461 pos = id3->first_frame_offset;
1462 1461
1463 return pos; 1462 return pos;
1464} 1463}
@@ -2316,6 +2315,9 @@ static bool audio_loadcodec(bool start_play)
2316/* TODO: Copied from mpeg.c. Should be moved somewhere else. */ 2315/* TODO: Copied from mpeg.c. Should be moved somewhere else. */
2317static void audio_set_elapsed(struct mp3entry* id3) 2316static void audio_set_elapsed(struct mp3entry* id3)
2318{ 2317{
2318 unsigned long offset = id3->offset > id3->first_frame_offset ?
2319 id3->offset - id3->first_frame_offset : 0;
2320
2319 if ( id3->vbr ) { 2321 if ( id3->vbr ) {
2320 if ( id3->has_toc ) { 2322 if ( id3->has_toc ) {
2321 /* calculate elapsed time using TOC */ 2323 /* calculate elapsed time using TOC */
@@ -2324,7 +2326,7 @@ static void audio_set_elapsed(struct mp3entry* id3)
2324 2326
2325 /* find wich percent we're at */ 2327 /* find wich percent we're at */
2326 for (i=0; i<100; i++ ) 2328 for (i=0; i<100; i++ )
2327 if ( id3->offset < id3->toc[i] * (id3->filesize / 256) ) 2329 if ( offset < id3->toc[i] * (id3->filesize / 256) )
2328 break; 2330 break;
2329 2331
2330 i--; 2332 i--;
@@ -2338,7 +2340,7 @@ static void audio_set_elapsed(struct mp3entry* id3)
2338 else 2340 else
2339 nextpos = 256; 2341 nextpos = 256;
2340 2342
2341 remainder = id3->offset - (relpos * (id3->filesize / 256)); 2343 remainder = offset - (relpos * (id3->filesize / 256));
2342 2344
2343 /* set time for this percent (divide before multiply to prevent 2345 /* set time for this percent (divide before multiply to prevent
2344 overflow on long files. loss of precision is negligible on 2346 overflow on long files. loss of precision is negligible on
@@ -2352,15 +2354,17 @@ static void audio_set_elapsed(struct mp3entry* id3)
2352 } 2354 }
2353 else { 2355 else {
2354 /* no TOC exists. set a rough estimate using average bitrate */ 2356 /* no TOC exists. set a rough estimate using average bitrate */
2355 int tpk = id3->length / (id3->filesize / 1024); 2357 int tpk = id3->length /
2356 id3->elapsed = id3->offset / 1024 * tpk; 2358 ((id3->filesize - id3->first_frame_offset - id3->id3v1len) /
2359 1024);
2360 id3->elapsed = offset / 1024 * tpk;
2357 } 2361 }
2358 } 2362 }
2359 else 2363 else
2360 { 2364 {
2361 /* constant bitrate, use exact calculation */ 2365 /* constant bitrate, use exact calculation */
2362 if (id3->bitrate != 0) 2366 if (id3->bitrate != 0)
2363 id3->elapsed = id3->offset / (id3->bitrate / 8); 2367 id3->elapsed = offset / (id3->bitrate / 8);
2364 } 2368 }
2365} 2369}
2366 2370