summaryrefslogtreecommitdiff
path: root/apps/codecs/mpa.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/codecs/mpa.c')
-rw-r--r--apps/codecs/mpa.c59
1 files changed, 58 insertions, 1 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)
109 return pos; 109 return pos;
110} 110}
111 111
112static void set_elapsed(struct mp3entry* id3)
113{
114 unsigned long offset = id3->offset > id3->first_frame_offset ?
115 id3->offset - id3->first_frame_offset : 0;
116
117 if ( id3->vbr ) {
118 if ( id3->has_toc ) {
119 /* calculate elapsed time using TOC */
120 int i;
121 unsigned int remainder, plen, relpos, nextpos;
122
123 /* find wich percent we're at */
124 for (i=0; i<100; i++ )
125 if ( offset < id3->toc[i] * (id3->filesize / 256) )
126 break;
127
128 i--;
129 if (i < 0)
130 i = 0;
131
132 relpos = id3->toc[i];
133
134 if (i < 99)
135 nextpos = id3->toc[i+1];
136 else
137 nextpos = 256;
138
139 remainder = offset - (relpos * (id3->filesize / 256));
140
141 /* set time for this percent (divide before multiply to prevent
142 overflow on long files. loss of precision is negligible on
143 short files) */
144 id3->elapsed = i * (id3->length / 100);
145
146 /* calculate remainder time */
147 plen = (nextpos - relpos) * (id3->filesize / 256);
148 id3->elapsed += (((remainder * 100) / plen) *
149 (id3->length / 10000));
150 }
151 else {
152 /* no TOC exists. set a rough estimate using average bitrate */
153 int tpk = id3->length /
154 ((id3->filesize - id3->first_frame_offset - id3->id3v1len) /
155 1024);
156 id3->elapsed = offset / 1024 * tpk;
157 }
158 }
159 else
160 {
161 /* constant bitrate, use exact calculation */
162 if (id3->bitrate != 0)
163 id3->elapsed = offset / (id3->bitrate / 8);
164 }
165}
166
112/* this is the codec entry point */ 167/* this is the codec entry point */
113enum codec_status codec_main(void) 168enum codec_status codec_main(void)
114{ 169{
@@ -145,8 +200,10 @@ next_track:
145 current_frequency = ci->id3->frequency; 200 current_frequency = ci->id3->frequency;
146 codec_set_replaygain(ci->id3); 201 codec_set_replaygain(ci->id3);
147 202
148 if (ci->id3->offset) 203 if (ci->id3->offset) {
149 ci->seek_buffer(ci->id3->offset); 204 ci->seek_buffer(ci->id3->offset);
205 set_elapsed(ci->id3);
206 }
150 else 207 else
151 ci->seek_buffer(ci->id3->first_frame_offset); 208 ci->seek_buffer(ci->id3->first_frame_offset);
152 209