diff options
author | Chris Robinson <[email protected]> | 2021-04-24 08:28:13 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2021-04-24 08:28:13 -0700 |
commit | b54bb388a3dbd92518beef4bda03df5854aad1a9 (patch) | |
tree | 8cde0be5ca02b61ae81bf0c3ccdd3a2439b1923a /alc/alcmain.h | |
parent | 519672c8e54585bc6d827dd3efed943e06b3e6cd (diff) |
Create a base the ALCdevice and ALCcontext structs
A base that contains the API-agnostic data, with ALCdevice and ALCcontext being
for AL-specific data.
Diffstat (limited to 'alc/alcmain.h')
-rw-r--r-- | alc/alcmain.h | 178 |
1 files changed, 94 insertions, 84 deletions
diff --git a/alc/alcmain.h b/alc/alcmain.h index 69f05bfe..025ba3d4 100644 --- a/alc/alcmain.h +++ b/alc/alcmain.h @@ -38,6 +38,7 @@ struct ALeffect; struct ALfilter; struct BackendBase; struct Compressor; +struct ContextBase; struct EffectState; struct UhjEncoder; struct bs2b; @@ -75,52 +76,6 @@ struct InputRemixMap { }; -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; } -}; - - /* Maximum delay in samples for speaker distance compensation. */ #define MAX_DELAY_LENGTH 1024 @@ -179,7 +134,7 @@ enum { DeviceFlagsCount }; -struct ALCdevice : public al::intrusive_ref<ALCdevice> { +struct DeviceBase { std::atomic<bool> Connected{true}; const DeviceType Type{}; @@ -203,10 +158,7 @@ struct ALCdevice : public al::intrusive_ref<ALCdevice> { // Device flags std::bitset<DeviceFlagsCount> Flags{}; - // Maximum number of sources that can be created - uint SourcesMax{}; - // Maximum number of slots that can be created - uint AuxiliaryEffectSlotMax{}; + uint NumAuxSends{}; /* Rendering mode. */ RenderMode mRenderMode{RenderMode::Normal}; @@ -257,7 +209,7 @@ struct ALCdevice : public al::intrusive_ref<ALCdevice> { /* Stereo-to-binaural filter */ std::unique_ptr<bs2b> Bs2b; - using PostProc = void(ALCdevice::*)(const size_t SamplesToDo); + using PostProc = void(DeviceBase::*)(const size_t SamplesToDo); PostProc PostProcess{nullptr}; std::unique_ptr<Compressor> Limiter; @@ -277,7 +229,7 @@ struct ALCdevice : public al::intrusive_ref<ALCdevice> { RefCount MixCount{0u}; // Contexts created on this device - std::atomic<al::FlexArray<ALCcontext*>*> mContexts{nullptr}; + std::atomic<al::FlexArray<ContextBase*>*> mContexts{nullptr}; /* This lock protects the device state (format, update size, etc) from * being from being changed in multiple threads, or being accessed while @@ -287,37 +239,10 @@ struct ALCdevice : public al::intrusive_ref<ALCdevice> { std::unique_ptr<BackendBase> Backend; - ALCuint NumMonoSources{}; - ALCuint NumStereoSources{}; - ALCuint NumAuxSends{}; - - std::string mHrtfName; - al::vector<std::string> mHrtfList; - ALCenum mHrtfStatus{ALC_FALSE}; - - ALCenum LimiterState{ALC_DONT_CARE_SOFT}; - - std::atomic<ALCenum> LastError{ALC_NO_ERROR}; - - // Map of Buffers for this device - std::mutex BufferLock; - al::vector<BufferSubList> BufferList; - - // Map of Effects for this device - std::mutex EffectLock; - al::vector<EffectSubList> EffectList; - - // Map of Filters for this device - std::mutex FilterLock; - al::vector<FilterSubList> FilterList; - - - ALCdevice(DeviceType type); - ALCdevice(const ALCdevice&) = delete; - ALCdevice& operator=(const ALCdevice&) = delete; - ~ALCdevice(); - - void enumerateHrtfs(); + DeviceBase(DeviceType type); + DeviceBase(const DeviceBase&) = delete; + DeviceBase& operator=(const DeviceBase&) = delete; + ~DeviceBase(); uint bytesFromFmt() const noexcept { return BytesFromDevFmt(FmtType); } uint channelsFromFmt() const noexcept { return ChannelsFromDevFmt(FmtChans, mAmbiOrder); } @@ -350,6 +275,91 @@ struct ALCdevice : public al::intrusive_ref<ALCdevice> { #endif void handleDisconnect(const char *msg, ...); + DISABLE_ALLOC() +}; + + +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 { + 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; + al::vector<std::string> mHrtfList; + ALCenum mHrtfStatus{ALC_FALSE}; + + ALCenum LimiterState{ALC_DONT_CARE_SOFT}; + + std::atomic<ALCenum> LastError{ALC_NO_ERROR}; + + // Map of Buffers for this device + std::mutex BufferLock; + al::vector<BufferSubList> BufferList; + + // Map of Effects for this device + std::mutex EffectLock; + al::vector<EffectSubList> EffectList; + + // Map of Filters for this device + std::mutex FilterLock; + al::vector<FilterSubList> FilterList; + + + ALCdevice(DeviceType type) : DeviceBase{type} { } + ~ALCdevice(); + + void enumerateHrtfs(); + DEF_NEWDEL(ALCdevice) }; |