Silence and fix some clang-tidy warnings
[openal-soft.git] / alc / device.h
blobcef3294c41463874c18bea3ffa2d84472c500bac
1 #ifndef ALC_DEVICE_H
2 #define ALC_DEVICE_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>
13 #include "AL/al.h"
14 #include "AL/alc.h"
15 #include "AL/alext.h"
17 #include "alconfig.h"
18 #include "core/device.h"
19 #include "intrusive_ptr.h"
21 #ifdef ALSOFT_EAX
22 #include "al/eax/x_ram.h"
23 #endif // ALSOFT_EAX
25 struct BackendBase;
26 struct BufferSubList;
27 struct EffectSubList;
28 struct FilterSubList;
30 using uint = unsigned int;
33 struct ALCdevice : public al::intrusive_ref<ALCdevice>, DeviceBase {
34 /* This lock protects the device state (format, update size, etc) from
35 * being from being changed in multiple threads, or being accessed while
36 * being changed. It's also used to serialize calls to the backend.
38 std::mutex StateLock;
39 std::unique_ptr<BackendBase> Backend;
41 ALCuint NumMonoSources{};
42 ALCuint NumStereoSources{};
44 // Maximum number of sources that can be created
45 uint SourcesMax{};
46 // Maximum number of slots that can be created
47 uint AuxiliaryEffectSlotMax{};
49 std::string mHrtfName;
50 std::vector<std::string> mHrtfList;
51 ALCenum mHrtfStatus{ALC_FALSE};
53 enum class OutputMode1 : ALCenum {
54 Any = ALC_ANY_SOFT,
55 Mono = ALC_MONO_SOFT,
56 Stereo = ALC_STEREO_SOFT,
57 StereoBasic = ALC_STEREO_BASIC_SOFT,
58 Uhj2 = ALC_STEREO_UHJ_SOFT,
59 Hrtf = ALC_STEREO_HRTF_SOFT,
60 Quad = ALC_QUAD_SOFT,
61 X51 = ALC_SURROUND_5_1_SOFT,
62 X61 = ALC_SURROUND_6_1_SOFT,
63 X71 = ALC_SURROUND_7_1_SOFT
65 OutputMode1 getOutputMode1() const noexcept;
67 using OutputMode = OutputMode1;
69 std::atomic<ALCenum> LastError{ALC_NO_ERROR};
71 // Map of Buffers for this device
72 std::mutex BufferLock;
73 std::vector<BufferSubList> BufferList;
75 // Map of Effects for this device
76 std::mutex EffectLock;
77 std::vector<EffectSubList> EffectList;
79 // Map of Filters for this device
80 std::mutex FilterLock;
81 std::vector<FilterSubList> FilterList;
83 #ifdef ALSOFT_EAX
84 ALuint eax_x_ram_free_size{eax_x_ram_max_size};
85 #endif // ALSOFT_EAX
88 std::unordered_map<ALuint,std::string> mBufferNames;
89 std::unordered_map<ALuint,std::string> mEffectNames;
90 std::unordered_map<ALuint,std::string> mFilterNames;
92 std::string mVendorOverride;
93 std::string mVersionOverride;
94 std::string mRendererOverride;
96 ALCdevice(DeviceType type);
97 ~ALCdevice();
99 void enumerateHrtfs();
101 bool getConfigValueBool(const std::string_view block, const std::string_view key, bool def)
102 { return GetConfigValueBool(mDeviceName, block, key, def); }
104 template<typename T>
105 inline std::optional<T> configValue(const std::string_view block, const std::string_view key) = delete;
108 template<>
109 inline std::optional<std::string> ALCdevice::configValue(const std::string_view block, const std::string_view key)
110 { return ConfigValueStr(mDeviceName, block, key); }
111 template<>
112 inline std::optional<int> ALCdevice::configValue(const std::string_view block, const std::string_view key)
113 { return ConfigValueInt(mDeviceName, block, key); }
114 template<>
115 inline std::optional<uint> ALCdevice::configValue(const std::string_view block, const std::string_view key)
116 { return ConfigValueUInt(mDeviceName, block, key); }
117 template<>
118 inline std::optional<float> ALCdevice::configValue(const std::string_view block, const std::string_view key)
119 { return ConfigValueFloat(mDeviceName, block, key); }
120 template<>
121 inline std::optional<bool> ALCdevice::configValue(const std::string_view block, const std::string_view key)
122 { return ConfigValueBool(mDeviceName, block, key); }
124 /** Stores the latest ALC device error. */
125 void alcSetError(ALCdevice *device, ALCenum errorCode);
127 #endif