1 #include "video/avi/timer.hpp"
2 #include "library/minmax.hpp"
4 timer::timer(uint32_t rate_n
, uint32_t rate_d
)
7 set_step(rate_n
, rate_d
);
10 void timer::rate(uint32_t rate_n
, uint32_t rate_d
)
14 set_step(rate_n
, rate_d
);
18 n
= n
* (d
/ old_d
) + 0.5;
23 // The highest value rate_n can safely have: 9,223,372,036,854,775,808
24 // The highest value rate_d can safely have: 18,446,744,073
25 void timer::set_step(uint32_t rate_n
, uint32_t rate_d
)
27 uint64_t maxnscl
= 9223372036854775808ULL / rate_n
;
28 uint64_t maxdscl
= 18446744073ULL / rate_d
;
29 uint64_t maxscl
= min(maxnscl
, maxdscl
);
30 uint64_t _rate_n
= maxscl
* rate_n
;
31 uint64_t _rate_d
= maxscl
* rate_d
;
33 sw
= 1000000000ULL * _rate_d
/ _rate_n
;
34 sn
= 1000000000ULL * _rate_d
% _rate_n
;
37 uint64_t timer::read_next()
39 uint64_t tmp_w
= w
+ sw
;
40 uint64_t tmp_n
= n
+ sn
;