summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apps/codecs/mpa.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/apps/codecs/mpa.c b/apps/codecs/mpa.c
index 1b71bde79e..d5b4d02889 100644
--- a/apps/codecs/mpa.c
+++ b/apps/codecs/mpa.c
@@ -91,12 +91,17 @@ static int get_file_pos(int newtime)
91 struct mp3entry *id3 = ci->id3; 91 struct mp3entry *id3 = ci->id3;
92 92
93 if (id3->vbr) { 93 if (id3->vbr) {
94 /* Convert newtime and id3->length to seconds to
95 * avoid overflow */
96 unsigned int newtime_s = newtime/1000;
97 unsigned int length_s = id3->length/1000;
98
94 if (id3->has_toc) { 99 if (id3->has_toc) {
95 /* Use the TOC to find the new position */ 100 /* Use the TOC to find the new position */
96 unsigned int percent, remainder; 101 unsigned int percent, remainder;
97 int curtoc, nexttoc, plen; 102 int curtoc, nexttoc, plen;
98 103
99 percent = (newtime*100) / id3->length; 104 percent = (newtime_s*100) / length_s;
100 if (percent > 99) 105 if (percent > 99)
101 percent = 99; 106 percent = 99;
102 107
@@ -111,14 +116,13 @@ static int get_file_pos(int newtime)
111 pos = (id3->filesize/256)*curtoc; 116 pos = (id3->filesize/256)*curtoc;
112 117
113 /* Use the remainder to get a more accurate position */ 118 /* Use the remainder to get a more accurate position */
114 remainder = (newtime*100) % id3->length; 119 remainder = (newtime_s*100) % length_s;
115 remainder = (remainder*100) / id3->length; 120 remainder = (remainder*100) / length_s;
116 plen = (nexttoc - curtoc)*(id3->filesize/256); 121 plen = (nexttoc - curtoc)*(id3->filesize/256);
117 pos += (plen/100)*remainder; 122 pos += (plen/100)*remainder;
118 } else { 123 } else {
119 /* No TOC exists, estimate the new position */ 124 /* No TOC exists, estimate the new position */
120 pos = (id3->filesize / (id3->length / 1000)) * 125 pos = (id3->filesize / length_s) * newtime_s;
121 (newtime / 1000);
122 } 126 }
123 } else if (id3->bitrate) { 127 } else if (id3->bitrate) {
124 pos = newtime * (id3->bitrate / 8); 128 pos = newtime * (id3->bitrate / 8);