diff options
Diffstat (limited to 'Alc')
-rw-r--r-- | Alc/alc.cpp | 3 | ||||
-rw-r--r-- | Alc/alcontext.h | 180 | ||||
-rw-r--r-- | Alc/alu.cpp | 15 | ||||
-rw-r--r-- | Alc/effects/autowah.cpp | 1 | ||||
-rw-r--r-- | Alc/effects/chorus.cpp | 1 | ||||
-rw-r--r-- | Alc/effects/compressor.cpp | 8 | ||||
-rw-r--r-- | Alc/effects/dedicated.cpp | 2 | ||||
-rw-r--r-- | Alc/effects/distortion.cpp | 1 | ||||
-rw-r--r-- | Alc/effects/echo.cpp | 1 | ||||
-rw-r--r-- | Alc/effects/equalizer.cpp | 1 | ||||
-rw-r--r-- | Alc/effects/fshifter.cpp | 2 | ||||
-rw-r--r-- | Alc/effects/modulator.cpp | 1 | ||||
-rw-r--r-- | Alc/effects/null.cpp | 2 | ||||
-rw-r--r-- | Alc/effects/pshifter.cpp | 2 | ||||
-rw-r--r-- | Alc/effects/reverb.cpp | 1 | ||||
-rw-r--r-- | Alc/mixvoice.cpp | 4 |
16 files changed, 210 insertions, 15 deletions
diff --git a/Alc/alc.cpp b/Alc/alc.cpp index c719eaa9..ec9a0adf 100644 --- a/Alc/alc.cpp +++ b/Alc/alc.cpp @@ -37,6 +37,7 @@ #include <algorithm> #include "alMain.h" +#include "alcontext.h" #include "alSource.h" #include "alListener.h" #include "alSource.h" @@ -2633,7 +2634,7 @@ static ALvoid InitContext(ALCcontext *Context) ATOMIC_INIT(&Context->ActiveAuxSlots, auxslots); //Set globals - Context->DistanceModel = DefaultDistanceModel; + Context->DistanceModel = DistanceModel::Default; Context->SourceDistanceModel = AL_FALSE; Context->DopplerFactor = 1.0f; Context->DopplerVelocity = 1.0f; diff --git a/Alc/alcontext.h b/Alc/alcontext.h new file mode 100644 index 00000000..9ef2db3b --- /dev/null +++ b/Alc/alcontext.h @@ -0,0 +1,180 @@ +#ifndef ALCONTEXT_H +#define ALCONTEXT_H + +#include "AL/al.h" +#include "AL/alc.h" +#include "AL/alext.h" +#include "inprogext.h" + +#include "atomic.h" +#include "vector.h" +#include "threads.h" + + +struct ALlistener; +struct ALsource; +struct ALeffectslot; +struct ALcontextProps; +struct ALlistenerProps; +struct ALvoiceProps; +struct ALeffectslotProps; +struct ALvoice; +struct ALeffectslotArray; +struct ll_ringbuffer; + +enum class DistanceModel { + InverseClamped = AL_INVERSE_DISTANCE_CLAMPED, + LinearClamped = AL_LINEAR_DISTANCE_CLAMPED, + ExponentClamped = AL_EXPONENT_DISTANCE_CLAMPED, + Inverse = AL_INVERSE_DISTANCE, + Linear = AL_LINEAR_DISTANCE, + Exponent = AL_EXPONENT_DISTANCE, + Disable = AL_NONE, + + Default = InverseClamped +}; + +struct SourceSubList { + uint64_t FreeMask; + ALsource *Sources; /* 64 */ +}; +TYPEDEF_VECTOR(SourceSubList, vector_SourceSubList) + +/* Effect slots are rather large, and apps aren't likely to have more than one + * or two (let alone 64), so hold them individually. + */ +using ALeffectslotPtr = struct ALeffectslot*; +TYPEDEF_VECTOR(ALeffectslotPtr, vector_ALeffectslotPtr) + +struct ALCcontext_struct { + RefCount ref; + + ALlistener *Listener; + + vector_SourceSubList SourceList; + ALuint NumSources; + almtx_t SourceLock; + + vector_ALeffectslotPtr EffectSlotList; + almtx_t EffectSlotLock; + + ATOMIC(ALenum) LastError; + + enum DistanceModel DistanceModel; + ALboolean SourceDistanceModel; + + ALfloat DopplerFactor; + ALfloat DopplerVelocity; + ALfloat SpeedOfSound; + ALfloat MetersPerUnit; + + ATOMIC(ALenum) PropsClean; + ATOMIC(ALenum) DeferUpdates; + + almtx_t PropLock; + + /* Counter for the pre-mixing updates, in 31.1 fixed point (lowest bit + * indicates if updates are currently happening). + */ + RefCount UpdateCount; + ATOMIC(ALenum) HoldUpdates; + + ALfloat GainBoost; + + ATOMIC(ALcontextProps*) Update; + + /* Linked lists of unused property containers, free to use for future + * updates. + */ + ATOMIC(ALcontextProps*) FreeContextProps; + ATOMIC(ALlistenerProps*) FreeListenerProps; + ATOMIC(ALvoiceProps*) FreeVoiceProps; + ATOMIC(ALeffectslotProps*) FreeEffectslotProps; + + ALvoice **Voices; + ALsizei VoiceCount; + ALsizei MaxVoices; + + ATOMIC(ALeffectslotArray*) ActiveAuxSlots; + + althrd_t EventThread; + alsem_t EventSem; + ll_ringbuffer *AsyncEvents; + ATOMIC(ALbitfieldSOFT) EnabledEvts; + almtx_t EventCbLock; + ALEVENTPROCSOFT EventCb; + void *EventParam; + + /* Default effect slot */ + ALeffectslot *DefaultSlot; + + ALCdevice *Device; + const ALCchar *ExtensionList; + + ATOMIC(ALCcontext*) next; + + /* Memory space used by the listener (and possibly default effect slot) */ + alignas(16) ALCbyte _listener_mem[]; +}; + +ALCcontext *GetContextRef(void); +void ALCcontext_DecRef(ALCcontext *context); + +void UpdateContextProps(ALCcontext *context); + +void ALCcontext_DeferUpdates(ALCcontext *context); +void ALCcontext_ProcessUpdates(ALCcontext *context); + +inline void LockEffectSlotList(ALCcontext *context) +{ almtx_lock(&context->EffectSlotLock); } +inline void UnlockEffectSlotList(ALCcontext *context) +{ almtx_unlock(&context->EffectSlotLock); } + + +/* Simple RAII context reference. Takes the reference of the provided + * ALCcontext, and decrements it when leaving scope. Movable (transfer + * reference) but not copyable (no new references). + */ +class ContextRef { + ALCcontext *mCtx{nullptr}; + + void release() noexcept + { + if(mCtx) + ALCcontext_DecRef(mCtx); + mCtx = nullptr; + } + +public: + ContextRef() noexcept = default; + explicit ContextRef(ALCcontext *ctx) noexcept : mCtx(ctx) { } + ~ContextRef() { release(); } + + ContextRef& operator=(const ContextRef&) = delete; + ContextRef& operator=(ContextRef&& rhs) noexcept + { + release(); + mCtx = rhs.mCtx; + rhs.mCtx = nullptr; + return *this; + } + + operator bool() const noexcept { return mCtx != nullptr; } + + ALCcontext* operator->() noexcept { return mCtx; } + ALCcontext* get() noexcept { return mCtx; } +}; + + +struct ALcontextProps { + ALfloat DopplerFactor; + ALfloat DopplerVelocity; + ALfloat SpeedOfSound; + ALboolean SourceDistanceModel; + enum DistanceModel DistanceModel; + ALfloat MetersPerUnit; + + ATOMIC(struct ALcontextProps*) next; +}; + +#endif /* ALCONTEXT_H */ diff --git a/Alc/alu.cpp b/Alc/alu.cpp index 3075f1ec..1895b777 100644 --- a/Alc/alu.cpp +++ b/Alc/alu.cpp @@ -27,6 +27,7 @@ #include <assert.h> #include "alMain.h" +#include "alcontext.h" #include "alSource.h" #include "alBuffer.h" #include "alListener.h" @@ -1218,12 +1219,12 @@ static void CalcAttnSourceParams(ALvoice *voice, const struct ALvoiceProps *prop switch(Listener->Params.SourceDistanceModel ? props->DistanceModel : Listener->Params.DistanceModel) { - case InverseDistanceClamped: + case DistanceModel::InverseClamped: ClampedDist = clampf(ClampedDist, props->RefDistance, props->MaxDistance); if(props->MaxDistance < props->RefDistance) break; /*fall-through*/ - case InverseDistance: + case DistanceModel::Inverse: if(!(props->RefDistance > 0.0f)) ClampedDist = props->RefDistance; else @@ -1238,12 +1239,12 @@ static void CalcAttnSourceParams(ALvoice *voice, const struct ALvoiceProps *prop } break; - case LinearDistanceClamped: + case DistanceModel::LinearClamped: ClampedDist = clampf(ClampedDist, props->RefDistance, props->MaxDistance); if(props->MaxDistance < props->RefDistance) break; /*fall-through*/ - case LinearDistance: + case DistanceModel::Linear: if(!(props->MaxDistance != props->RefDistance)) ClampedDist = props->RefDistance; else @@ -1260,12 +1261,12 @@ static void CalcAttnSourceParams(ALvoice *voice, const struct ALvoiceProps *prop } break; - case ExponentDistanceClamped: + case DistanceModel::ExponentClamped: ClampedDist = clampf(ClampedDist, props->RefDistance, props->MaxDistance); if(props->MaxDistance < props->RefDistance) break; /*fall-through*/ - case ExponentDistance: + case DistanceModel::Exponent: if(!(ClampedDist > 0.0f && props->RefDistance > 0.0f)) ClampedDist = props->RefDistance; else @@ -1276,7 +1277,7 @@ static void CalcAttnSourceParams(ALvoice *voice, const struct ALvoiceProps *prop } break; - case DisableDistance: + case DistanceModel::Disable: ClampedDist = props->RefDistance; break; } diff --git a/Alc/effects/autowah.cpp b/Alc/effects/autowah.cpp index b4ef8f3c..e2f07b6f 100644 --- a/Alc/effects/autowah.cpp +++ b/Alc/effects/autowah.cpp @@ -24,6 +24,7 @@ #include <stdlib.h> #include "alMain.h" +#include "alcontext.h" #include "alAuxEffectSlot.h" #include "alError.h" #include "alu.h" diff --git a/Alc/effects/chorus.cpp b/Alc/effects/chorus.cpp index b658098e..411ba6a5 100644 --- a/Alc/effects/chorus.cpp +++ b/Alc/effects/chorus.cpp @@ -24,6 +24,7 @@ #include <stdlib.h> #include "alMain.h" +#include "alcontext.h" #include "alAuxEffectSlot.h" #include "alError.h" #include "alu.h" diff --git a/Alc/effects/compressor.cpp b/Alc/effects/compressor.cpp index 0a307a5f..5603deea 100644 --- a/Alc/effects/compressor.cpp +++ b/Alc/effects/compressor.cpp @@ -18,13 +18,15 @@ * Or go to http://www.gnu.org/copyleft/lgpl.html */ +#include "config.h" + #include <stdlib.h> -#include "config.h" -#include "alError.h" #include "alMain.h" -#include "alAuxEffectSlot.h" +#include "alcontext.h" #include "alu.h" +#include "alAuxEffectSlot.h" +#include "alError.h" #define AMP_ENVELOPE_MIN 0.5f diff --git a/Alc/effects/dedicated.cpp b/Alc/effects/dedicated.cpp index dd250e64..705f7d41 100644 --- a/Alc/effects/dedicated.cpp +++ b/Alc/effects/dedicated.cpp @@ -23,10 +23,10 @@ #include <stdlib.h> #include "alMain.h" +#include "alcontext.h" #include "alAuxEffectSlot.h" #include "alError.h" #include "alu.h" -#include "filters/defs.h" struct ALdedicatedState final : public ALeffectState { diff --git a/Alc/effects/distortion.cpp b/Alc/effects/distortion.cpp index 75629d9c..7dd15981 100644 --- a/Alc/effects/distortion.cpp +++ b/Alc/effects/distortion.cpp @@ -24,6 +24,7 @@ #include <stdlib.h> #include "alMain.h" +#include "alcontext.h" #include "alAuxEffectSlot.h" #include "alError.h" #include "alu.h" diff --git a/Alc/effects/echo.cpp b/Alc/effects/echo.cpp index f987e582..492da6f6 100644 --- a/Alc/effects/echo.cpp +++ b/Alc/effects/echo.cpp @@ -24,6 +24,7 @@ #include <stdlib.h> #include "alMain.h" +#include "alcontext.h" #include "alFilter.h" #include "alAuxEffectSlot.h" #include "alError.h" diff --git a/Alc/effects/equalizer.cpp b/Alc/effects/equalizer.cpp index 8388a123..48c6d1e2 100644 --- a/Alc/effects/equalizer.cpp +++ b/Alc/effects/equalizer.cpp @@ -24,6 +24,7 @@ #include <stdlib.h> #include "alMain.h" +#include "alcontext.h" #include "alAuxEffectSlot.h" #include "alError.h" #include "alu.h" diff --git a/Alc/effects/fshifter.cpp b/Alc/effects/fshifter.cpp index 304e281f..f112c4c7 100644 --- a/Alc/effects/fshifter.cpp +++ b/Alc/effects/fshifter.cpp @@ -27,10 +27,10 @@ #include <algorithm> #include "alMain.h" +#include "alcontext.h" #include "alAuxEffectSlot.h" #include "alError.h" #include "alu.h" -#include "filters/defs.h" #include "alcomplex.h" diff --git a/Alc/effects/modulator.cpp b/Alc/effects/modulator.cpp index 19513add..7e8f8ce4 100644 --- a/Alc/effects/modulator.cpp +++ b/Alc/effects/modulator.cpp @@ -24,6 +24,7 @@ #include <stdlib.h> #include "alMain.h" +#include "alcontext.h" #include "alAuxEffectSlot.h" #include "alError.h" #include "alu.h" diff --git a/Alc/effects/null.cpp b/Alc/effects/null.cpp index 377593ab..0d85d505 100644 --- a/Alc/effects/null.cpp +++ b/Alc/effects/null.cpp @@ -4,7 +4,9 @@ #include "AL/al.h" #include "AL/alc.h" + #include "alMain.h" +#include "alcontext.h" #include "alAuxEffectSlot.h" #include "alError.h" diff --git a/Alc/effects/pshifter.cpp b/Alc/effects/pshifter.cpp index f0cdf53e..1199a19d 100644 --- a/Alc/effects/pshifter.cpp +++ b/Alc/effects/pshifter.cpp @@ -27,10 +27,10 @@ #include <algorithm> #include "alMain.h" +#include "alcontext.h" #include "alAuxEffectSlot.h" #include "alError.h" #include "alu.h" -#include "filters/defs.h" #include "alcomplex.h" diff --git a/Alc/effects/reverb.cpp b/Alc/effects/reverb.cpp index 5cfc0012..fe9cc9f7 100644 --- a/Alc/effects/reverb.cpp +++ b/Alc/effects/reverb.cpp @@ -25,6 +25,7 @@ #include <math.h> #include "alMain.h" +#include "alcontext.h" #include "alu.h" #include "alAuxEffectSlot.h" #include "alListener.h" diff --git a/Alc/mixvoice.cpp b/Alc/mixvoice.cpp index 03d51dd6..f89b6efa 100644 --- a/Alc/mixvoice.cpp +++ b/Alc/mixvoice.cpp @@ -26,9 +26,11 @@ #include <ctype.h> #include <assert.h> -#include "alMain.h" #include "AL/al.h" #include "AL/alc.h" + +#include "alMain.h" +#include "alcontext.h" #include "alSource.h" #include "alBuffer.h" #include "alListener.h" |