diff options
author | Chris Robinson <[email protected]> | 2020-05-10 20:16:43 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2020-05-10 20:16:43 -0700 |
commit | 0406e3bef75bd42e310f147fc3f9589859140f3f (patch) | |
tree | 452ec840dde654776ca7cb81d28861c2ff27fefa | |
parent | 2fb4ac1621dff45940c40bfdf4d82737bb4e6fc3 (diff) |
Change a couple functions into member functions
-rw-r--r-- | al/auxeffectslot.cpp | 117 | ||||
-rw-r--r-- | al/auxeffectslot.h | 9 | ||||
-rw-r--r-- | alc/alc.cpp | 12 |
3 files changed, 68 insertions, 70 deletions
diff --git a/al/auxeffectslot.cpp b/al/auxeffectslot.cpp index 62cf4514..7c20ec64 100644 --- a/al/auxeffectslot.cpp +++ b/al/auxeffectslot.cpp @@ -199,7 +199,7 @@ ALeffectslot *AllocEffectSlot(ALCcontext *context) auto slidx = static_cast<ALuint>(CTZ64(sublist->FreeMask)); ALeffectslot *slot{::new (sublist->EffectSlots + slidx) ALeffectslot{}}; - if(ALenum err{InitEffectSlot(slot)}) + if(ALenum err{slot->init()}) { al::destroy_at(slot); context->setError(err, "Effect slot object initialization failed"); @@ -231,7 +231,7 @@ void FreeEffectSlot(ALCcontext *context, ALeffectslot *slot) #define DO_UPDATEPROPS() do { \ if(!context->mDeferUpdates.load(std::memory_order_acquire)) \ - UpdateEffectSlotProps(slot, context.get()); \ + slot->updateProps(context.get()); \ else \ slot->PropsClean.clear(std::memory_order_release); \ } while(0) @@ -381,7 +381,7 @@ START_API_FUNC ALeffect *effect{value ? LookupEffect(device, static_cast<ALuint>(value)) : nullptr}; if(!(value == 0 || effect != nullptr)) SETERR_RETURN(context, AL_INVALID_VALUE,, "Invalid effect ID %u", value); - err = InitializeEffect(context.get(), slot, effect); + err = slot->initEffect(effect, context.get()); } if(err != AL_NO_ERROR) { @@ -420,7 +420,7 @@ START_API_FUNC if(target) IncrementRef(target->ref); DecrementRef(oldtarget->ref); slot->Target = target; - UpdateEffectSlotProps(slot, context.get()); + slot->updateProps(context.get()); return; } @@ -631,10 +631,43 @@ START_API_FUNC END_API_FUNC -ALenum InitializeEffect(ALCcontext *Context, ALeffectslot *EffectSlot, ALeffect *effect) +ALeffectslot::~ALeffectslot() +{ + if(Target) + DecrementRef(Target->ref); + Target = nullptr; + + ALeffectslotProps *props{Params.Update.load()}; + if(props) + { + if(props->State) props->State->release(); + TRACE("Freed unapplied AuxiliaryEffectSlot update %p\n", + decltype(std::declval<void*>()){props}); + delete props; + } + + if(Effect.State) + Effect.State->release(); + if(Params.mEffectState) + Params.mEffectState->release(); +} + +ALenum ALeffectslot::init() +{ + EffectStateFactory *factory{getFactoryByType(Effect.Type)}; + if(!factory) return AL_INVALID_VALUE; + Effect.State = factory->create(); + if(!Effect.State) return AL_OUT_OF_MEMORY; + + Effect.State->add_ref(); + Params.mEffectState = Effect.State; + return AL_NO_ERROR; +} + +ALenum ALeffectslot::initEffect(ALeffect *effect, ALCcontext *context) { ALenum newtype{effect ? effect->type : AL_EFFECT_NULL}; - if(newtype != EffectSlot->Effect.Type) + if(newtype != Effect.Type) { EffectStateFactory *factory{getFactoryByType(newtype)}; if(!factory) @@ -645,7 +678,7 @@ ALenum InitializeEffect(ALCcontext *Context, ALeffectslot *EffectSlot, ALeffect EffectState *State{factory->create()}; if(!State) return AL_OUT_OF_MEMORY; - ALCdevice *Device{Context->mDevice.get()}; + ALCdevice *Device{context->mDevice.get()}; std::unique_lock<std::mutex> statelock{Device->StateLock}; State->mOutTarget = Device->Dry.Buffer; { @@ -655,23 +688,23 @@ ALenum InitializeEffect(ALCcontext *Context, ALeffectslot *EffectSlot, ALeffect if(!effect) { - EffectSlot->Effect.Type = AL_EFFECT_NULL; - EffectSlot->Effect.Props = EffectProps{}; + Effect.Type = AL_EFFECT_NULL; + Effect.Props = EffectProps{}; } else { - EffectSlot->Effect.Type = effect->type; - EffectSlot->Effect.Props = effect->Props; + Effect.Type = effect->type; + Effect.Props = effect->Props; } - EffectSlot->Effect.State->release(); - EffectSlot->Effect.State = State; + Effect.State->release(); + Effect.State = State; } else if(effect) - EffectSlot->Effect.Props = effect->Props; + Effect.Props = effect->Props; /* Remove state references from old effect slot property updates. */ - ALeffectslotProps *props{Context->mFreeEffectslotProps.load()}; + ALeffectslotProps *props{context->mFreeEffectslotProps.load()}; while(props) { if(props->State) @@ -683,41 +716,7 @@ ALenum InitializeEffect(ALCcontext *Context, ALeffectslot *EffectSlot, ALeffect return AL_NO_ERROR; } - -ALenum InitEffectSlot(ALeffectslot *slot) -{ - EffectStateFactory *factory{getFactoryByType(slot->Effect.Type)}; - if(!factory) return AL_INVALID_VALUE; - slot->Effect.State = factory->create(); - if(!slot->Effect.State) return AL_OUT_OF_MEMORY; - - slot->Effect.State->add_ref(); - slot->Params.mEffectState = slot->Effect.State; - return AL_NO_ERROR; -} - -ALeffectslot::~ALeffectslot() -{ - if(Target) - DecrementRef(Target->ref); - Target = nullptr; - - ALeffectslotProps *props{Params.Update.load()}; - if(props) - { - if(props->State) props->State->release(); - TRACE("Freed unapplied AuxiliaryEffectSlot update %p\n", - decltype(std::declval<void*>()){props}); - delete props; - } - - if(Effect.State) - Effect.State->release(); - if(Params.mEffectState) - Params.mEffectState->release(); -} - -void UpdateEffectSlotProps(ALeffectslot *slot, ALCcontext *context) +void ALeffectslot::updateProps(ALCcontext *context) { /* Get an unused property container, or allocate a new one as needed. */ ALeffectslotProps *props{context->mFreeEffectslotProps.load(std::memory_order_relaxed)}; @@ -733,21 +732,21 @@ void UpdateEffectSlotProps(ALeffectslot *slot, ALCcontext *context) } /* Copy in current property values. */ - props->Gain = slot->Gain; - props->AuxSendAuto = slot->AuxSendAuto; - props->Target = slot->Target; + props->Gain = Gain; + props->AuxSendAuto = AuxSendAuto; + props->Target = Target; - props->Type = slot->Effect.Type; - props->Props = slot->Effect.Props; + props->Type = Effect.Type; + props->Props = Effect.Props; /* Swap out any stale effect state object there may be in the container, to * delete it. */ EffectState *oldstate{props->State}; - slot->Effect.State->add_ref(); - props->State = slot->Effect.State; + Effect.State->add_ref(); + props->State = Effect.State; /* Set the new container for updating internal parameters. */ - props = slot->Params.Update.exchange(props, std::memory_order_acq_rel); + props = Params.Update.exchange(props, std::memory_order_acq_rel); if(props) { /* If there was an unused update container, put it back in the @@ -770,7 +769,7 @@ void UpdateAllEffectSlotProps(ALCcontext *context) for(ALeffectslot *slot : *auxslots) { if(!slot->PropsClean.test_and_set(std::memory_order_acq_rel)) - UpdateEffectSlotProps(slot, context); + slot->updateProps(context); } } diff --git a/al/auxeffectslot.h b/al/auxeffectslot.h index c1432c56..5f1e6aa8 100644 --- a/al/auxeffectslot.h +++ b/al/auxeffectslot.h @@ -90,17 +90,16 @@ struct ALeffectslot { ALeffectslot& operator=(const ALeffectslot&) = delete; ~ALeffectslot(); + ALenum init(); + ALenum initEffect(ALeffect *effect, ALCcontext *context); + void updateProps(ALCcontext *context); + static ALeffectslotArray *CreatePtrArray(size_t count) noexcept; /* This can be new'd for the context's default effect slot. */ DEF_NEWDEL(ALeffectslot) }; -ALenum InitEffectSlot(ALeffectslot *slot); -void UpdateEffectSlotProps(ALeffectslot *slot, ALCcontext *context); void UpdateAllEffectSlotProps(ALCcontext *context); - -ALenum InitializeEffect(ALCcontext *Context, ALeffectslot *EffectSlot, ALeffect *effect); - #endif diff --git a/alc/alc.cpp b/alc/alc.cpp index e7cd65b2..258d3de3 100644 --- a/alc/alc.cpp +++ b/alc/alc.cpp @@ -2230,7 +2230,7 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const int *attrList) EffectState *state{slot->Effect.State}; state->mOutTarget = device->Dry.Buffer; state->deviceUpdate(device); - UpdateEffectSlotProps(slot, context); + slot->updateProps(context); } std::unique_lock<std::mutex> proplock{context->mPropLock}; @@ -2251,7 +2251,7 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const int *attrList) EffectState *state{slot->Effect.State}; state->mOutTarget = device->Dry.Buffer; state->deviceUpdate(device); - UpdateEffectSlotProps(slot, context); + slot->updateProps(context); } } slotlock.unlock(); @@ -2563,7 +2563,7 @@ void ALCcontext::init() if(DefaultEffect.type != AL_EFFECT_NULL && mDevice->Type == Playback) { mDefaultSlot = std::unique_ptr<ALeffectslot>{new ALeffectslot{}}; - if(InitEffectSlot(mDefaultSlot.get()) == AL_NO_ERROR) + if(mDefaultSlot->init() == AL_NO_ERROR) aluInitEffectPanning(mDefaultSlot.get(), mDevice.get()); else { @@ -3462,10 +3462,10 @@ START_API_FUNC ContextList.emplace(iter, context.get()); } - if(context->mDefaultSlot) + if(ALeffectslot *slot{context->mDefaultSlot.get()}) { - if(InitializeEffect(context.get(), context->mDefaultSlot.get(), &DefaultEffect) == AL_NO_ERROR) - UpdateEffectSlotProps(context->mDefaultSlot.get(), context.get()); + if(slot->initEffect(&DefaultEffect, context.get()) == AL_NO_ERROR) + slot->updateProps(context.get()); else ERR("Failed to initialize the default effect\n"); } |