/*
|
/*
|
* mad - MPEG audio decoder
|
* mad - MPEG audio decoder
|
* Copyright (C) 2000-2001 Robert Leslie
|
* Copyright (C) 2000-2001 Robert Leslie
|
*
|
*
|
* This program is free software; you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
* the Free Software Foundation; either version 2 of the License, or
|
* the Free Software Foundation; either version 2 of the License, or
|
* (at your option) any later version.
|
* (at your option) any later version.
|
*
|
*
|
* This program is distributed in the hope that it will be useful,
|
* This program is distributed in the hope that it will be useful,
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* GNU General Public License for more details.
|
* GNU General Public License for more details.
|
*
|
*
|
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
* along with this program; if not, write to the Free Software
|
* along with this program; if not, write to the Free Software
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
*
|
*
|
* $Id: timer.c,v 1.3 2001-11-06 17:01:28 simons Exp $
|
* $Id: timer.c,v 1.3 2001-11-06 17:01:28 simons Exp $
|
*/
|
*/
|
|
|
# ifdef HAVE_CONFIG_H
|
# ifdef HAVE_CONFIG_H
|
# include "config.h"
|
# include "config.h"
|
# endif
|
# endif
|
|
|
# include "global.h"
|
# include "global.h"
|
|
|
# ifndef EMBED
|
# ifndef EMBED
|
# include <stdio.h>
|
# include <stdio.h>
|
# include <assert.h>
|
# include <assert.h>
|
# else
|
# else
|
# define assert(x)
|
# define assert(x)
|
# endif
|
# endif
|
|
|
# include "timer.h"
|
# include "timer.h"
|
|
|
mad_timer_t const mad_timer_zero = { 0, 0 };
|
mad_timer_t const mad_timer_zero = { 0, 0 };
|
|
|
/*
|
/*
|
* NAME: timer->compare()
|
* NAME: timer->compare()
|
* DESCRIPTION: indicate relative order of two timers
|
* DESCRIPTION: indicate relative order of two timers
|
*/
|
*/
|
int mad_timer_compare(mad_timer_t timer1, mad_timer_t timer2)
|
int mad_timer_compare(mad_timer_t timer1, mad_timer_t timer2)
|
{
|
{
|
signed long diff;
|
signed long diff;
|
|
|
diff = timer1.seconds - timer2.seconds;
|
diff = timer1.seconds - timer2.seconds;
|
if (diff < 0)
|
if (diff < 0)
|
return -1;
|
return -1;
|
else if (diff > 0)
|
else if (diff > 0)
|
return +1;
|
return +1;
|
|
|
diff = timer1.fraction - timer2.fraction;
|
diff = timer1.fraction - timer2.fraction;
|
if (diff < 0)
|
if (diff < 0)
|
return -1;
|
return -1;
|
else if (diff > 0)
|
else if (diff > 0)
|
return +1;
|
return +1;
|
|
|
return 0;
|
return 0;
|
}
|
}
|
|
|
/*
|
/*
|
* NAME: timer->negate()
|
* NAME: timer->negate()
|
* DESCRIPTION: invert the sign of a timer
|
* DESCRIPTION: invert the sign of a timer
|
*/
|
*/
|
void mad_timer_negate(mad_timer_t *timer)
|
void mad_timer_negate(mad_timer_t *timer)
|
{
|
{
|
timer->seconds = -timer->seconds;
|
timer->seconds = -timer->seconds;
|
|
|
if (timer->fraction) {
|
if (timer->fraction) {
|
timer->seconds -= 1;
|
timer->seconds -= 1;
|
timer->fraction = MAD_TIMER_RESOLUTION - timer->fraction;
|
timer->fraction = MAD_TIMER_RESOLUTION - timer->fraction;
|
}
|
}
|
}
|
}
|
|
|
/*
|
/*
|
* NAME: timer->abs()
|
* NAME: timer->abs()
|
* DESCRIPTION: return the absolute value of a timer
|
* DESCRIPTION: return the absolute value of a timer
|
*/
|
*/
|
mad_timer_t mad_timer_abs(mad_timer_t timer)
|
mad_timer_t mad_timer_abs(mad_timer_t timer)
|
{
|
{
|
if (mad_timer_sign(timer) < 0)
|
if (mad_timer_sign(timer) < 0)
|
mad_timer_negate(&timer);
|
mad_timer_negate(&timer);
|
|
|
return timer;
|
return timer;
|
}
|
}
|
|
|
/*
|
/*
|
* NAME: reduce_timer()
|
* NAME: reduce_timer()
|
* DESCRIPTION: carry timer fraction into seconds
|
* DESCRIPTION: carry timer fraction into seconds
|
*/
|
*/
|
static
|
static
|
void reduce_timer(mad_timer_t *timer)
|
void reduce_timer(mad_timer_t *timer)
|
{
|
{
|
timer->seconds += timer->fraction / MAD_TIMER_RESOLUTION;
|
timer->seconds += timer->fraction / MAD_TIMER_RESOLUTION;
|
timer->fraction %= MAD_TIMER_RESOLUTION;
|
timer->fraction %= MAD_TIMER_RESOLUTION;
|
}
|
}
|
|
|
/*
|
/*
|
* NAME: gcd()
|
* NAME: gcd()
|
* DESCRIPTION: compute greatest common denominator
|
* DESCRIPTION: compute greatest common denominator
|
*/
|
*/
|
static
|
static
|
unsigned long gcd(unsigned long num1, unsigned long num2)
|
unsigned long gcd(unsigned long num1, unsigned long num2)
|
{
|
{
|
unsigned long tmp;
|
unsigned long tmp;
|
|
|
while (num2) {
|
while (num2) {
|
tmp = num2;
|
tmp = num2;
|
num2 = num1 % num2;
|
num2 = num1 % num2;
|
num1 = tmp;
|
num1 = tmp;
|
}
|
}
|
|
|
return num1;
|
return num1;
|
}
|
}
|
|
|
/*
|
/*
|
* NAME: reduce_rational()
|
* NAME: reduce_rational()
|
* DESCRIPTION: convert rational expression to lowest terms
|
* DESCRIPTION: convert rational expression to lowest terms
|
*/
|
*/
|
static
|
static
|
void reduce_rational(unsigned long *numer, unsigned long *denom)
|
void reduce_rational(unsigned long *numer, unsigned long *denom)
|
{
|
{
|
unsigned long factor;
|
unsigned long factor;
|
|
|
factor = gcd(*numer, *denom);
|
factor = gcd(*numer, *denom);
|
|
|
assert(factor != 0);
|
assert(factor != 0);
|
|
|
*numer /= factor;
|
*numer /= factor;
|
*denom /= factor;
|
*denom /= factor;
|
}
|
}
|
|
|
/*
|
/*
|
* NAME: scale_rational()
|
* NAME: scale_rational()
|
* DESCRIPTION: solve numer/denom == ?/scale avoiding overflowing
|
* DESCRIPTION: solve numer/denom == ?/scale avoiding overflowing
|
*/
|
*/
|
static
|
static
|
unsigned long scale_rational(unsigned long numer, unsigned long denom,
|
unsigned long scale_rational(unsigned long numer, unsigned long denom,
|
unsigned long scale)
|
unsigned long scale)
|
{
|
{
|
reduce_rational(&numer, &denom);
|
reduce_rational(&numer, &denom);
|
reduce_rational(&scale, &denom);
|
reduce_rational(&scale, &denom);
|
|
|
assert(denom != 0);
|
assert(denom != 0);
|
|
|
if (denom < scale)
|
if (denom < scale)
|
return numer * (scale / denom) + numer * (scale % denom) / denom;
|
return numer * (scale / denom) + numer * (scale % denom) / denom;
|
if (denom < numer)
|
if (denom < numer)
|
return scale * (numer / denom) + scale * (numer % denom) / denom;
|
return scale * (numer / denom) + scale * (numer % denom) / denom;
|
|
|
return numer * scale / denom;
|
return numer * scale / denom;
|
}
|
}
|
|
|
/*
|
/*
|
* NAME: timer->set()
|
* NAME: timer->set()
|
* DESCRIPTION: set timer to specific value
|
* DESCRIPTION: set timer to specific value
|
*/
|
*/
|
void mad_timer_set(mad_timer_t *timer, unsigned long seconds,
|
void mad_timer_set(mad_timer_t *timer, unsigned long seconds,
|
unsigned long fraction, unsigned long fracparts)
|
unsigned long fraction, unsigned long fracparts)
|
{
|
{
|
timer->seconds = seconds;
|
timer->seconds = seconds;
|
|
|
if (fraction == 0)
|
if (fraction == 0)
|
fracparts = 0;
|
fracparts = 0;
|
else if (fracparts == 0) {
|
else if (fracparts == 0) {
|
fracparts = fraction;
|
fracparts = fraction;
|
fraction = 1;
|
fraction = 1;
|
}
|
}
|
|
|
switch (fracparts) {
|
switch (fracparts) {
|
case 0:
|
case 0:
|
timer->fraction = 0;
|
timer->fraction = 0;
|
break;
|
break;
|
|
|
case MAD_TIMER_RESOLUTION:
|
case MAD_TIMER_RESOLUTION:
|
timer->fraction = fraction;
|
timer->fraction = fraction;
|
break;
|
break;
|
|
|
case 8000:
|
case 8000:
|
timer->fraction = fraction * (MAD_TIMER_RESOLUTION / 8000);
|
timer->fraction = fraction * (MAD_TIMER_RESOLUTION / 8000);
|
break;
|
break;
|
|
|
case 11025:
|
case 11025:
|
timer->fraction = fraction * (MAD_TIMER_RESOLUTION / 11025);
|
timer->fraction = fraction * (MAD_TIMER_RESOLUTION / 11025);
|
break;
|
break;
|
|
|
case 12000:
|
case 12000:
|
timer->fraction = fraction * (MAD_TIMER_RESOLUTION / 12000);
|
timer->fraction = fraction * (MAD_TIMER_RESOLUTION / 12000);
|
break;
|
break;
|
|
|
case 16000:
|
case 16000:
|
timer->fraction = fraction * (MAD_TIMER_RESOLUTION / 16000);
|
timer->fraction = fraction * (MAD_TIMER_RESOLUTION / 16000);
|
break;
|
break;
|
|
|
case 22050:
|
case 22050:
|
timer->fraction = fraction * (MAD_TIMER_RESOLUTION / 22050);
|
timer->fraction = fraction * (MAD_TIMER_RESOLUTION / 22050);
|
break;
|
break;
|
|
|
case 24000:
|
case 24000:
|
timer->fraction = fraction * (MAD_TIMER_RESOLUTION / 24000);
|
timer->fraction = fraction * (MAD_TIMER_RESOLUTION / 24000);
|
break;
|
break;
|
|
|
case 32000:
|
case 32000:
|
timer->fraction = fraction * (MAD_TIMER_RESOLUTION / 32000);
|
timer->fraction = fraction * (MAD_TIMER_RESOLUTION / 32000);
|
break;
|
break;
|
|
|
case 44100:
|
case 44100:
|
timer->fraction = fraction * (MAD_TIMER_RESOLUTION / 44100);
|
timer->fraction = fraction * (MAD_TIMER_RESOLUTION / 44100);
|
break;
|
break;
|
|
|
case 48000:
|
case 48000:
|
timer->fraction = fraction * (MAD_TIMER_RESOLUTION / 48000);
|
timer->fraction = fraction * (MAD_TIMER_RESOLUTION / 48000);
|
break;
|
break;
|
|
|
default:
|
default:
|
timer->fraction =
|
timer->fraction =
|
scale_rational(fraction, fracparts, MAD_TIMER_RESOLUTION);
|
scale_rational(fraction, fracparts, MAD_TIMER_RESOLUTION);
|
break;
|
break;
|
}
|
}
|
|
|
if (timer->fraction >= MAD_TIMER_RESOLUTION)
|
if (timer->fraction >= MAD_TIMER_RESOLUTION)
|
reduce_timer(timer);
|
reduce_timer(timer);
|
}
|
}
|
|
|
/*
|
/*
|
* NAME: timer->add()
|
* NAME: timer->add()
|
* DESCRIPTION: add one timer to another
|
* DESCRIPTION: add one timer to another
|
*/
|
*/
|
void mad_timer_add(mad_timer_t *timer, mad_timer_t incr)
|
void mad_timer_add(mad_timer_t *timer, mad_timer_t incr)
|
{
|
{
|
timer->seconds += incr.seconds;
|
timer->seconds += incr.seconds;
|
timer->fraction += incr.fraction;
|
timer->fraction += incr.fraction;
|
|
|
if (timer->fraction >= MAD_TIMER_RESOLUTION)
|
if (timer->fraction >= MAD_TIMER_RESOLUTION)
|
reduce_timer(timer);
|
reduce_timer(timer);
|
}
|
}
|
|
|
/*
|
/*
|
* NAME: timer->multiply()
|
* NAME: timer->multiply()
|
* DESCRIPTION: multiply a timer by a scalar value
|
* DESCRIPTION: multiply a timer by a scalar value
|
*/
|
*/
|
void mad_timer_multiply(mad_timer_t *timer, signed long scalar)
|
void mad_timer_multiply(mad_timer_t *timer, signed long scalar)
|
{
|
{
|
mad_timer_t addend;
|
mad_timer_t addend;
|
unsigned long factor;
|
unsigned long factor;
|
|
|
factor = scalar;
|
factor = scalar;
|
if (scalar < 0) {
|
if (scalar < 0) {
|
mad_timer_negate(timer);
|
mad_timer_negate(timer);
|
factor = -scalar;
|
factor = -scalar;
|
}
|
}
|
|
|
addend = *timer;
|
addend = *timer;
|
*timer = mad_timer_zero;
|
*timer = mad_timer_zero;
|
|
|
while (factor) {
|
while (factor) {
|
if (factor & 1)
|
if (factor & 1)
|
mad_timer_add(timer, addend);
|
mad_timer_add(timer, addend);
|
|
|
mad_timer_add(&addend, addend);
|
mad_timer_add(&addend, addend);
|
factor >>= 1;
|
factor >>= 1;
|
}
|
}
|
}
|
}
|
|
|
/*
|
/*
|
* NAME: timer->count()
|
* NAME: timer->count()
|
* DESCRIPTION: return timer value in selected units
|
* DESCRIPTION: return timer value in selected units
|
*/
|
*/
|
signed long mad_timer_count(mad_timer_t timer, enum mad_units units)
|
signed long mad_timer_count(mad_timer_t timer, enum mad_units units)
|
{
|
{
|
switch (units) {
|
switch (units) {
|
case MAD_UNITS_HOURS:
|
case MAD_UNITS_HOURS:
|
return timer.seconds / 60 / 60;
|
return timer.seconds / 60 / 60;
|
|
|
case MAD_UNITS_MINUTES:
|
case MAD_UNITS_MINUTES:
|
return timer.seconds / 60;
|
return timer.seconds / 60;
|
|
|
case MAD_UNITS_SECONDS:
|
case MAD_UNITS_SECONDS:
|
return timer.seconds;
|
return timer.seconds;
|
|
|
case MAD_UNITS_DECISECONDS:
|
case MAD_UNITS_DECISECONDS:
|
case MAD_UNITS_CENTISECONDS:
|
case MAD_UNITS_CENTISECONDS:
|
case MAD_UNITS_MILLISECONDS:
|
case MAD_UNITS_MILLISECONDS:
|
|
|
case MAD_UNITS_8000_HZ:
|
case MAD_UNITS_8000_HZ:
|
case MAD_UNITS_11025_HZ:
|
case MAD_UNITS_11025_HZ:
|
case MAD_UNITS_12000_HZ:
|
case MAD_UNITS_12000_HZ:
|
case MAD_UNITS_16000_HZ:
|
case MAD_UNITS_16000_HZ:
|
case MAD_UNITS_22050_HZ:
|
case MAD_UNITS_22050_HZ:
|
case MAD_UNITS_24000_HZ:
|
case MAD_UNITS_24000_HZ:
|
case MAD_UNITS_32000_HZ:
|
case MAD_UNITS_32000_HZ:
|
case MAD_UNITS_44100_HZ:
|
case MAD_UNITS_44100_HZ:
|
case MAD_UNITS_48000_HZ:
|
case MAD_UNITS_48000_HZ:
|
|
|
case MAD_UNITS_24_FPS:
|
case MAD_UNITS_24_FPS:
|
case MAD_UNITS_25_FPS:
|
case MAD_UNITS_25_FPS:
|
case MAD_UNITS_30_FPS:
|
case MAD_UNITS_30_FPS:
|
case MAD_UNITS_48_FPS:
|
case MAD_UNITS_48_FPS:
|
case MAD_UNITS_50_FPS:
|
case MAD_UNITS_50_FPS:
|
case MAD_UNITS_60_FPS:
|
case MAD_UNITS_60_FPS:
|
case MAD_UNITS_75_FPS:
|
case MAD_UNITS_75_FPS:
|
return timer.seconds * (signed long) units +
|
return timer.seconds * (signed long) units +
|
(signed long) scale_rational(timer.fraction, MAD_TIMER_RESOLUTION,
|
(signed long) scale_rational(timer.fraction, MAD_TIMER_RESOLUTION,
|
units);
|
units);
|
|
|
case MAD_UNITS_23_976_FPS:
|
case MAD_UNITS_23_976_FPS:
|
case MAD_UNITS_24_975_FPS:
|
case MAD_UNITS_24_975_FPS:
|
case MAD_UNITS_29_97_FPS:
|
case MAD_UNITS_29_97_FPS:
|
case MAD_UNITS_47_952_FPS:
|
case MAD_UNITS_47_952_FPS:
|
case MAD_UNITS_49_95_FPS:
|
case MAD_UNITS_49_95_FPS:
|
case MAD_UNITS_59_94_FPS:
|
case MAD_UNITS_59_94_FPS:
|
return (mad_timer_count(timer, -units) + 1) * 1000 / 1001;
|
return (mad_timer_count(timer, -units) + 1) * 1000 / 1001;
|
}
|
}
|
|
|
/* unsupported units */
|
/* unsupported units */
|
return 0;
|
return 0;
|
}
|
}
|
|
|
/*
|
/*
|
* NAME: timer->fraction()
|
* NAME: timer->fraction()
|
* DESCRIPTION: return fractional part of timer in arbitrary terms
|
* 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 fracparts)
|
{
|
{
|
timer = mad_timer_abs(timer);
|
timer = mad_timer_abs(timer);
|
|
|
switch (fracparts) {
|
switch (fracparts) {
|
case 0:
|
case 0:
|
return MAD_TIMER_RESOLUTION / timer.fraction;
|
return MAD_TIMER_RESOLUTION / timer.fraction;
|
|
|
case MAD_TIMER_RESOLUTION:
|
case MAD_TIMER_RESOLUTION:
|
return timer.fraction;
|
return timer.fraction;
|
|
|
default:
|
default:
|
return scale_rational(timer.fraction, MAD_TIMER_RESOLUTION, fracparts);
|
return scale_rational(timer.fraction, MAD_TIMER_RESOLUTION, fracparts);
|
}
|
}
|
}
|
}
|
|
|
#ifndef EMBED
|
#ifndef EMBED
|
/*
|
/*
|
* NAME: timer->string()
|
* NAME: timer->string()
|
* DESCRIPTION: write a string representation of a timer using a template
|
* DESCRIPTION: write a string representation of a timer using a template
|
*/
|
*/
|
void mad_timer_string(mad_timer_t timer,
|
void mad_timer_string(mad_timer_t timer,
|
char *dest, char const *format, enum mad_units units,
|
char *dest, char const *format, enum mad_units units,
|
enum mad_units fracunits, unsigned long subparts)
|
enum mad_units fracunits, unsigned long subparts)
|
{
|
{
|
unsigned long hours, minutes, seconds, sub;
|
unsigned long hours, minutes, seconds, sub;
|
unsigned int frac;
|
unsigned int frac;
|
|
|
timer = mad_timer_abs(timer);
|
timer = mad_timer_abs(timer);
|
|
|
seconds = timer.seconds;
|
seconds = timer.seconds;
|
frac = sub = 0;
|
frac = sub = 0;
|
|
|
switch (fracunits) {
|
switch (fracunits) {
|
case MAD_UNITS_HOURS:
|
case MAD_UNITS_HOURS:
|
case MAD_UNITS_MINUTES:
|
case MAD_UNITS_MINUTES:
|
case MAD_UNITS_SECONDS:
|
case MAD_UNITS_SECONDS:
|
break;
|
break;
|
|
|
case MAD_UNITS_DECISECONDS:
|
case MAD_UNITS_DECISECONDS:
|
case MAD_UNITS_CENTISECONDS:
|
case MAD_UNITS_CENTISECONDS:
|
case MAD_UNITS_MILLISECONDS:
|
case MAD_UNITS_MILLISECONDS:
|
|
|
case MAD_UNITS_8000_HZ:
|
case MAD_UNITS_8000_HZ:
|
case MAD_UNITS_11025_HZ:
|
case MAD_UNITS_11025_HZ:
|
case MAD_UNITS_12000_HZ:
|
case MAD_UNITS_12000_HZ:
|
case MAD_UNITS_16000_HZ:
|
case MAD_UNITS_16000_HZ:
|
case MAD_UNITS_22050_HZ:
|
case MAD_UNITS_22050_HZ:
|
case MAD_UNITS_24000_HZ:
|
case MAD_UNITS_24000_HZ:
|
case MAD_UNITS_32000_HZ:
|
case MAD_UNITS_32000_HZ:
|
case MAD_UNITS_44100_HZ:
|
case MAD_UNITS_44100_HZ:
|
case MAD_UNITS_48000_HZ:
|
case MAD_UNITS_48000_HZ:
|
|
|
case MAD_UNITS_24_FPS:
|
case MAD_UNITS_24_FPS:
|
case MAD_UNITS_25_FPS:
|
case MAD_UNITS_25_FPS:
|
case MAD_UNITS_30_FPS:
|
case MAD_UNITS_30_FPS:
|
case MAD_UNITS_48_FPS:
|
case MAD_UNITS_48_FPS:
|
case MAD_UNITS_50_FPS:
|
case MAD_UNITS_50_FPS:
|
case MAD_UNITS_60_FPS:
|
case MAD_UNITS_60_FPS:
|
case MAD_UNITS_75_FPS:
|
case MAD_UNITS_75_FPS:
|
{
|
{
|
unsigned long fracparts;
|
unsigned long fracparts;
|
|
|
fracparts = MAD_TIMER_RESOLUTION / fracunits;
|
fracparts = MAD_TIMER_RESOLUTION / fracunits;
|
|
|
frac = timer.fraction / fracparts;
|
frac = timer.fraction / fracparts;
|
sub = scale_rational(timer.fraction % fracparts, fracparts, subparts);
|
sub = scale_rational(timer.fraction % fracparts, fracparts, subparts);
|
}
|
}
|
break;
|
break;
|
|
|
case MAD_UNITS_23_976_FPS:
|
case MAD_UNITS_23_976_FPS:
|
case MAD_UNITS_24_975_FPS:
|
case MAD_UNITS_24_975_FPS:
|
case MAD_UNITS_29_97_FPS:
|
case MAD_UNITS_29_97_FPS:
|
case MAD_UNITS_47_952_FPS:
|
case MAD_UNITS_47_952_FPS:
|
case MAD_UNITS_49_95_FPS:
|
case MAD_UNITS_49_95_FPS:
|
case MAD_UNITS_59_94_FPS:
|
case MAD_UNITS_59_94_FPS:
|
/* drop-frame encoding */
|
/* drop-frame encoding */
|
/* N.B. this is only well-defined for MAD_UNITS_29_97_FPS */
|
/* N.B. this is only well-defined for MAD_UNITS_29_97_FPS */
|
{
|
{
|
unsigned long frame, cycle, d, m;
|
unsigned long frame, cycle, d, m;
|
|
|
frame = mad_timer_count(timer, fracunits);
|
frame = mad_timer_count(timer, fracunits);
|
|
|
cycle = -fracunits * 60 * 10 - (10 - 1) * 2;
|
cycle = -fracunits * 60 * 10 - (10 - 1) * 2;
|
|
|
d = frame / cycle;
|
d = frame / cycle;
|
m = frame % cycle;
|
m = frame % cycle;
|
frame += (10 - 1) * 2 * d;
|
frame += (10 - 1) * 2 * d;
|
if (m > 2)
|
if (m > 2)
|
frame += 2 * ((m - 2) / (cycle / 10));
|
frame += 2 * ((m - 2) / (cycle / 10));
|
|
|
frac = frame % -fracunits;
|
frac = frame % -fracunits;
|
seconds = frame / -fracunits;
|
seconds = frame / -fracunits;
|
}
|
}
|
break;
|
break;
|
}
|
}
|
|
|
switch (units) {
|
switch (units) {
|
case MAD_UNITS_HOURS:
|
case MAD_UNITS_HOURS:
|
minutes = seconds / 60;
|
minutes = seconds / 60;
|
hours = minutes / 60;
|
hours = minutes / 60;
|
|
|
sprintf(dest, format,
|
sprintf(dest, format,
|
hours,
|
hours,
|
(unsigned int) (minutes % 60),
|
(unsigned int) (minutes % 60),
|
(unsigned int) (seconds % 60),
|
(unsigned int) (seconds % 60),
|
frac, sub);
|
frac, sub);
|
break;
|
break;
|
|
|
case MAD_UNITS_MINUTES:
|
case MAD_UNITS_MINUTES:
|
minutes = seconds / 60;
|
minutes = seconds / 60;
|
|
|
sprintf(dest, format,
|
sprintf(dest, format,
|
minutes,
|
minutes,
|
(unsigned int) (seconds % 60),
|
(unsigned int) (seconds % 60),
|
frac, sub);
|
frac, sub);
|
break;
|
break;
|
|
|
case MAD_UNITS_SECONDS:
|
case MAD_UNITS_SECONDS:
|
sprintf(dest, format,
|
sprintf(dest, format,
|
seconds,
|
seconds,
|
frac, sub);
|
frac, sub);
|
break;
|
break;
|
|
|
case MAD_UNITS_23_976_FPS:
|
case MAD_UNITS_23_976_FPS:
|
case MAD_UNITS_24_975_FPS:
|
case MAD_UNITS_24_975_FPS:
|
case MAD_UNITS_29_97_FPS:
|
case MAD_UNITS_29_97_FPS:
|
case MAD_UNITS_47_952_FPS:
|
case MAD_UNITS_47_952_FPS:
|
case MAD_UNITS_49_95_FPS:
|
case MAD_UNITS_49_95_FPS:
|
case MAD_UNITS_59_94_FPS:
|
case MAD_UNITS_59_94_FPS:
|
if (fracunits < 0) {
|
if (fracunits < 0) {
|
/* not yet implemented */
|
/* not yet implemented */
|
sub = 0;
|
sub = 0;
|
}
|
}
|
|
|
/* fall through */
|
/* fall through */
|
|
|
case MAD_UNITS_DECISECONDS:
|
case MAD_UNITS_DECISECONDS:
|
case MAD_UNITS_CENTISECONDS:
|
case MAD_UNITS_CENTISECONDS:
|
case MAD_UNITS_MILLISECONDS:
|
case MAD_UNITS_MILLISECONDS:
|
|
|
case MAD_UNITS_8000_HZ:
|
case MAD_UNITS_8000_HZ:
|
case MAD_UNITS_11025_HZ:
|
case MAD_UNITS_11025_HZ:
|
case MAD_UNITS_12000_HZ:
|
case MAD_UNITS_12000_HZ:
|
case MAD_UNITS_16000_HZ:
|
case MAD_UNITS_16000_HZ:
|
case MAD_UNITS_22050_HZ:
|
case MAD_UNITS_22050_HZ:
|
case MAD_UNITS_24000_HZ:
|
case MAD_UNITS_24000_HZ:
|
case MAD_UNITS_32000_HZ:
|
case MAD_UNITS_32000_HZ:
|
case MAD_UNITS_44100_HZ:
|
case MAD_UNITS_44100_HZ:
|
case MAD_UNITS_48000_HZ:
|
case MAD_UNITS_48000_HZ:
|
|
|
case MAD_UNITS_24_FPS:
|
case MAD_UNITS_24_FPS:
|
case MAD_UNITS_25_FPS:
|
case MAD_UNITS_25_FPS:
|
case MAD_UNITS_30_FPS:
|
case MAD_UNITS_30_FPS:
|
case MAD_UNITS_48_FPS:
|
case MAD_UNITS_48_FPS:
|
case MAD_UNITS_50_FPS:
|
case MAD_UNITS_50_FPS:
|
case MAD_UNITS_60_FPS:
|
case MAD_UNITS_60_FPS:
|
case MAD_UNITS_75_FPS:
|
case MAD_UNITS_75_FPS:
|
sprintf(dest, format, mad_timer_count(timer, units), sub);
|
sprintf(dest, format, mad_timer_count(timer, units), sub);
|
break;
|
break;
|
}
|
}
|
}
|
}
|
|
|
#endif
|
#endif
|
|
|