device.cpp 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #include "config.h"
  2. #include "device.h"
  3. #include <algorithm>
  4. #include <cstddef>
  5. #include <numeric>
  6. #include "al/buffer.h"
  7. #include "al/effect.h"
  8. #include "al/filter.h"
  9. #include "albit.h"
  10. #include "alnumeric.h"
  11. #include "atomic.h"
  12. #include "backends/base.h"
  13. #include "core/devformat.h"
  14. #include "core/hrtf.h"
  15. #include "core/logging.h"
  16. #include "core/mastering.h"
  17. #include "flexarray.h"
  18. namespace {
  19. using voidp = void*;
  20. } // namespace
  21. ALCdevice::ALCdevice(DeviceType type) : DeviceBase{type}
  22. { }
  23. ALCdevice::~ALCdevice()
  24. {
  25. TRACE("Freeing device %p\n", voidp{this});
  26. Backend = nullptr;
  27. size_t count{std::accumulate(BufferList.cbegin(), BufferList.cend(), 0_uz,
  28. [](size_t cur, const BufferSubList &sublist) noexcept -> size_t
  29. { return cur + static_cast<uint>(al::popcount(~sublist.FreeMask)); })};
  30. if(count > 0)
  31. WARN("%zu Buffer%s not deleted\n", count, (count==1)?"":"s");
  32. count = std::accumulate(EffectList.cbegin(), EffectList.cend(), 0_uz,
  33. [](size_t cur, const EffectSubList &sublist) noexcept -> size_t
  34. { return cur + static_cast<uint>(al::popcount(~sublist.FreeMask)); });
  35. if(count > 0)
  36. WARN("%zu Effect%s not deleted\n", count, (count==1)?"":"s");
  37. count = std::accumulate(FilterList.cbegin(), FilterList.cend(), 0_uz,
  38. [](size_t cur, const FilterSubList &sublist) noexcept -> size_t
  39. { return cur + static_cast<uint>(al::popcount(~sublist.FreeMask)); });
  40. if(count > 0)
  41. WARN("%zu Filter%s not deleted\n", count, (count==1)?"":"s");
  42. }
  43. void ALCdevice::enumerateHrtfs()
  44. {
  45. mHrtfList = EnumerateHrtf(configValue<std::string>({}, "hrtf-paths"));
  46. if(auto defhrtfopt = configValue<std::string>({}, "default-hrtf"))
  47. {
  48. auto iter = std::find(mHrtfList.begin(), mHrtfList.end(), *defhrtfopt);
  49. if(iter == mHrtfList.end())
  50. WARN("Failed to find default HRTF \"%s\"\n", defhrtfopt->c_str());
  51. else if(iter != mHrtfList.begin())
  52. std::rotate(mHrtfList.begin(), iter, iter+1);
  53. }
  54. }
  55. auto ALCdevice::getOutputMode1() const noexcept -> OutputMode1
  56. {
  57. if(mContexts.load(std::memory_order_relaxed)->empty())
  58. return OutputMode1::Any;
  59. switch(FmtChans)
  60. {
  61. case DevFmtMono: return OutputMode1::Mono;
  62. case DevFmtStereo:
  63. if(mHrtf)
  64. return OutputMode1::Hrtf;
  65. else if(mUhjEncoder)
  66. return OutputMode1::Uhj2;
  67. return OutputMode1::StereoBasic;
  68. case DevFmtQuad: return OutputMode1::Quad;
  69. case DevFmtX51: return OutputMode1::X51;
  70. case DevFmtX61: return OutputMode1::X61;
  71. case DevFmtX71: return OutputMode1::X71;
  72. case DevFmtX714:
  73. case DevFmtX7144:
  74. case DevFmtX3D71:
  75. case DevFmtAmbi3D:
  76. break;
  77. }
  78. return OutputMode1::Any;
  79. }