aboutsummaryrefslogtreecommitdiffstats
path: root/libav/tick.h
blob: 8b6d6b4421bce2fb37fbc36662602a1b0db64454 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/* 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);

extern inline int ticker_tick(Ticker *tick, int num)
{
    int n = num * tick->div;

    tick->value += num * tick->mod;
    while (tick->value > 0) {
        tick->value -= tick->inrate;
        n++;
    }

    return n;
}