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.

Clock.hpp 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /* Copyright 2016, Ableton AG, Berlin. All rights reserved.
  2. *
  3. * This program is free software: you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License as published by
  5. * the Free Software Foundation, either version 2 of the License, or
  6. * (at your option) any later version.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. *
  16. * If you would like to incorporate Link into a proprietary software application,
  17. * please contact <link-devs@ableton.com>.
  18. */
  19. #pragma once
  20. #include <chrono>
  21. #include <cstdint>
  22. namespace ableton
  23. {
  24. namespace platforms
  25. {
  26. namespace windows
  27. {
  28. struct Clock
  29. {
  30. using Ticks = std::int64_t;
  31. using Micros = std::chrono::microseconds;
  32. Clock()
  33. {
  34. LARGE_INTEGER frequency;
  35. QueryPerformanceFrequency(&frequency);
  36. mTicksToMicros = 1.0e6 / frequency.QuadPart;
  37. }
  38. Micros ticksToMicros(const Ticks ticks) const
  39. {
  40. return Micros{llround(mTicksToMicros * ticks)};
  41. }
  42. Ticks microsToTicks(const Micros micros) const
  43. {
  44. return static_cast<Ticks>(micros.count() / mTicksToMicros);
  45. }
  46. Ticks ticks() const
  47. {
  48. LARGE_INTEGER count;
  49. QueryPerformanceCounter(&count);
  50. return count.QuadPart;
  51. }
  52. std::chrono::microseconds micros() const
  53. {
  54. return ticksToMicros(ticks());
  55. }
  56. double mTicksToMicros;
  57. };
  58. } // namespace windows
  59. } // namespace platforms
  60. } // namespace ableton