forked from len0rd/rockbox
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
This commit is contained in:
parent
f51f98e134
commit
73a71a4712
2 changed files with 58 additions and 58 deletions
|
@ -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);
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue