summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorSolomon Peachy <pizza@shaftnet.org>2018-10-15 17:59:13 -0400
committerSolomon Peachy <pizza@shaftnet.org>2018-10-29 19:50:34 +0100
commit20b91a83d3078eeabc02a4d214f6d44c64282f89 (patch)
tree00a182ef2240e6edc5a88ae4cf037479f5fa042c /lib
parent0120ecd651a2ff3f8e202a704d6e73b705cf81d0 (diff)
downloadrockbox-20b91a83d3078eeabc02a4d214f6d44c64282f89.tar.gz
rockbox-20b91a83d3078eeabc02a4d214f6d44c64282f89.zip
codecs: Fix elapsed time calculation for large files
In particular, this solves seeking glitches seen in ~6 hr mp3 files. (Patch taken from Igor Poretsky's tree) Change-Id: Id65b6726146b6d2d1a223e90b88e401d1b2d597a
Diffstat (limited to 'lib')
-rw-r--r--lib/rbcodec/codecs/aac.c5
-rw-r--r--lib/rbcodec/codecs/alac.c6
-rw-r--r--lib/rbcodec/codecs/ape.c7
-rw-r--r--lib/rbcodec/codecs/mpa.c4
-rw-r--r--lib/rbcodec/codecs/mpc.c6
-rw-r--r--lib/rbcodec/codecs/shorten.c2
-rw-r--r--lib/rbcodec/codecs/speex.c2
7 files changed, 15 insertions, 17 deletions
diff --git a/lib/rbcodec/codecs/aac.c b/lib/rbcodec/codecs/aac.c
index 5e289f0306..c00946f227 100644
--- a/lib/rbcodec/codecs/aac.c
+++ b/lib/rbcodec/codecs/aac.c
@@ -141,8 +141,7 @@ enum codec_status codec_run(void)
141 sound_samples_done = 0; 141 sound_samples_done = 0;
142 } 142 }
143 NeAACDecPostSeekReset(decoder, i); 143 NeAACDecPostSeekReset(decoder, i);
144 elapsed_time = (sound_samples_done * 10) / 144 elapsed_time = sound_samples_done * 1000LL / ci->id3->frequency;
145 (ci->id3->frequency / 100);
146 } else if (param) { 145 } else if (param) {
147 elapsed_time = param; 146 elapsed_time = param;
148 action = CODEC_ACTION_SEEK_TIME; 147 action = CODEC_ACTION_SEEK_TIME;
@@ -176,7 +175,7 @@ enum codec_status codec_run(void)
176 (param/10/sbr_fac)*(ci->id3->frequency/100), 175 (param/10/sbr_fac)*(ci->id3->frequency/100),
177 &sound_samples_done, (int*) &i)) { 176 &sound_samples_done, (int*) &i)) {
178 sound_samples_done *= sbr_fac; 177 sound_samples_done *= sbr_fac;
179 elapsed_time = (sound_samples_done * 10) / (ci->id3->frequency / 100); 178 elapsed_time = sound_samples_done * 1000LL / ci->id3->frequency;
180 ci->set_elapsed(elapsed_time); 179 ci->set_elapsed(elapsed_time);
181 seek_idx = 0; 180 seek_idx = 0;
182 181
diff --git a/lib/rbcodec/codecs/alac.c b/lib/rbcodec/codecs/alac.c
index 35c3645657..903ea2850e 100644
--- a/lib/rbcodec/codecs/alac.c
+++ b/lib/rbcodec/codecs/alac.c
@@ -104,7 +104,7 @@ enum codec_status codec_run(void)
104 } 104 }
105 } 105 }
106 106
107 elapsedtime = (samplesdone*10)/(ci->id3->frequency/100); 107 elapsedtime = samplesdone * 1000LL / ci->id3->frequency;
108 ci->set_elapsed(elapsedtime); 108 ci->set_elapsed(elapsedtime);
109 109
110 /* The main decoding loop */ 110 /* The main decoding loop */
@@ -119,7 +119,7 @@ enum codec_status codec_run(void)
119 if (m4a_seek(&demux_res, &input_stream, 119 if (m4a_seek(&demux_res, &input_stream,
120 (param/10) * (ci->id3->frequency/100), 120 (param/10) * (ci->id3->frequency/100),
121 &samplesdone, (int *)&i)) { 121 &samplesdone, (int *)&i)) {
122 elapsedtime=(samplesdone*10)/(ci->id3->frequency/100); 122 elapsedtime=samplesdone*1000LL/ci->id3->frequency;
123 } 123 }
124 ci->set_elapsed(elapsedtime); 124 ci->set_elapsed(elapsedtime);
125 ci->seek_complete(); 125 ci->seek_complete();
@@ -140,7 +140,7 @@ enum codec_status codec_run(void)
140 140
141 /* Update the elapsed-time indicator */ 141 /* Update the elapsed-time indicator */
142 samplesdone+=samplesdecoded; 142 samplesdone+=samplesdecoded;
143 elapsedtime=(samplesdone*10)/(ci->id3->frequency/100); 143 elapsedtime=samplesdone*1000LL/ci->id3->frequency;
144 ci->set_elapsed(elapsedtime); 144 ci->set_elapsed(elapsedtime);
145 145
146 i++; 146 i++;
diff --git a/lib/rbcodec/codecs/ape.c b/lib/rbcodec/codecs/ape.c
index 0adc793ade..937af1945f 100644
--- a/lib/rbcodec/codecs/ape.c
+++ b/lib/rbcodec/codecs/ape.c
@@ -218,7 +218,7 @@ enum codec_status codec_run(void)
218 218
219 ape_resume(&ape_ctx, resume_offset, 219 ape_resume(&ape_ctx, resume_offset,
220 &currentframe, &samplesdone, &samplestoskip, &firstbyte); 220 &currentframe, &samplesdone, &samplestoskip, &firstbyte);
221 elapsedtime = (samplesdone*10)/(ape_ctx.samplerate/100); 221 elapsedtime = samplesdone*1000LL/ape_ctx.samplerate;
222 } 222 }
223 else { 223 else {
224 currentframe = 0; 224 currentframe = 0;
@@ -285,8 +285,7 @@ frame_start:
285 inbuffer = ci->request_buffer(&bytesleft, 285 inbuffer = ci->request_buffer(&bytesleft,
286 INPUT_CHUNKSIZE); 286 INPUT_CHUNKSIZE);
287 287
288 elapsedtime = (samplesdone*10)/ 288 elapsedtime = samplesdone*1000LL/ape_ctx.samplerate;
289 (ape_ctx.samplerate/100);
290 ci->set_elapsed(elapsedtime); 289 ci->set_elapsed(elapsedtime);
291 ci->seek_complete(); 290 ci->seek_complete();
292 action = CODEC_ACTION_NULL; 291 action = CODEC_ACTION_NULL;
@@ -330,7 +329,7 @@ frame_start:
330 329
331 if (!samplestoskip) { 330 if (!samplestoskip) {
332 /* Update the elapsed-time indicator */ 331 /* Update the elapsed-time indicator */
333 elapsedtime = (samplesdone*10)/(ape_ctx.samplerate/100); 332 elapsedtime = samplesdone*1000LL/ape_ctx.samplerate;
334 ci->set_elapsed(elapsedtime); 333 ci->set_elapsed(elapsedtime);
335 } 334 }
336 335
diff --git a/lib/rbcodec/codecs/mpa.c b/lib/rbcodec/codecs/mpa.c
index 0e7b4faf4f..e6662ddcbe 100644
--- a/lib/rbcodec/codecs/mpa.c
+++ b/lib/rbcodec/codecs/mpa.c
@@ -420,7 +420,7 @@ enum codec_status codec_run(void)
420 break; 420 break;
421 } 421 }
422 422
423 ci->set_elapsed((samplesdone * 1000) / current_frequency); 423 ci->set_elapsed((samplesdone * 1000LL) / current_frequency);
424 ci->seek_complete(); 424 ci->seek_complete();
425 init_mad(); 425 init_mad();
426 framelength = 0; 426 framelength = 0;
@@ -508,7 +508,7 @@ enum codec_status codec_run(void)
508 } 508 }
509 509
510 samplesdone += framelength; 510 samplesdone += framelength;
511 ci->set_elapsed((samplesdone * 1000) / current_frequency); 511 ci->set_elapsed((samplesdone * 1000LL) / current_frequency);
512 } 512 }
513 513
514 /* wait for synth idle - MT only*/ 514 /* wait for synth idle - MT only*/
diff --git a/lib/rbcodec/codecs/mpc.c b/lib/rbcodec/codecs/mpc.c
index a856f6f3d1..44c286ba0a 100644
--- a/lib/rbcodec/codecs/mpc.c
+++ b/lib/rbcodec/codecs/mpc.c
@@ -140,7 +140,7 @@ enum codec_status codec_run(void)
140 samplesdone = 0; 140 samplesdone = 0;
141 } 141 }
142 142
143 elapsed_time = (samplesdone*10)/frequency; 143 elapsed_time = (samplesdone*10LL)/frequency;
144 } 144 }
145 145
146 ci->set_elapsed(elapsed_time); 146 ci->set_elapsed(elapsed_time);
@@ -162,7 +162,7 @@ enum codec_status codec_run(void)
162 samplesdone = new_offset; 162 samplesdone = new_offset;
163 } 163 }
164 164
165 elapsed_time = (samplesdone*10)/frequency; 165 elapsed_time = (samplesdone*10LL)/frequency;
166 ci->set_elapsed(elapsed_time); 166 ci->set_elapsed(elapsed_time);
167 ci->seek_complete(); 167 ci->seek_complete();
168 } 168 }
@@ -182,7 +182,7 @@ enum codec_status codec_run(void)
182 frame.buffer + MPC_FRAME_LENGTH, 182 frame.buffer + MPC_FRAME_LENGTH,
183 frame.samples); 183 frame.samples);
184 samplesdone += frame.samples; 184 samplesdone += frame.samples;
185 elapsed_time = (samplesdone*10)/frequency; 185 elapsed_time = (samplesdone*10LL)/frequency;
186 ci->set_elapsed(elapsed_time); 186 ci->set_elapsed(elapsed_time);
187 /* Remark: rockbox offset is the file offset in bytes. So estimate 187 /* Remark: rockbox offset is the file offset in bytes. So estimate
188 * this offset from the samples, sampling frequency and bitrate */ 188 * this offset from the samples, sampling frequency and bitrate */
diff --git a/lib/rbcodec/codecs/shorten.c b/lib/rbcodec/codecs/shorten.c
index f171b69a64..e8d845c18b 100644
--- a/lib/rbcodec/codecs/shorten.c
+++ b/lib/rbcodec/codecs/shorten.c
@@ -145,7 +145,7 @@ seek_start:
145 145
146 /* Update the elapsed-time indicator */ 146 /* Update the elapsed-time indicator */
147 samplesdone += nsamples; 147 samplesdone += nsamples;
148 elapsedtime = (samplesdone*10) / (sc.sample_rate/100); 148 elapsedtime = samplesdone*1000LL/sc.sample_rate;
149 ci->set_elapsed(elapsedtime); 149 ci->set_elapsed(elapsedtime);
150 } 150 }
151 151
diff --git a/lib/rbcodec/codecs/speex.c b/lib/rbcodec/codecs/speex.c
index e1be971096..659694fa2a 100644
--- a/lib/rbcodec/codecs/speex.c
+++ b/lib/rbcodec/codecs/speex.c
@@ -570,7 +570,7 @@ next_page:
570 ci->set_offset((long) ci->curpos); 570 ci->set_offset((long) ci->curpos);
571 571
572 ci->set_elapsed((samplerate == 0) ? 0 : 572 ci->set_elapsed((samplerate == 0) ? 0 :
573 cur_granule * 1000 / samplerate); 573 cur_granule * 1000LL / samplerate);
574 } 574 }
575 } 575 }
576 } 576 }