device.h 3.6 KB

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