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