Audio plugin host https://kx.studio/carla
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.

Time.h 1.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #pragma once
  2. #include <stdint.h>
  3. #include "../globals.h"
  4. class AbsTime
  5. {
  6. public:
  7. AbsTime(const SYNTH_T &synth)
  8. :frames(0),
  9. s(synth){};
  10. void operator++(){++frames;};
  11. void operator++(int){frames++;};
  12. int64_t time() const {return frames;};
  13. float dt() const { return s.dt(); }
  14. float framesPerSec() const { return 1/s.dt();}
  15. int samplesPerFrame() const {return s.buffersize;}
  16. private:
  17. int64_t frames;
  18. const SYNTH_T &s;
  19. };
  20. //Marker for an event relative to some position of the absolute timer
  21. class RelTime
  22. {
  23. public:
  24. RelTime(const AbsTime &t_, float sec)
  25. :t(t_)
  26. {
  27. //Calculate time of event
  28. double deltaFrames = sec*t.framesPerSec();
  29. int64_t tmp = (int64_t)deltaFrames;
  30. frame = t.time() + tmp;
  31. sample = t.samplesPerFrame()*(deltaFrames-tmp);
  32. }
  33. bool inThisFrame() {return t.time() == frame;};
  34. bool inPast() {return t.time() > frame;}
  35. bool inFuture() {return t.time() < frame;}
  36. private:
  37. int64_t frame;
  38. int32_t sample;
  39. const AbsTime &t;
  40. };