summaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorNicolas Pennequin <nicolas.pennequin@free.fr>2008-04-03 12:13:03 +0000
committerNicolas Pennequin <nicolas.pennequin@free.fr>2008-04-03 12:13:03 +0000
commit73a71a4712795cef91849bd1eef327ac68ef19db (patch)
treec245f8f0e9fa7f473b8a81313b5420a8ccb1844b /apps
parentf51f98e13405fa46ccdda0230aafe868dec8410b (diff)
downloadrockbox-73a71a4712795cef91849bd1eef327ac68ef19db.tar.gz
rockbox-73a71a4712795cef91849bd1eef327ac68ef19db.tar.bz2
rockbox-73a71a4712795cef91849bd1eef327ac68ef19db.zip
Move audio_set_elapsed to mpa.c, as recommended by the TODO note. Please correct me if affecting ci->id3->elapsed directly (ie without using ci->set_elapsed) is wrong.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@16945 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps')
-rw-r--r--apps/codecs/mpa.c59
-rw-r--r--apps/playback.c57
2 files changed, 58 insertions, 58 deletions
diff --git a/apps/codecs/mpa.c b/apps/codecs/mpa.c
index f9a27f5b41..a18a5e8090 100644
--- a/apps/codecs/mpa.c
+++ b/apps/codecs/mpa.c
@@ -109,6 +109,61 @@ int get_file_pos(int newtime)
return pos;
}
+static void set_elapsed(struct mp3entry* id3)
+{
+ unsigned long offset = id3->offset > id3->first_frame_offset ?
+ id3->offset - id3->first_frame_offset : 0;
+
+ if ( id3->vbr ) {
+ if ( id3->has_toc ) {
+ /* calculate elapsed time using TOC */
+ int i;
+ unsigned int remainder, plen, relpos, nextpos;
+
+ /* find wich percent we're at */
+ for (i=0; i<100; i++ )
+ if ( offset < id3->toc[i] * (id3->filesize / 256) )
+ break;
+
+ i--;
+ if (i < 0)
+ i = 0;
+
+ relpos = id3->toc[i];
+
+ if (i < 99)
+ nextpos = id3->toc[i+1];
+ else
+ nextpos = 256;
+
+ remainder = offset - (relpos * (id3->filesize / 256));
+
+ /* set time for this percent (divide before multiply to prevent
+ overflow on long files. loss of precision is negligible on
+ short files) */
+ id3->elapsed = i * (id3->length / 100);
+
+ /* calculate remainder time */
+ plen = (nextpos - relpos) * (id3->filesize / 256);
+ id3->elapsed += (((remainder * 100) / plen) *
+ (id3->length / 10000));
+ }
+ else {
+ /* no TOC exists. set a rough estimate using average bitrate */
+ int tpk = id3->length /
+ ((id3->filesize - id3->first_frame_offset - id3->id3v1len) /
+ 1024);
+ id3->elapsed = offset / 1024 * tpk;
+ }
+ }
+ else
+ {
+ /* constant bitrate, use exact calculation */
+ if (id3->bitrate != 0)
+ id3->elapsed = offset / (id3->bitrate / 8);
+ }
+}
+
/* this is the codec entry point */
enum codec_status codec_main(void)
{
@@ -145,8 +200,10 @@ next_track:
current_frequency = ci->id3->frequency;
codec_set_replaygain(ci->id3);
- if (ci->id3->offset)
+ if (ci->id3->offset) {
ci->seek_buffer(ci->id3->offset);
+ set_elapsed(ci->id3);
+ }
else
ci->seek_buffer(ci->id3->first_frame_offset);
diff --git a/apps/playback.c b/apps/playback.c
index f49831ef30..2875f44505 100644
--- a/apps/playback.c
+++ b/apps/playback.c
@@ -1559,62 +1559,6 @@ static bool audio_loadcodec(bool start_play)
return true;
}
-/* TODO: Copied from mpeg.c. Should be moved somewhere else. */
-static void audio_set_elapsed(struct mp3entry* id3)
-{
- unsigned long offset = id3->offset > id3->first_frame_offset ?
- id3->offset - id3->first_frame_offset : 0;
-
- if ( id3->vbr ) {
- if ( id3->has_toc ) {
- /* calculate elapsed time using TOC */
- int i;
- unsigned int remainder, plen, relpos, nextpos;
-
- /* find wich percent we're at */
- for (i=0; i<100; i++ )
- if ( offset < id3->toc[i] * (id3->filesize / 256) )
- break;
-
- i--;
- if (i < 0)
- i = 0;
-
- relpos = id3->toc[i];
-
- if (i < 99)
- nextpos = id3->toc[i+1];
- else
- nextpos = 256;
-
- remainder = offset - (relpos * (id3->filesize / 256));
-
- /* set time for this percent (divide before multiply to prevent
- overflow on long files. loss of precision is negligible on
- short files) */
- id3->elapsed = i * (id3->length / 100);
-
- /* calculate remainder time */
- plen = (nextpos - relpos) * (id3->filesize / 256);
- id3->elapsed += (((remainder * 100) / plen) *
- (id3->length / 10000));
- }
- else {
- /* no TOC exists. set a rough estimate using average bitrate */
- int tpk = id3->length /
- ((id3->filesize - id3->first_frame_offset - id3->id3v1len) /
- 1024);
- id3->elapsed = offset / 1024 * tpk;
- }
- }
- else
- {
- /* constant bitrate, use exact calculation */
- if (id3->bitrate != 0)
- id3->elapsed = offset / (id3->bitrate / 8);
- }
-}
-
/* Load one track by making the appropriate bufopen calls. Return true if
everything required was loaded correctly, false if not. */
static bool audio_load_track(int offset, bool start_play)
@@ -1781,7 +1725,6 @@ static bool audio_load_track(int offset, bool start_play)
if (offset > 0) {
file_offset = offset;
track_id3->offset = offset;
- audio_set_elapsed(track_id3);
}
break;