author | harlekin <harlekin> | 2002-04-19 16:08:55 (UTC) |
---|---|---|
committer | harlekin <harlekin> | 2002-04-19 16:08:55 (UTC) |
commit | 7ea4abeb652e6787e57a938e1ca028d25fd249ce (patch) (unidiff) | |
tree | ee08f2d9d6aaa8adb1c5f07f4124da8a61eb8cd5 /core/multimedia/opieplayer/libmad/timer.c | |
parent | caa7ced77b9014526607f9f65c58aabe7e0ba631 (diff) | |
download | opie-7ea4abeb652e6787e57a938e1ca028d25fd249ce.zip opie-7ea4abeb652e6787e57a938e1ca028d25fd249ce.tar.gz opie-7ea4abeb652e6787e57a938e1ca028d25fd249ce.tar.bz2 |
new libmad version, less cpu usage
Diffstat (limited to 'core/multimedia/opieplayer/libmad/timer.c') (more/less context) (show whitespace changes)
-rw-r--r-- | core/multimedia/opieplayer/libmad/timer.c | 64 |
1 files changed, 34 insertions, 30 deletions
diff --git a/core/multimedia/opieplayer/libmad/timer.c b/core/multimedia/opieplayer/libmad/timer.c index b30680c..299fe0b 100644 --- a/core/multimedia/opieplayer/libmad/timer.c +++ b/core/multimedia/opieplayer/libmad/timer.c | |||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | * mad - MPEG audio decoder | 2 | * libmad - MPEG audio decoder library |
3 | * Copyright (C) 2000-2001 Robert Leslie | 3 | * Copyright (C) 2000-2001 Robert Leslie |
4 | * | 4 | * |
5 | * This program is free software; you can redistribute it and/or modify | 5 | * This program is free software; you can redistribute it and/or modify |
@@ -26,7 +26,10 @@ | |||
26 | # include "libmad_global.h" | 26 | # include "libmad_global.h" |
27 | 27 | ||
28 | # include <stdio.h> | 28 | # include <stdio.h> |
29 | |||
30 | # ifdef HAVE_ASSERT_H | ||
29 | # include <assert.h> | 31 | # include <assert.h> |
32 | # endif | ||
30 | 33 | ||
31 | # include "timer.h" | 34 | # include "timer.h" |
32 | 35 | ||
@@ -150,68 +153,69 @@ unsigned long scale_rational(unsigned long numer, unsigned long denom, | |||
150 | 153 | ||
151 | /* | 154 | /* |
152 | * NAME:timer->set() | 155 | * NAME:timer->set() |
153 | * DESCRIPTION:set timer to specific value | 156 | * DESCRIPTION:set timer to specific (positive) value |
154 | */ | 157 | */ |
155 | void mad_timer_set(mad_timer_t *timer, unsigned long seconds, | 158 | void mad_timer_set(mad_timer_t *timer, unsigned long seconds, |
156 | unsigned long fraction, unsigned long fracparts) | 159 | unsigned long numer, unsigned long denom) |
157 | { | 160 | { |
158 | timer->seconds = seconds; | 161 | timer->seconds = seconds; |
159 | 162 | if (numer >= denom && denom > 0) { | |
160 | if (fraction == 0) | 163 | timer->seconds += numer / denom; |
161 | fracparts = 0; | 164 | numer %= denom; |
162 | else if (fracparts == 0) { | ||
163 | fracparts = fraction; | ||
164 | fraction = 1; | ||
165 | } | 165 | } |
166 | 166 | ||
167 | switch (fracparts) { | 167 | switch (denom) { |
168 | case 0: | 168 | case 0: |
169 | case 1: | ||
169 | timer->fraction = 0; | 170 | timer->fraction = 0; |
170 | break; | 171 | break; |
171 | 172 | ||
172 | case MAD_TIMER_RESOLUTION: | 173 | case MAD_TIMER_RESOLUTION: |
173 | timer->fraction = fraction; | 174 | timer->fraction = numer; |
175 | break; | ||
176 | |||
177 | case 1000: | ||
178 | timer->fraction = numer * (MAD_TIMER_RESOLUTION / 1000); | ||
174 | break; | 179 | break; |
175 | 180 | ||
176 | case 8000: | 181 | case 8000: |
177 | timer->fraction = fraction * (MAD_TIMER_RESOLUTION / 8000); | 182 | timer->fraction = numer * (MAD_TIMER_RESOLUTION / 8000); |
178 | break; | 183 | break; |
179 | 184 | ||
180 | case 11025: | 185 | case 11025: |
181 | timer->fraction = fraction * (MAD_TIMER_RESOLUTION / 11025); | 186 | timer->fraction = numer * (MAD_TIMER_RESOLUTION / 11025); |
182 | break; | 187 | break; |
183 | 188 | ||
184 | case 12000: | 189 | case 12000: |
185 | timer->fraction = fraction * (MAD_TIMER_RESOLUTION / 12000); | 190 | timer->fraction = numer * (MAD_TIMER_RESOLUTION / 12000); |
186 | break; | 191 | break; |
187 | 192 | ||
188 | case 16000: | 193 | case 16000: |
189 | timer->fraction = fraction * (MAD_TIMER_RESOLUTION / 16000); | 194 | timer->fraction = numer * (MAD_TIMER_RESOLUTION / 16000); |
190 | break; | 195 | break; |
191 | 196 | ||
192 | case 22050: | 197 | case 22050: |
193 | timer->fraction = fraction * (MAD_TIMER_RESOLUTION / 22050); | 198 | timer->fraction = numer * (MAD_TIMER_RESOLUTION / 22050); |
194 | break; | 199 | break; |
195 | 200 | ||
196 | case 24000: | 201 | case 24000: |
197 | timer->fraction = fraction * (MAD_TIMER_RESOLUTION / 24000); | 202 | timer->fraction = numer * (MAD_TIMER_RESOLUTION / 24000); |
198 | break; | 203 | break; |
199 | 204 | ||
200 | case 32000: | 205 | case 32000: |
201 | timer->fraction = fraction * (MAD_TIMER_RESOLUTION / 32000); | 206 | timer->fraction = numer * (MAD_TIMER_RESOLUTION / 32000); |
202 | break; | 207 | break; |
203 | 208 | ||
204 | case 44100: | 209 | case 44100: |
205 | timer->fraction = fraction * (MAD_TIMER_RESOLUTION / 44100); | 210 | timer->fraction = numer * (MAD_TIMER_RESOLUTION / 44100); |
206 | break; | 211 | break; |
207 | 212 | ||
208 | case 48000: | 213 | case 48000: |
209 | timer->fraction = fraction * (MAD_TIMER_RESOLUTION / 48000); | 214 | timer->fraction = numer * (MAD_TIMER_RESOLUTION / 48000); |
210 | break; | 215 | break; |
211 | 216 | ||
212 | default: | 217 | default: |
213 | timer->fraction = | 218 | timer->fraction = scale_rational(numer, denom, MAD_TIMER_RESOLUTION); |
214 | scale_rational(fraction, fracparts, MAD_TIMER_RESOLUTION); | ||
215 | break; | 219 | break; |
216 | } | 220 | } |
217 | 221 | ||
@@ -243,8 +247,8 @@ void mad_timer_multiply(mad_timer_t *timer, signed long scalar) | |||
243 | 247 | ||
244 | factor = scalar; | 248 | factor = scalar; |
245 | if (scalar < 0) { | 249 | if (scalar < 0) { |
246 | mad_timer_negate(timer); | ||
247 | factor = -scalar; | 250 | factor = -scalar; |
251 | mad_timer_negate(timer); | ||
248 | } | 252 | } |
249 | 253 | ||
250 | addend = *timer; | 254 | addend = *timer; |
@@ -317,11 +321,11 @@ signed long mad_timer_count(mad_timer_t timer, enum mad_units units) | |||
317 | * NAME:timer->fraction() | 321 | * NAME:timer->fraction() |
318 | * DESCRIPTION:return fractional part of timer in arbitrary terms | 322 | * DESCRIPTION:return fractional part of timer in arbitrary terms |
319 | */ | 323 | */ |
320 | unsigned long mad_timer_fraction(mad_timer_t timer, unsigned long fracparts) | 324 | unsigned long mad_timer_fraction(mad_timer_t timer, unsigned long denom) |
321 | { | 325 | { |
322 | timer = mad_timer_abs(timer); | 326 | timer = mad_timer_abs(timer); |
323 | 327 | ||
324 | switch (fracparts) { | 328 | switch (denom) { |
325 | case 0: | 329 | case 0: |
326 | return MAD_TIMER_RESOLUTION / timer.fraction; | 330 | return MAD_TIMER_RESOLUTION / timer.fraction; |
327 | 331 | ||
@@ -329,7 +333,7 @@ unsigned long mad_timer_fraction(mad_timer_t timer, unsigned long fracparts) | |||
329 | return timer.fraction; | 333 | return timer.fraction; |
330 | 334 | ||
331 | default: | 335 | default: |
332 | return scale_rational(timer.fraction, MAD_TIMER_RESOLUTION, fracparts); | 336 | return scale_rational(timer.fraction, MAD_TIMER_RESOLUTION, denom); |
333 | } | 337 | } |
334 | } | 338 | } |
335 | 339 | ||
@@ -377,12 +381,12 @@ void mad_timer_string(mad_timer_t timer, | |||
377 | case MAD_UNITS_60_FPS: | 381 | case MAD_UNITS_60_FPS: |
378 | case MAD_UNITS_75_FPS: | 382 | case MAD_UNITS_75_FPS: |
379 | { | 383 | { |
380 | unsigned long fracparts; | 384 | unsigned long denom; |
381 | 385 | ||
382 | fracparts = MAD_TIMER_RESOLUTION / fracunits; | 386 | denom = MAD_TIMER_RESOLUTION / fracunits; |
383 | 387 | ||
384 | frac = timer.fraction / fracparts; | 388 | frac = timer.fraction / denom; |
385 | sub = scale_rational(timer.fraction % fracparts, fracparts, subparts); | 389 | sub = scale_rational(timer.fraction % denom, denom, subparts); |
386 | } | 390 | } |
387 | break; | 391 | break; |
388 | 392 | ||