You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

32 lines
690B

  1. /* tick.h - Compute successive integer multiples of a rational
  2. * number without long-term rounding error.
  3. * (c)2002 by Lennert Buytenhek <buytenh@gnu.org>
  4. * File licensed under the GPL, see http://www.fsf.org/ for more info.
  5. * Dedicated to Marija Kulikova.
  6. */
  7. #include "avcodec.h"
  8. typedef struct Ticker {
  9. int value;
  10. int inrate;
  11. int outrate;
  12. int div;
  13. int mod;
  14. } Ticker;
  15. extern void ticker_init(Ticker *tick, INT64 inrate, INT64 outrate);
  16. static inline int ticker_tick(Ticker *tick, int num)
  17. {
  18. int n = num * tick->div;
  19. tick->value += num * tick->mod;
  20. while (tick->value > 0) {
  21. tick->value -= tick->inrate;
  22. n++;
  23. }
  24. return n;
  25. }