base.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #include "config.h"
  2. #include <stdlib.h>
  3. #include "alMain.h"
  4. #include "alu.h"
  5. #include "backends/base.h"
  6. extern inline ALuint64 GetDeviceClockTime(ALCdevice *device);
  7. /* Base ALCbackend method implementations. */
  8. void ALCbackend_Construct(ALCbackend *self, ALCdevice *device)
  9. {
  10. int ret = almtx_init(&self->mMutex, almtx_recursive);
  11. assert(ret == althrd_success);
  12. self->mDevice = device;
  13. }
  14. void ALCbackend_Destruct(ALCbackend *self)
  15. {
  16. almtx_destroy(&self->mMutex);
  17. }
  18. ALCboolean ALCbackend_reset(ALCbackend* UNUSED(self))
  19. {
  20. return ALC_FALSE;
  21. }
  22. ALCenum ALCbackend_captureSamples(ALCbackend* UNUSED(self), void* UNUSED(buffer), ALCuint UNUSED(samples))
  23. {
  24. return ALC_INVALID_DEVICE;
  25. }
  26. ALCuint ALCbackend_availableSamples(ALCbackend* UNUSED(self))
  27. {
  28. return 0;
  29. }
  30. ClockLatency ALCbackend_getClockLatency(ALCbackend *self)
  31. {
  32. ALCdevice *device = self->mDevice;
  33. ALuint refcount;
  34. ClockLatency ret;
  35. do {
  36. while(((refcount=ATOMIC_LOAD(&device->MixCount, almemory_order_acquire))&1))
  37. althrd_yield();
  38. ret.ClockTime = GetDeviceClockTime(device);
  39. ATOMIC_THREAD_FENCE(almemory_order_acquire);
  40. } while(refcount != ATOMIC_LOAD(&device->MixCount, almemory_order_relaxed));
  41. /* NOTE: The device will generally have about all but one periods filled at
  42. * any given time during playback. Without a more accurate measurement from
  43. * the output, this is an okay approximation.
  44. */
  45. ret.Latency = device->UpdateSize * DEVICE_CLOCK_RES / device->Frequency *
  46. maxu(device->NumUpdates-1, 1);
  47. return ret;
  48. }
  49. void ALCbackend_lock(ALCbackend *self)
  50. {
  51. int ret = almtx_lock(&self->mMutex);
  52. assert(ret == althrd_success);
  53. }
  54. void ALCbackend_unlock(ALCbackend *self)
  55. {
  56. int ret = almtx_unlock(&self->mMutex);
  57. assert(ret == althrd_success);
  58. }
  59. /* Base ALCbackendFactory method implementations. */
  60. void ALCbackendFactory_deinit(ALCbackendFactory* UNUSED(self))
  61. {
  62. }