summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorroman.artiukhin <bahusdrive@gmail.com>2023-08-21 12:57:27 +0300
committerSolomon Peachy <pizza@shaftnet.org>2023-08-28 14:04:56 -0400
commit3883c978abdcb443ac6ca2b4a57d941c418e8b74 (patch)
tree805cdb77bc69146b883617035121569a09d51665
parent8a22660770d3c0c713247ab8f2b7c08777affd9f (diff)
downloadrockbox-3883c978abdcb443ac6ca2b4a57d941c418e8b74.tar.gz
rockbox-3883c978abdcb443ac6ca2b4a57d941c418e8b74.zip
Fix MP3 VBR seek jumps in wrong direction for long files
Fix jumps in the wrong direction by seeking relative to the current position Change-Id: I5ca3d5bcb256dd8fb1cd17e6149878190571d359
-rw-r--r--lib/rbcodec/codecs/mpa.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/lib/rbcodec/codecs/mpa.c b/lib/rbcodec/codecs/mpa.c
index bafed3970c..c5d47a6791 100644
--- a/lib/rbcodec/codecs/mpa.c
+++ b/lib/rbcodec/codecs/mpa.c
@@ -192,12 +192,20 @@ static int get_file_pos(int newtime)
192 pos = cur_toc * toc_sizestep; 192 pos = cur_toc * toc_sizestep;
193 193
194 /* Interpolate between this TOC mark and the next TOC mark */ 194 /* Interpolate between this TOC mark and the next TOC mark */
195 newtime -= percent * pct_timestep; 195 int newtime_toc = newtime - percent * pct_timestep;
196 pos += (uint64_t)plength * newtime / pct_timestep; 196 pos += (uint64_t)plength * newtime_toc / pct_timestep;
197 } else { 197 } else {
198 /* No TOC exists, estimate the new position */ 198 /* No TOC exists, estimate the new position */
199 pos = (uint64_t)newtime * id3->filesize / id3->length; 199 pos = (uint64_t)newtime * id3->filesize / id3->length;
200 } 200 }
201 // VBR seek might be very inaccurate in long files
202 // So make sure that seeking actually happened in the intended direction
203 // Fix jumps in the wrong direction by seeking relative to the current position
204 long delta = id3->elapsed - newtime;
205 if ((delta >= 0 && pos > ci->curpos) || (delta < 0 && pos < ci->curpos))
206 {
207 pos = ci->curpos - delta * id3->filesize / id3->length;
208 }
201 } else if (id3->bitrate) { 209 } else if (id3->bitrate) {
202 pos = newtime * (id3->bitrate / 8); 210 pos = newtime * (id3->bitrate / 8);
203 } else { 211 } else {