summaryrefslogtreecommitdiff
path: root/apps/codecs
diff options
context:
space:
mode:
authorMichael Sevakis <jethead71@rockbox.org>2008-03-29 06:36:53 +0000
committerMichael Sevakis <jethead71@rockbox.org>2008-03-29 06:36:53 +0000
commit4855e734f30229b03e1910440986a16ca798df58 (patch)
tree226a2243bb41a4f7643c0ec0bcb4e657973e923f /apps/codecs
parentd746b793178cf3b55a1405bf97e07c2adeca9769 (diff)
downloadrockbox-4855e734f30229b03e1910440986a16ca798df58.zip
rockbox-4855e734f30229b03e1910440986a16ca798df58.tar.gz
rockbox-4855e734f30229b03e1910440986a16ca798df58.tar.bz2
rockbox-4855e734f30229b03e1910440986a16ca798df58.tar.xz
Move codec_get_file_pos somewhere else like the comment said should be done. Codec API version increment was needed so update all codecs.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@16874 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/codecs')
-rw-r--r--apps/codecs/mpa.c53
1 files changed, 52 insertions, 1 deletions
diff --git a/apps/codecs/mpa.c b/apps/codecs/mpa.c
index 3de7684..f9a27f5 100644
--- a/apps/codecs/mpa.c
+++ b/apps/codecs/mpa.c
@@ -58,6 +58,57 @@ void init_mad(void)
stream.main_data = &mad_main_data;
}
+int get_file_pos(int newtime)
+{
+ int pos = -1;
+ struct mp3entry *id3 = ci->id3;
+
+ if (id3->vbr) {
+ if (id3->has_toc) {
+ /* Use the TOC to find the new position */
+ unsigned int percent, remainder;
+ int curtoc, nexttoc, plen;
+
+ percent = (newtime*100) / id3->length;
+ if (percent > 99)
+ percent = 99;
+
+ curtoc = id3->toc[percent];
+
+ if (percent < 99) {
+ nexttoc = id3->toc[percent+1];
+ } else {
+ nexttoc = 256;
+ }
+
+ pos = (id3->filesize/256)*curtoc;
+
+ /* Use the remainder to get a more accurate position */
+ remainder = (newtime*100) % id3->length;
+ remainder = (remainder*100) / id3->length;
+ plen = (nexttoc - curtoc)*(id3->filesize/256);
+ pos += (plen/100)*remainder;
+ } else {
+ /* No TOC exists, estimate the new position */
+ pos = (id3->filesize / (id3->length / 1000)) *
+ (newtime / 1000);
+ }
+ } else if (id3->bitrate) {
+ pos = newtime * (id3->bitrate / 8);
+ } else {
+ return -1;
+ }
+
+ pos += id3->first_frame_offset;
+
+ /* Don't seek right to the end of the file so that we can
+ transition properly to the next song */
+ if (pos >= (int)(id3->filesize - id3->id3v1len))
+ pos = id3->filesize - id3->id3v1len - 1;
+
+ return pos;
+}
+
/* this is the codec entry point */
enum codec_status codec_main(void)
{
@@ -146,7 +197,7 @@ next_track:
newpos = ci->id3->first_frame_offset;
samples_to_skip = start_skip;
} else {
- newpos = ci->mp3_get_filepos(ci->seek_time-1);
+ newpos = get_file_pos(ci->seek_time-1);
samples_to_skip = 0;
}