axmol/thirdparty/openal/alc/device.h

170 lines
5.1 KiB
C
Raw Normal View History

2021-05-14 10:15:42 +08:00
#ifndef ALC_DEVICE_H
#define ALC_DEVICE_H
#include <atomic>
2022-04-25 12:02:45 +08:00
#include <memory>
2021-05-14 10:15:42 +08:00
#include <mutex>
#include <optional>
2021-05-14 10:15:42 +08:00
#include <stdint.h>
#include <string>
#include <utility>
#include <vector>
2021-05-14 10:15:42 +08:00
#include "AL/alc.h"
#include "AL/alext.h"
2022-04-25 12:02:45 +08:00
#include "alconfig.h"
2021-05-14 10:15:42 +08:00
#include "almalloc.h"
#include "alnumeric.h"
#include "core/device.h"
2022-04-25 12:02:45 +08:00
#include "inprogext.h"
2021-05-14 10:15:42 +08:00
#include "intrusive_ptr.h"
2022-04-25 12:02:45 +08:00
#ifdef ALSOFT_EAX
#include "al/eax/x_ram.h"
2022-04-25 12:02:45 +08:00
#endif // ALSOFT_EAX
2021-05-14 10:15:42 +08:00
struct ALbuffer;
struct ALeffect;
struct ALfilter;
2022-04-25 12:02:45 +08:00
struct BackendBase;
2021-05-14 10:15:42 +08:00
using uint = unsigned int;
struct BufferSubList {
uint64_t FreeMask{~0_u64};
ALbuffer *Buffers{nullptr}; /* 64 */
BufferSubList() noexcept = default;
BufferSubList(const BufferSubList&) = delete;
BufferSubList(BufferSubList&& rhs) noexcept : FreeMask{rhs.FreeMask}, Buffers{rhs.Buffers}
{ rhs.FreeMask = ~0_u64; rhs.Buffers = nullptr; }
~BufferSubList();
BufferSubList& operator=(const BufferSubList&) = delete;
BufferSubList& operator=(BufferSubList&& rhs) noexcept
{ std::swap(FreeMask, rhs.FreeMask); std::swap(Buffers, rhs.Buffers); return *this; }
};
struct EffectSubList {
uint64_t FreeMask{~0_u64};
ALeffect *Effects{nullptr}; /* 64 */
EffectSubList() noexcept = default;
EffectSubList(const EffectSubList&) = delete;
EffectSubList(EffectSubList&& rhs) noexcept : FreeMask{rhs.FreeMask}, Effects{rhs.Effects}
{ rhs.FreeMask = ~0_u64; rhs.Effects = nullptr; }
~EffectSubList();
EffectSubList& operator=(const EffectSubList&) = delete;
EffectSubList& operator=(EffectSubList&& rhs) noexcept
{ std::swap(FreeMask, rhs.FreeMask); std::swap(Effects, rhs.Effects); return *this; }
};
struct FilterSubList {
uint64_t FreeMask{~0_u64};
ALfilter *Filters{nullptr}; /* 64 */
FilterSubList() noexcept = default;
FilterSubList(const FilterSubList&) = delete;
FilterSubList(FilterSubList&& rhs) noexcept : FreeMask{rhs.FreeMask}, Filters{rhs.Filters}
{ rhs.FreeMask = ~0_u64; rhs.Filters = nullptr; }
~FilterSubList();
FilterSubList& operator=(const FilterSubList&) = delete;
FilterSubList& operator=(FilterSubList&& rhs) noexcept
{ std::swap(FreeMask, rhs.FreeMask); std::swap(Filters, rhs.Filters); return *this; }
};
struct ALCdevice : public al::intrusive_ref<ALCdevice>, DeviceBase {
2022-04-25 12:02:45 +08:00
/* This lock protects the device state (format, update size, etc) from
* being from being changed in multiple threads, or being accessed while
* being changed. It's also used to serialize calls to the backend.
*/
std::mutex StateLock;
std::unique_ptr<BackendBase> Backend;
2021-05-14 10:15:42 +08:00
ALCuint NumMonoSources{};
ALCuint NumStereoSources{};
// Maximum number of sources that can be created
uint SourcesMax{};
// Maximum number of slots that can be created
uint AuxiliaryEffectSlotMax{};
std::string mHrtfName;
std::vector<std::string> mHrtfList;
2021-05-14 10:15:42 +08:00
ALCenum mHrtfStatus{ALC_FALSE};
2022-04-25 12:02:45 +08:00
enum class OutputMode1 : ALCenum {
Any = ALC_ANY_SOFT,
Mono = ALC_MONO_SOFT,
Stereo = ALC_STEREO_SOFT,
StereoBasic = ALC_STEREO_BASIC_SOFT,
Uhj2 = ALC_STEREO_UHJ_SOFT,
Hrtf = ALC_STEREO_HRTF_SOFT,
Quad = ALC_QUAD_SOFT,
X51 = ALC_SURROUND_5_1_SOFT,
X61 = ALC_SURROUND_6_1_SOFT,
X71 = ALC_SURROUND_7_1_SOFT
};
OutputMode1 getOutputMode1() const noexcept;
using OutputMode = OutputMode1;
2021-05-14 10:15:42 +08:00
std::atomic<ALCenum> LastError{ALC_NO_ERROR};
// Map of Buffers for this device
std::mutex BufferLock;
std::vector<BufferSubList> BufferList;
2021-05-14 10:15:42 +08:00
// Map of Effects for this device
std::mutex EffectLock;
std::vector<EffectSubList> EffectList;
2021-05-14 10:15:42 +08:00
// Map of Filters for this device
std::mutex FilterLock;
std::vector<FilterSubList> FilterList;
2021-05-14 10:15:42 +08:00
2022-04-25 12:02:45 +08:00
#ifdef ALSOFT_EAX
ALuint eax_x_ram_free_size{eax_x_ram_max_size};
#endif // ALSOFT_EAX
2021-05-14 10:15:42 +08:00
2022-04-25 12:02:45 +08:00
ALCdevice(DeviceType type);
2021-05-14 10:15:42 +08:00
~ALCdevice();
void enumerateHrtfs();
2022-04-25 12:02:45 +08:00
bool getConfigValueBool(const char *block, const char *key, bool def)
{ return GetConfigValueBool(DeviceName.c_str(), block, key, def); }
template<typename T>
inline std::optional<T> configValue(const char *block, const char *key) = delete;
2022-04-25 12:02:45 +08:00
2021-05-14 10:15:42 +08:00
DEF_NEWDEL(ALCdevice)
};
2022-04-25 12:02:45 +08:00
template<>
inline std::optional<std::string> ALCdevice::configValue(const char *block, const char *key)
2022-04-25 12:02:45 +08:00
{ return ConfigValueStr(DeviceName.c_str(), block, key); }
template<>
inline std::optional<int> ALCdevice::configValue(const char *block, const char *key)
2022-04-25 12:02:45 +08:00
{ return ConfigValueInt(DeviceName.c_str(), block, key); }
template<>
inline std::optional<uint> ALCdevice::configValue(const char *block, const char *key)
2022-04-25 12:02:45 +08:00
{ return ConfigValueUInt(DeviceName.c_str(), block, key); }
template<>
inline std::optional<float> ALCdevice::configValue(const char *block, const char *key)
2022-04-25 12:02:45 +08:00
{ return ConfigValueFloat(DeviceName.c_str(), block, key); }
template<>
inline std::optional<bool> ALCdevice::configValue(const char *block, const char *key)
2022-04-25 12:02:45 +08:00
{ return ConfigValueBool(DeviceName.c_str(), block, key); }
/** Stores the latest ALC device error. */
void alcSetError(ALCdevice *device, ALCenum errorCode);
2021-05-14 10:15:42 +08:00
#endif