summaryrefslogtreecommitdiff
path: root/core/multimedia/opieplayer/libmad/timer.c
Side-by-side diff
Diffstat (limited to 'core/multimedia/opieplayer/libmad/timer.c') (more/less context) (ignore whitespace changes)
-rw-r--r--core/multimedia/opieplayer/libmad/timer.c66
1 files changed, 35 insertions, 31 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,14 +1,14 @@
/*
- * mad - MPEG audio decoder
+ * libmad - MPEG audio decoder library
* Copyright (C) 2000-2001 Robert Leslie
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
@@ -17,25 +17,28 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* $Id$
*/
# ifdef HAVE_CONFIG_H
# include "libmad_config.h"
# endif
# include "libmad_global.h"
# include <stdio.h>
-# include <assert.h>
+
+# ifdef HAVE_ASSERT_H
+# include <assert.h>
+# endif
# include "timer.h"
mad_timer_t const mad_timer_zero = { 0, 0 };
/*
* NAME: timer->compare()
* DESCRIPTION: indicate relative order of two timers
*/
int mad_timer_compare(mad_timer_t timer1, mad_timer_t timer2)
{
signed long diff;
@@ -141,86 +144,87 @@ unsigned long scale_rational(unsigned long numer, unsigned long denom,
assert(denom != 0);
if (denom < scale)
return numer * (scale / denom) + numer * (scale % denom) / denom;
if (denom < numer)
return scale * (numer / denom) + scale * (numer % denom) / denom;
return numer * scale / denom;
}
/*
* NAME: timer->set()
- * DESCRIPTION: set timer to specific value
+ * DESCRIPTION: set timer to specific (positive) value
*/
void mad_timer_set(mad_timer_t *timer, unsigned long seconds,
- unsigned long fraction, unsigned long fracparts)
+ unsigned long numer, unsigned long denom)
{
timer->seconds = seconds;
-
- if (fraction == 0)
- fracparts = 0;
- else if (fracparts == 0) {
- fracparts = fraction;
- fraction = 1;
+ if (numer >= denom && denom > 0) {
+ timer->seconds += numer / denom;
+ numer %= denom;
}
- switch (fracparts) {
+ switch (denom) {
case 0:
+ case 1:
timer->fraction = 0;
break;
case MAD_TIMER_RESOLUTION:
- timer->fraction = fraction;
+ timer->fraction = numer;
+ break;
+
+ case 1000:
+ timer->fraction = numer * (MAD_TIMER_RESOLUTION / 1000);
break;
case 8000:
- timer->fraction = fraction * (MAD_TIMER_RESOLUTION / 8000);
+ timer->fraction = numer * (MAD_TIMER_RESOLUTION / 8000);
break;
case 11025:
- timer->fraction = fraction * (MAD_TIMER_RESOLUTION / 11025);
+ timer->fraction = numer * (MAD_TIMER_RESOLUTION / 11025);
break;
case 12000:
- timer->fraction = fraction * (MAD_TIMER_RESOLUTION / 12000);
+ timer->fraction = numer * (MAD_TIMER_RESOLUTION / 12000);
break;
case 16000:
- timer->fraction = fraction * (MAD_TIMER_RESOLUTION / 16000);
+ timer->fraction = numer * (MAD_TIMER_RESOLUTION / 16000);
break;
case 22050:
- timer->fraction = fraction * (MAD_TIMER_RESOLUTION / 22050);
+ timer->fraction = numer * (MAD_TIMER_RESOLUTION / 22050);
break;
case 24000:
- timer->fraction = fraction * (MAD_TIMER_RESOLUTION / 24000);
+ timer->fraction = numer * (MAD_TIMER_RESOLUTION / 24000);
break;
case 32000:
- timer->fraction = fraction * (MAD_TIMER_RESOLUTION / 32000);
+ timer->fraction = numer * (MAD_TIMER_RESOLUTION / 32000);
break;
case 44100:
- timer->fraction = fraction * (MAD_TIMER_RESOLUTION / 44100);
+ timer->fraction = numer * (MAD_TIMER_RESOLUTION / 44100);
break;
case 48000:
- timer->fraction = fraction * (MAD_TIMER_RESOLUTION / 48000);
+ timer->fraction = numer * (MAD_TIMER_RESOLUTION / 48000);
break;
default:
- timer->fraction =
- scale_rational(fraction, fracparts, MAD_TIMER_RESOLUTION);
+ timer->fraction = scale_rational(numer, denom, MAD_TIMER_RESOLUTION);
break;
}
if (timer->fraction >= MAD_TIMER_RESOLUTION)
reduce_timer(timer);
}
/*
* NAME: timer->add()
* DESCRIPTION: add one timer to another
*/
void mad_timer_add(mad_timer_t *timer, mad_timer_t incr)
@@ -234,26 +238,26 @@ void mad_timer_add(mad_timer_t *timer, mad_timer_t incr)
/*
* NAME: timer->multiply()
* DESCRIPTION: multiply a timer by a scalar value
*/
void mad_timer_multiply(mad_timer_t *timer, signed long scalar)
{
mad_timer_t addend;
unsigned long factor;
factor = scalar;
if (scalar < 0) {
- mad_timer_negate(timer);
factor = -scalar;
+ mad_timer_negate(timer);
}
addend = *timer;
*timer = mad_timer_zero;
while (factor) {
if (factor & 1)
mad_timer_add(timer, addend);
mad_timer_add(&addend, addend);
factor >>= 1;
}
@@ -308,37 +312,37 @@ signed long mad_timer_count(mad_timer_t timer, enum mad_units units)
case MAD_UNITS_59_94_FPS:
return (mad_timer_count(timer, -units) + 1) * 1000 / 1001;
}
/* unsupported units */
return 0;
}
/*
* NAME: timer->fraction()
* DESCRIPTION: return fractional part of timer in arbitrary terms
*/
-unsigned long mad_timer_fraction(mad_timer_t timer, unsigned long fracparts)
+unsigned long mad_timer_fraction(mad_timer_t timer, unsigned long denom)
{
timer = mad_timer_abs(timer);
- switch (fracparts) {
+ switch (denom) {
case 0:
return MAD_TIMER_RESOLUTION / timer.fraction;
case MAD_TIMER_RESOLUTION:
return timer.fraction;
default:
- return scale_rational(timer.fraction, MAD_TIMER_RESOLUTION, fracparts);
+ return scale_rational(timer.fraction, MAD_TIMER_RESOLUTION, denom);
}
}
/*
* NAME: timer->string()
* DESCRIPTION: write a string representation of a timer using a template
*/
void mad_timer_string(mad_timer_t timer,
char *dest, char const *format, enum mad_units units,
enum mad_units fracunits, unsigned long subparts)
{
unsigned long hours, minutes, seconds, sub;
@@ -368,30 +372,30 @@ void mad_timer_string(mad_timer_t timer,
case MAD_UNITS_32000_HZ:
case MAD_UNITS_44100_HZ:
case MAD_UNITS_48000_HZ:
case MAD_UNITS_24_FPS:
case MAD_UNITS_25_FPS:
case MAD_UNITS_30_FPS:
case MAD_UNITS_48_FPS:
case MAD_UNITS_50_FPS:
case MAD_UNITS_60_FPS:
case MAD_UNITS_75_FPS:
{
- unsigned long fracparts;
+ unsigned long denom;
- fracparts = MAD_TIMER_RESOLUTION / fracunits;
+ denom = MAD_TIMER_RESOLUTION / fracunits;
- frac = timer.fraction / fracparts;
- sub = scale_rational(timer.fraction % fracparts, fracparts, subparts);
+ frac = timer.fraction / denom;
+ sub = scale_rational(timer.fraction % denom, denom, subparts);
}
break;
case MAD_UNITS_23_976_FPS:
case MAD_UNITS_24_975_FPS:
case MAD_UNITS_29_97_FPS:
case MAD_UNITS_47_952_FPS:
case MAD_UNITS_49_95_FPS:
case MAD_UNITS_59_94_FPS:
/* drop-frame encoding */
/* N.B. this is only well-defined for MAD_UNITS_29_97_FPS */
{