Move some function definitions to a more appropriate source
[openal-soft.git] / alc / device.h
blobdd9335dc5161158d6805769bf589d775a227d06c
1 #ifndef ALC_DEVICE_H
2 #define ALC_DEVICE_H
4 #include <array>
5 #include <atomic>
6 #include <memory>
7 #include <mutex>
8 #include <optional>
9 #include <stdint.h>
10 #include <string>
11 #include <unordered_map>
12 #include <utility>
13 #include <vector>
15 #include "AL/alc.h"
16 #include "AL/alext.h"
18 #include "alconfig.h"
19 #include "almalloc.h"
20 #include "alnumeric.h"
21 #include "core/device.h"
22 #include "inprogext.h"
23 #include "intrusive_ptr.h"
25 #ifdef ALSOFT_EAX
26 #include "al/eax/x_ram.h"
27 #endif // ALSOFT_EAX
29 struct ALbuffer;
30 struct ALeffect;
31 struct ALfilter;
32 struct BackendBase;
33 struct BufferSubList;
34 struct EffectSubList;
35 struct FilterSubList;
37 using uint = unsigned int;
40 struct ALCdevice : public al::intrusive_ref<ALCdevice>, DeviceBase {
41 /* This lock protects the device state (format, update size, etc) from
42 * being from being changed in multiple threads, or being accessed while
43 * being changed. It's also used to serialize calls to the backend.
45 std::mutex StateLock;
46 std::unique_ptr<BackendBase> Backend;
48 ALCuint NumMonoSources{};
49 ALCuint NumStereoSources{};
51 // Maximum number of sources that can be created
52 uint SourcesMax{};
53 // Maximum number of slots that can be created
54 uint AuxiliaryEffectSlotMax{};
56 std::string mHrtfName;
57 std::vector<std::string> mHrtfList;
58 ALCenum mHrtfStatus{ALC_FALSE};
60 enum class OutputMode1 : ALCenum {
61 Any = ALC_ANY_SOFT,
62 Mono = ALC_MONO_SOFT,
63 Stereo = ALC_STEREO_SOFT,
64 StereoBasic = ALC_STEREO_BASIC_SOFT,
65 Uhj2 = ALC_STEREO_UHJ_SOFT,
66 Hrtf = ALC_STEREO_HRTF_SOFT,
67 Quad = ALC_QUAD_SOFT,
68 X51 = ALC_SURROUND_5_1_SOFT,
69 X61 = ALC_SURROUND_6_1_SOFT,
70 X71 = ALC_SURROUND_7_1_SOFT
72 OutputMode1 getOutputMode1() const noexcept;
74 using OutputMode = OutputMode1;
76 std::atomic<ALCenum> LastError{ALC_NO_ERROR};
78 // Map of Buffers for this device
79 std::mutex BufferLock;
80 std::vector<BufferSubList> BufferList;
82 // Map of Effects for this device
83 std::mutex EffectLock;
84 std::vector<EffectSubList> EffectList;
86 // Map of Filters for this device
87 std::mutex FilterLock;
88 std::vector<FilterSubList> FilterList;
90 #ifdef ALSOFT_EAX
91 ALuint eax_x_ram_free_size{eax_x_ram_max_size};
92 #endif // ALSOFT_EAX
95 std::unordered_map<ALuint,std::string> mBufferNames;
96 std::unordered_map<ALuint,std::string> mEffectNames;
97 std::unordered_map<ALuint,std::string> mFilterNames;
99 ALCdevice(DeviceType type);
100 ~ALCdevice();
102 void enumerateHrtfs();
104 bool getConfigValueBool(const std::string_view block, const std::string_view key, bool def)
105 { return GetConfigValueBool(DeviceName, block, key, def); }
107 template<typename T>
108 inline std::optional<T> configValue(const std::string_view block, const std::string_view key) = delete;
111 template<>
112 inline std::optional<std::string> ALCdevice::configValue(const std::string_view block, const std::string_view key)
113 { return ConfigValueStr(DeviceName, block, key); }
114 template<>
115 inline std::optional<int> ALCdevice::configValue(const std::string_view block, const std::string_view key)
116 { return ConfigValueInt(DeviceName, block, key); }
117 template<>
118 inline std::optional<uint> ALCdevice::configValue(const std::string_view block, const std::string_view key)
119 { return ConfigValueUInt(DeviceName, block, key); }
120 template<>
121 inline std::optional<float> ALCdevice::configValue(const std::string_view block, const std::string_view key)
122 { return ConfigValueFloat(DeviceName, block, key); }
123 template<>
124 inline std::optional<bool> ALCdevice::configValue(const std::string_view block, const std::string_view key)
125 { return ConfigValueBool(DeviceName, block, key); }
127 /** Stores the latest ALC device error. */
128 void alcSetError(ALCdevice *device, ALCenum errorCode);
130 #endif