11 #include <unordered_map>
12 #include <string_view>
20 #include "core/device.h"
21 #include "intrusive_ptr.h"
24 #include "al/eax/x_ram.h"
32 using uint
= unsigned int;
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.
45 std::unique_ptr
<BackendBase
> Backend
;
47 ALCuint NumMonoSources
{};
48 ALCuint NumStereoSources
{};
50 // Maximum number of sources that can be created
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
{
62 Stereo
= ALC_STEREO_SOFT
,
63 StereoBasic
= ALC_STEREO_BASIC_SOFT
,
64 Uhj2
= ALC_STEREO_UHJ_SOFT
,
65 Hrtf
= ALC_STEREO_HRTF_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
;
90 ALuint eax_x_ram_free_size
{eax_x_ram_max_size
};
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
);
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;
115 auto Device::configValue(const std::string_view block
, const std::string_view key
) -> std::optional
<std::string
>
116 { return ConfigValueStr(mDeviceName
, block
, key
); }
118 auto Device::configValue(const std::string_view block
, const std::string_view key
) -> std::optional
<int>
119 { return ConfigValueInt(mDeviceName
, block
, key
); }
121 auto Device::configValue(const std::string_view block
, const std::string_view key
) -> std::optional
<uint
>
122 { return ConfigValueUInt(mDeviceName
, block
, key
); }
124 auto Device::configValue(const std::string_view block
, const std::string_view key
) -> std::optional
<float>
125 { return ConfigValueFloat(mDeviceName
, block
, key
); }
127 auto Device::configValue(const std::string_view block
, const std::string_view key
) -> std::optional
<bool>
128 { return ConfigValueBool(mDeviceName
, block
, key
); }
132 /** Stores the latest ALC device error. */
133 void alcSetError(al::Device
*device
, ALCenum errorCode
);