device.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. #ifndef ALC_DEVICE_H
  2. #define ALC_DEVICE_H
  3. #include "config.h"
  4. #include <atomic>
  5. #include <memory>
  6. #include <mutex>
  7. #include <optional>
  8. #include <string>
  9. #include <unordered_map>
  10. #include <string_view>
  11. #include <vector>
  12. #include "AL/al.h"
  13. #include "AL/alc.h"
  14. #include "AL/alext.h"
  15. #include "alconfig.h"
  16. #include "core/device.h"
  17. #include "intrusive_ptr.h"
  18. #if ALSOFT_EAX
  19. #include "al/eax/x_ram.h"
  20. #endif // ALSOFT_EAX
  21. struct BackendBase;
  22. struct BufferSubList;
  23. struct EffectSubList;
  24. struct FilterSubList;
  25. using uint = unsigned int;
  26. struct ALCdevice { virtual ~ALCdevice() = default; };
  27. namespace al {
  28. struct Device final : public ALCdevice, al::intrusive_ref<al::Device>, DeviceBase {
  29. /* This lock protects the device state (format, update size, etc) from
  30. * being from being changed in multiple threads, or being accessed while
  31. * being changed. It's also used to serialize calls to the backend.
  32. */
  33. std::mutex StateLock;
  34. std::unique_ptr<BackendBase> Backend;
  35. ALCuint NumMonoSources{};
  36. ALCuint NumStereoSources{};
  37. // Maximum number of sources that can be created
  38. uint SourcesMax{};
  39. // Maximum number of slots that can be created
  40. uint AuxiliaryEffectSlotMax{};
  41. std::string mHrtfName;
  42. std::vector<std::string> mHrtfList;
  43. ALCenum mHrtfStatus{ALC_FALSE};
  44. enum class OutputMode1 : ALCenum {
  45. Any = ALC_ANY_SOFT,
  46. Mono = ALC_MONO_SOFT,
  47. Stereo = ALC_STEREO_SOFT,
  48. StereoBasic = ALC_STEREO_BASIC_SOFT,
  49. Uhj2 = ALC_STEREO_UHJ_SOFT,
  50. Hrtf = ALC_STEREO_HRTF_SOFT,
  51. Quad = ALC_QUAD_SOFT,
  52. X51 = ALC_SURROUND_5_1_SOFT,
  53. X61 = ALC_SURROUND_6_1_SOFT,
  54. X71 = ALC_SURROUND_7_1_SOFT
  55. };
  56. OutputMode1 getOutputMode1() const noexcept;
  57. using OutputMode = OutputMode1;
  58. std::atomic<ALCenum> LastError{ALC_NO_ERROR};
  59. // Map of Buffers for this device
  60. std::mutex BufferLock;
  61. std::vector<BufferSubList> BufferList;
  62. // Map of Effects for this device
  63. std::mutex EffectLock;
  64. std::vector<EffectSubList> EffectList;
  65. // Map of Filters for this device
  66. std::mutex FilterLock;
  67. std::vector<FilterSubList> FilterList;
  68. #if ALSOFT_EAX
  69. ALuint eax_x_ram_free_size{eax_x_ram_max_size};
  70. #endif // ALSOFT_EAX
  71. std::unordered_map<ALuint,std::string> mBufferNames;
  72. std::unordered_map<ALuint,std::string> mEffectNames;
  73. std::unordered_map<ALuint,std::string> mFilterNames;
  74. std::string mVendorOverride;
  75. std::string mVersionOverride;
  76. std::string mRendererOverride;
  77. explicit Device(DeviceType type);
  78. ~Device() final;
  79. void enumerateHrtfs();
  80. bool getConfigValueBool(const std::string_view block, const std::string_view key, bool def)
  81. { return GetConfigValueBool(mDeviceName, block, key, def); }
  82. template<typename T>
  83. auto configValue(const std::string_view block, const std::string_view key) -> std::optional<T> = delete;
  84. };
  85. template<> inline
  86. auto Device::configValue(const std::string_view block, const std::string_view key) -> std::optional<std::string>
  87. { return ConfigValueStr(mDeviceName, block, key); }
  88. template<> inline
  89. auto Device::configValue(const std::string_view block, const std::string_view key) -> std::optional<int>
  90. { return ConfigValueInt(mDeviceName, block, key); }
  91. template<> inline
  92. auto Device::configValue(const std::string_view block, const std::string_view key) -> std::optional<uint>
  93. { return ConfigValueUInt(mDeviceName, block, key); }
  94. template<> inline
  95. auto Device::configValue(const std::string_view block, const std::string_view key) -> std::optional<float>
  96. { return ConfigValueFloat(mDeviceName, block, key); }
  97. template<> inline
  98. auto Device::configValue(const std::string_view block, const std::string_view key) -> std::optional<bool>
  99. { return ConfigValueBool(mDeviceName, block, key); }
  100. } // namespace al
  101. /** Stores the latest ALC device error. */
  102. void alcSetError(al::Device *device, ALCenum errorCode);
  103. #endif