mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2024-11-26 19:01:44 +02:00
d714edf190
Originally committed as revision 681 to svn://svn.ffmpeg.org/ffmpeg/trunk
42 lines
933 B
C
42 lines
933 B
C
/* tick.h - Compute successive integer multiples of a rational
|
|
* number without long-term rounding error.
|
|
* (c)2002 by Lennert Buytenhek <buytenh@gnu.org>
|
|
* File licensed under the GPL, see http://www.fsf.org/ for more info.
|
|
* Dedicated to Marija Kulikova.
|
|
*/
|
|
|
|
#include "avcodec.h"
|
|
|
|
typedef struct Ticker {
|
|
int value;
|
|
int inrate;
|
|
int outrate;
|
|
int div;
|
|
int mod;
|
|
} Ticker;
|
|
|
|
extern void ticker_init(Ticker *tick, INT64 inrate, INT64 outrate);
|
|
|
|
static inline int ticker_tick(Ticker *tick, int num)
|
|
{
|
|
int n = num * tick->div;
|
|
|
|
tick->value += num * tick->mod;
|
|
#if 1
|
|
if (tick->value > 0) {
|
|
n += (tick->value / tick->inrate);
|
|
tick->value = tick->value % tick->inrate;
|
|
if (tick->value > 0) {
|
|
tick->value -= tick->inrate;
|
|
n++;
|
|
}
|
|
}
|
|
#else
|
|
while (tick->value > 0) {
|
|
tick->value -= tick->inrate;
|
|
n++;
|
|
}
|
|
#endif
|
|
return n;
|
|
}
|