🛠️🐜 Antkeeper superbuild with dependencies included https://antkeeper.com
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.

58 lines
1.5 KiB

  1. #include "config.h"
  2. #include <cstdlib>
  3. #include <thread>
  4. #include "alMain.h"
  5. #include "alu.h"
  6. #include "backends/base.h"
  7. ClockLatency GetClockLatency(ALCdevice *device)
  8. {
  9. BackendBase *backend{device->Backend.get()};
  10. ClockLatency ret{backend->getClockLatency()};
  11. ret.Latency += device->FixedLatency;
  12. return ret;
  13. }
  14. /* BackendBase method implementations. */
  15. BackendBase::BackendBase(ALCdevice *device) noexcept : mDevice{device}
  16. { }
  17. BackendBase::~BackendBase() = default;
  18. ALCboolean BackendBase::reset()
  19. { return ALC_FALSE; }
  20. ALCenum BackendBase::captureSamples(void* UNUSED(buffer), ALCuint UNUSED(samples))
  21. { return ALC_INVALID_DEVICE; }
  22. ALCuint BackendBase::availableSamples()
  23. { return 0; }
  24. ClockLatency BackendBase::getClockLatency()
  25. {
  26. ClockLatency ret;
  27. ALuint refcount;
  28. do {
  29. while(((refcount=mDevice->MixCount.load(std::memory_order_acquire))&1))
  30. std::this_thread::yield();
  31. ret.ClockTime = GetDeviceClockTime(mDevice);
  32. std::atomic_thread_fence(std::memory_order_acquire);
  33. } while(refcount != mDevice->MixCount.load(std::memory_order_relaxed));
  34. /* NOTE: The device will generally have about all but one periods filled at
  35. * any given time during playback. Without a more accurate measurement from
  36. * the output, this is an okay approximation.
  37. */
  38. ret.Latency = std::chrono::seconds{maxi(mDevice->BufferSize-mDevice->UpdateSize, 0)};
  39. ret.Latency /= mDevice->Frequency;
  40. return ret;
  41. }