🛠️🐜 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.

160 lines
5.3 KiB

  1. #include "config.h"
  2. #include "base.h"
  3. #include <algorithm>
  4. #include <array>
  5. #include <atomic>
  6. #ifdef _WIN32
  7. #define WIN32_LEAN_AND_MEAN
  8. #include <windows.h>
  9. #include <mmreg.h>
  10. #include "albit.h"
  11. #include "core/logging.h"
  12. #include "aloptional.h"
  13. #endif
  14. #include "atomic.h"
  15. #include "core/devformat.h"
  16. bool BackendBase::reset()
  17. { throw al::backend_exception{al::backend_error::DeviceError, "Invalid BackendBase call"}; }
  18. void BackendBase::captureSamples(al::byte*, uint)
  19. { }
  20. uint BackendBase::availableSamples()
  21. { return 0; }
  22. ClockLatency BackendBase::getClockLatency()
  23. {
  24. ClockLatency ret;
  25. uint refcount;
  26. do {
  27. refcount = mDevice->waitForMix();
  28. ret.ClockTime = GetDeviceClockTime(mDevice);
  29. std::atomic_thread_fence(std::memory_order_acquire);
  30. } while(refcount != ReadRef(mDevice->MixCount));
  31. /* NOTE: The device will generally have about all but one periods filled at
  32. * any given time during playback. Without a more accurate measurement from
  33. * the output, this is an okay approximation.
  34. */
  35. ret.Latency = std::max(std::chrono::seconds{mDevice->BufferSize-mDevice->UpdateSize},
  36. std::chrono::seconds::zero());
  37. ret.Latency /= mDevice->Frequency;
  38. return ret;
  39. }
  40. void BackendBase::setDefaultWFXChannelOrder()
  41. {
  42. mDevice->RealOut.ChannelIndex.fill(INVALID_CHANNEL_INDEX);
  43. switch(mDevice->FmtChans)
  44. {
  45. case DevFmtMono:
  46. mDevice->RealOut.ChannelIndex[FrontCenter] = 0;
  47. break;
  48. case DevFmtStereo:
  49. mDevice->RealOut.ChannelIndex[FrontLeft] = 0;
  50. mDevice->RealOut.ChannelIndex[FrontRight] = 1;
  51. break;
  52. case DevFmtQuad:
  53. mDevice->RealOut.ChannelIndex[FrontLeft] = 0;
  54. mDevice->RealOut.ChannelIndex[FrontRight] = 1;
  55. mDevice->RealOut.ChannelIndex[BackLeft] = 2;
  56. mDevice->RealOut.ChannelIndex[BackRight] = 3;
  57. break;
  58. case DevFmtX51:
  59. mDevice->RealOut.ChannelIndex[FrontLeft] = 0;
  60. mDevice->RealOut.ChannelIndex[FrontRight] = 1;
  61. mDevice->RealOut.ChannelIndex[FrontCenter] = 2;
  62. mDevice->RealOut.ChannelIndex[LFE] = 3;
  63. mDevice->RealOut.ChannelIndex[SideLeft] = 4;
  64. mDevice->RealOut.ChannelIndex[SideRight] = 5;
  65. break;
  66. case DevFmtX61:
  67. mDevice->RealOut.ChannelIndex[FrontLeft] = 0;
  68. mDevice->RealOut.ChannelIndex[FrontRight] = 1;
  69. mDevice->RealOut.ChannelIndex[FrontCenter] = 2;
  70. mDevice->RealOut.ChannelIndex[LFE] = 3;
  71. mDevice->RealOut.ChannelIndex[BackCenter] = 4;
  72. mDevice->RealOut.ChannelIndex[SideLeft] = 5;
  73. mDevice->RealOut.ChannelIndex[SideRight] = 6;
  74. break;
  75. case DevFmtX71:
  76. mDevice->RealOut.ChannelIndex[FrontLeft] = 0;
  77. mDevice->RealOut.ChannelIndex[FrontRight] = 1;
  78. mDevice->RealOut.ChannelIndex[FrontCenter] = 2;
  79. mDevice->RealOut.ChannelIndex[LFE] = 3;
  80. mDevice->RealOut.ChannelIndex[BackLeft] = 4;
  81. mDevice->RealOut.ChannelIndex[BackRight] = 5;
  82. mDevice->RealOut.ChannelIndex[SideLeft] = 6;
  83. mDevice->RealOut.ChannelIndex[SideRight] = 7;
  84. break;
  85. case DevFmtX3D71:
  86. mDevice->RealOut.ChannelIndex[FrontLeft] = 0;
  87. mDevice->RealOut.ChannelIndex[FrontRight] = 1;
  88. mDevice->RealOut.ChannelIndex[FrontCenter] = 2;
  89. mDevice->RealOut.ChannelIndex[LFE] = 3;
  90. mDevice->RealOut.ChannelIndex[Aux0] = 4;
  91. mDevice->RealOut.ChannelIndex[Aux1] = 5;
  92. mDevice->RealOut.ChannelIndex[SideLeft] = 6;
  93. mDevice->RealOut.ChannelIndex[SideRight] = 7;
  94. break;
  95. case DevFmtAmbi3D:
  96. break;
  97. }
  98. }
  99. void BackendBase::setDefaultChannelOrder()
  100. {
  101. mDevice->RealOut.ChannelIndex.fill(INVALID_CHANNEL_INDEX);
  102. switch(mDevice->FmtChans)
  103. {
  104. case DevFmtX51:
  105. mDevice->RealOut.ChannelIndex[FrontLeft] = 0;
  106. mDevice->RealOut.ChannelIndex[FrontRight] = 1;
  107. mDevice->RealOut.ChannelIndex[SideLeft] = 2;
  108. mDevice->RealOut.ChannelIndex[SideRight] = 3;
  109. mDevice->RealOut.ChannelIndex[FrontCenter] = 4;
  110. mDevice->RealOut.ChannelIndex[LFE] = 5;
  111. return;
  112. case DevFmtX71:
  113. mDevice->RealOut.ChannelIndex[FrontLeft] = 0;
  114. mDevice->RealOut.ChannelIndex[FrontRight] = 1;
  115. mDevice->RealOut.ChannelIndex[BackLeft] = 2;
  116. mDevice->RealOut.ChannelIndex[BackRight] = 3;
  117. mDevice->RealOut.ChannelIndex[FrontCenter] = 4;
  118. mDevice->RealOut.ChannelIndex[LFE] = 5;
  119. mDevice->RealOut.ChannelIndex[SideLeft] = 6;
  120. mDevice->RealOut.ChannelIndex[SideRight] = 7;
  121. return;
  122. case DevFmtX3D71:
  123. mDevice->RealOut.ChannelIndex[FrontLeft] = 0;
  124. mDevice->RealOut.ChannelIndex[FrontRight] = 1;
  125. mDevice->RealOut.ChannelIndex[Aux0] = 2;
  126. mDevice->RealOut.ChannelIndex[Aux1] = 3;
  127. mDevice->RealOut.ChannelIndex[FrontCenter] = 4;
  128. mDevice->RealOut.ChannelIndex[LFE] = 5;
  129. mDevice->RealOut.ChannelIndex[SideLeft] = 6;
  130. mDevice->RealOut.ChannelIndex[SideRight] = 7;
  131. return;
  132. /* Same as WFX order */
  133. case DevFmtMono:
  134. case DevFmtStereo:
  135. case DevFmtQuad:
  136. case DevFmtX61:
  137. case DevFmtAmbi3D:
  138. setDefaultWFXChannelOrder();
  139. break;
  140. }
  141. }