aboutsummaryrefslogtreecommitdiffstats
path: root/OpenAL32
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2018-11-19 22:34:26 -0800
committerChris Robinson <[email protected]>2018-11-19 22:34:26 -0800
commit8472a9d916eae13771455c2b527c1148aa71d8fb (patch)
treed86470a5e2882ce73a86a892eac7082bd2b97566 /OpenAL32
parent6ac84c7a5f6d267522bdc872802c8940dcd2adec (diff)
Use proper inheritence for the effect state objects
Diffstat (limited to 'OpenAL32')
-rw-r--r--OpenAL32/Include/alAuxEffectSlot.h59
-rw-r--r--OpenAL32/Include/alMain.h3
-rw-r--r--OpenAL32/alAuxEffectSlot.cpp59
-rw-r--r--OpenAL32/event.cpp2
4 files changed, 40 insertions, 83 deletions
diff --git a/OpenAL32/Include/alAuxEffectSlot.h b/OpenAL32/Include/alAuxEffectSlot.h
index d3d4e704..ca2cb663 100644
--- a/OpenAL32/Include/alAuxEffectSlot.h
+++ b/OpenAL32/Include/alAuxEffectSlot.h
@@ -8,58 +8,31 @@
#include "atomic.h"
-struct ALeffectStateVtable;
struct ALeffectslot;
-typedef struct ALeffectState {
- RefCount Ref;
- const struct ALeffectStateVtable *vtbl;
- ALfloat (*OutBuffer)[BUFFERSIZE];
- ALsizei OutChannels;
-} ALeffectState;
+struct EffectState {
+ RefCount mRef{1u};
-void ALeffectState_Construct(ALeffectState *state);
-void ALeffectState_Destruct(ALeffectState *state);
+ ALfloat (*mOutBuffer)[BUFFERSIZE]{nullptr};
+ ALsizei mOutChannels{0};
-struct ALeffectStateVtable {
- void (*const Destruct)(ALeffectState *state);
- ALboolean (*const deviceUpdate)(ALeffectState *state, ALCdevice *device);
- void (*const update)(ALeffectState *state, const ALCcontext *context, const struct ALeffectslot *slot, const union ALeffectProps *props);
- void (*const process)(ALeffectState *state, ALsizei samplesToDo, const ALfloat (*RESTRICT samplesIn)[BUFFERSIZE], ALfloat (*RESTRICT samplesOut)[BUFFERSIZE], ALsizei numChannels);
+ virtual ~EffectState() = default;
- void (*const Delete)(void *ptr);
-};
+ virtual ALboolean deviceUpdate(ALCdevice *device) = 0;
+ virtual void update(const ALCcontext *context, const ALeffectslot *slot, const ALeffectProps *props) = 0;
+ virtual void process(ALsizei samplesToDo, const ALfloat (*RESTRICT samplesIn)[BUFFERSIZE], ALfloat (*RESTRICT samplesOut)[BUFFERSIZE], ALsizei numChannels) = 0;
-/* Small hack to use a pointer-to-array types as a normal argument type.
- * Shouldn't be used directly.
- */
-typedef ALfloat ALfloatBUFFERSIZE[BUFFERSIZE];
-
-#define DEFINE_ALEFFECTSTATE_VTABLE(T) \
-DECLARE_THUNK(T, ALeffectState, void, Destruct) \
-DECLARE_THUNK1(T, ALeffectState, ALboolean, deviceUpdate, ALCdevice*) \
-DECLARE_THUNK3(T, ALeffectState, void, update, const ALCcontext*, const ALeffectslot*, const ALeffectProps*) \
-DECLARE_THUNK4(T, ALeffectState, void, process, ALsizei, const ALfloatBUFFERSIZE*RESTRICT, ALfloatBUFFERSIZE*RESTRICT, ALsizei) \
-static void T##_ALeffectState_Delete(void *ptr) \
-{ return T##_Delete(STATIC_UPCAST(T, ALeffectState, (ALeffectState*)ptr)); } \
- \
-static const struct ALeffectStateVtable T##_ALeffectState_vtable = { \
- T##_ALeffectState_Destruct, \
- \
- T##_ALeffectState_deviceUpdate, \
- T##_ALeffectState_update, \
- T##_ALeffectState_process, \
- \
- T##_ALeffectState_Delete, \
-}
+ void IncRef() noexcept;
+ void DecRef() noexcept;
+};
struct EffectStateFactory {
virtual ~EffectStateFactory() { }
- virtual ALeffectState *create() = 0;
+ virtual EffectState *create() = 0;
};
@@ -79,7 +52,7 @@ struct ALeffectslotProps {
ALenum Type;
ALeffectProps Props;
- ALeffectState *State;
+ EffectState *State;
ATOMIC(struct ALeffectslotProps*) next;
};
@@ -93,7 +66,7 @@ struct ALeffectslot {
ALenum Type{AL_EFFECT_NULL};
ALeffectProps Props{};
- ALeffectState *State{nullptr};
+ EffectState *State{nullptr};
} Effect;
ATOMIC(ALenum) PropsClean{AL_TRUE};
@@ -108,7 +81,7 @@ struct ALeffectslot {
ALenum EffectType{AL_EFFECT_NULL};
ALeffectProps EffectProps{};
- ALeffectState *EffectState{nullptr};
+ EffectState *EffectState{nullptr};
ALfloat RoomRolloff{0.0f}; /* Added to the source's room rolloff, not multiplied. */
ALfloat DecayTime{0.0f};
@@ -167,6 +140,4 @@ EffectStateFactory *DedicatedStateFactory_getFactory(void);
ALenum InitializeEffect(ALCcontext *Context, ALeffectslot *EffectSlot, ALeffect *effect);
-void ALeffectState_DecRef(ALeffectState *state);
-
#endif
diff --git a/OpenAL32/Include/alMain.h b/OpenAL32/Include/alMain.h
index 64297592..8f08d94a 100644
--- a/OpenAL32/Include/alMain.h
+++ b/OpenAL32/Include/alMain.h
@@ -206,6 +206,7 @@ struct ALCbackend;
struct ALbuffer;
struct ALeffect;
struct ALfilter;
+struct EffectState;
#define DEFAULT_OUTPUT_RATE (44100)
@@ -755,7 +756,7 @@ typedef struct AsyncEvent {
ALuint param;
ALchar msg[1008];
} user;
- struct ALeffectState *EffectState;
+ EffectState *mEffectState;
} u;
} AsyncEvent;
#define ASYNC_EVENT(t) { t, { 0 } }
diff --git a/OpenAL32/alAuxEffectSlot.cpp b/OpenAL32/alAuxEffectSlot.cpp
index 4e25d3ee..cab9e43d 100644
--- a/OpenAL32/alAuxEffectSlot.cpp
+++ b/OpenAL32/alAuxEffectSlot.cpp
@@ -74,8 +74,6 @@ static inline EffectStateFactory *getFactoryByType(ALenum type)
return nullptr;
}
-static void ALeffectState_IncRef(ALeffectState *state);
-
static inline ALeffectslot *LookupEffectSlot(ALCcontext *context, ALuint id)
{
@@ -483,7 +481,7 @@ ALenum InitializeEffect(ALCcontext *Context, ALeffectslot *EffectSlot, ALeffect
ALCdevice *Device = Context->Device;
ALenum newtype = (effect ? effect->type : AL_EFFECT_NULL);
struct ALeffectslotProps *props;
- ALeffectState *State;
+ EffectState *State;
if(newtype != EffectSlot->Effect.Type)
{
@@ -498,13 +496,13 @@ ALenum InitializeEffect(ALCcontext *Context, ALeffectslot *EffectSlot, ALeffect
START_MIXER_MODE();
almtx_lock(&Device->BackendLock);
- State->OutBuffer = Device->Dry.Buffer;
- State->OutChannels = Device->Dry.NumChannels;
- if(V(State,deviceUpdate)(Device) == AL_FALSE)
+ State->mOutBuffer = Device->Dry.Buffer;
+ State->mOutChannels = Device->Dry.NumChannels;
+ if(State->deviceUpdate(Device) == AL_FALSE)
{
almtx_unlock(&Device->BackendLock);
LEAVE_MIXER_MODE();
- ALeffectState_DecRef(State);
+ State->DecRef();
return AL_OUT_OF_MEMORY;
}
almtx_unlock(&Device->BackendLock);
@@ -521,7 +519,7 @@ ALenum InitializeEffect(ALCcontext *Context, ALeffectslot *EffectSlot, ALeffect
EffectSlot->Effect.Props = effect->Props;
}
- ALeffectState_DecRef(EffectSlot->Effect.State);
+ EffectSlot->Effect.State->DecRef();
EffectSlot->Effect.State = State;
}
else if(effect)
@@ -532,7 +530,7 @@ ALenum InitializeEffect(ALCcontext *Context, ALeffectslot *EffectSlot, ALeffect
while(props)
{
if(props->State)
- ALeffectState_DecRef(props->State);
+ props->State->DecRef();
props->State = nullptr;
props = ATOMIC_LOAD(&props->next, almemory_order_relaxed);
}
@@ -541,30 +539,17 @@ ALenum InitializeEffect(ALCcontext *Context, ALeffectslot *EffectSlot, ALeffect
}
-static void ALeffectState_IncRef(ALeffectState *state)
+void EffectState::IncRef() noexcept
{
- auto ref = IncrementRef(&state->Ref);
- TRACEREF("%p increasing refcount to %u\n", state, ref);
-}
-
-void ALeffectState_DecRef(ALeffectState *state)
-{
- auto ref = DecrementRef(&state->Ref);
- TRACEREF("%p decreasing refcount to %u\n", state, ref);
- if(ref == 0) DELETE_OBJ(state);
-}
-
-
-void ALeffectState_Construct(ALeffectState *state)
-{
- InitRef(&state->Ref, 1);
-
- state->OutBuffer = nullptr;
- state->OutChannels = 0;
+ auto ref = IncrementRef(&mRef);
+ TRACEREF("%p increasing refcount to %u\n", this, ref);
}
-void ALeffectState_Destruct(ALeffectState *UNUSED(state))
+void EffectState::DecRef() noexcept
{
+ auto ref = DecrementRef(&mRef);
+ TRACEREF("%p decreasing refcount to %u\n", this, ref);
+ if(ref == 0) delete this;
}
@@ -664,7 +649,7 @@ ALenum InitEffectSlot(ALeffectslot *slot)
slot->Effect.State = factory->create();
if(!slot->Effect.State) return AL_OUT_OF_MEMORY;
- ALeffectState_IncRef(slot->Effect.State);
+ slot->Effect.State->IncRef();
slot->Params.EffectState = slot->Effect.State;
return AL_NO_ERROR;
}
@@ -674,21 +659,21 @@ ALeffectslot::~ALeffectslot()
struct ALeffectslotProps *props{Update.load()};
if(props)
{
- if(props->State) ALeffectState_DecRef(props->State);
+ if(props->State) props->State->DecRef();
TRACE("Freed unapplied AuxiliaryEffectSlot update %p\n", props);
al_free(props);
}
if(Effect.State)
- ALeffectState_DecRef(Effect.State);
+ Effect.State->DecRef();
if(Params.EffectState)
- ALeffectState_DecRef(Params.EffectState);
+ Params.EffectState->DecRef();
}
void UpdateEffectSlotProps(ALeffectslot *slot, ALCcontext *context)
{
struct ALeffectslotProps *props;
- ALeffectState *oldstate;
+ EffectState *oldstate;
/* Get an unused property container, or allocate a new one as needed. */
props = context->FreeEffectslotProps.load(std::memory_order_relaxed);
@@ -712,7 +697,7 @@ void UpdateEffectSlotProps(ALeffectslot *slot, ALCcontext *context)
/* Swap out any stale effect state object there may be in the container, to
* delete it.
*/
- ALeffectState_IncRef(slot->Effect.State);
+ slot->Effect.State->IncRef();
oldstate = props->State;
props->State = slot->Effect.State;
@@ -724,13 +709,13 @@ void UpdateEffectSlotProps(ALeffectslot *slot, ALCcontext *context)
* freelist.
*/
if(props->State)
- ALeffectState_DecRef(props->State);
+ props->State->DecRef();
props->State = nullptr;
AtomicReplaceHead(context->FreeEffectslotProps, props);
}
if(oldstate)
- ALeffectState_DecRef(oldstate);
+ oldstate->DecRef();
}
void UpdateAllEffectSlotProps(ALCcontext *context)
diff --git a/OpenAL32/event.cpp b/OpenAL32/event.cpp
index 1dc2745f..d6fa01fb 100644
--- a/OpenAL32/event.cpp
+++ b/OpenAL32/event.cpp
@@ -34,7 +34,7 @@ static int EventThread(ALCcontext *context)
if(evt.EnumType == EventType_ReleaseEffectState)
{
- ALeffectState_DecRef(evt.u.EffectState);
+ evt.u.mEffectState->DecRef();
continue;
}