aboutsummaryrefslogtreecommitdiffstats
path: root/al/auxeffectslot.cpp
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2020-09-05 20:48:56 -0700
committerChris Robinson <[email protected]>2020-09-05 20:48:56 -0700
commitc52bf8c401aaf78bbcfa99b33fdaf4838999d547 (patch)
tree453bccbc16da43e7ec5403b57feab52e82e12faa /al/auxeffectslot.cpp
parent9975aeb37f0bcb9a35b1cba7a755abc4774883d0 (diff)
Rework effect slot buffer setting
Rather than creating an effect-specific buffer that gets passed along as a property, the buffer is set the effect state when the effect state is created, the device is updated, or the buffer is changed. The buffer can only be set while the effect slot isn't playing, so it won't be changed or updated while the mixer is processing the effect state.
Diffstat (limited to 'al/auxeffectslot.cpp')
-rw-r--r--al/auxeffectslot.cpp24
1 files changed, 9 insertions, 15 deletions
diff --git a/al/auxeffectslot.cpp b/al/auxeffectslot.cpp
index d9f459ba..a4e945b4 100644
--- a/al/auxeffectslot.cpp
+++ b/al/auxeffectslot.cpp
@@ -484,7 +484,6 @@ START_API_FUNC
SETERR_RETURN(context, AL_INVALID_NAME,, "Invalid effect slot ID %u", effectslot);
ALeffectslot *target{};
- ALbuffer *buffer{};
ALCdevice *device{};
ALenum err{};
switch(param)
@@ -552,8 +551,13 @@ START_API_FUNC
case AL_BUFFER:
device = context->mDevice.get();
+ if(slot->mState == SlotState::Playing)
+ SETERR_RETURN(context, AL_INVALID_OPERATION,,
+ "Setting buffer on playing effect slot %u", slot->id);
+
{
std::lock_guard<std::mutex> ___{device->BufferLock};
+ ALbuffer *buffer{};
if(value)
{
buffer = LookupBuffer(device, static_cast<ALuint>(value));
@@ -569,13 +573,9 @@ START_API_FUNC
DecrementRef(oldbuffer->ref);
slot->Buffer = buffer;
- slot->Effect.Buffer = nullptr;
- if(buffer)
- {
- FPUCtl mixer_mode{};
- auto *state = slot->Effect.State.get();
- slot->Effect.Buffer.reset(state->createBuffer(device, buffer->mBuffer));
- }
+ FPUCtl mixer_mode{};
+ auto *state = slot->Effect.State.get();
+ state->setBuffer(device, buffer ? &buffer->mBuffer : nullptr);
}
break;
@@ -819,8 +819,6 @@ ALeffectslot::~ALeffectslot()
if(Params.mEffectState)
Params.mEffectState->release();
- if(Params.mEffectBuffer)
- Params.mEffectBuffer->release();
}
ALenum ALeffectslot::init()
@@ -856,9 +854,8 @@ ALenum ALeffectslot::initEffect(ALeffect *effect, ALCcontext *context)
{
FPUCtl mixer_mode{};
State->deviceUpdate(Device);
- Effect.Buffer = nullptr;
if(Buffer)
- Effect.Buffer.reset(State->createBuffer(Device, Buffer->mBuffer));
+ State->setBuffer(Device, &Buffer->mBuffer);
}
if(!effect)
@@ -882,7 +879,6 @@ ALenum ALeffectslot::initEffect(ALeffect *effect, ALCcontext *context)
while(props)
{
props->State = nullptr;
- props->Buffer = nullptr;
props = props->next.load(std::memory_order_relaxed);
}
@@ -912,7 +908,6 @@ void ALeffectslot::updateProps(ALCcontext *context)
props->Type = Effect.Type;
props->Props = Effect.Props;
props->State = Effect.State;
- props->Buffer = Effect.Buffer;
/* Set the new container for updating internal parameters. */
props = Params.Update.exchange(props, std::memory_order_acq_rel);
@@ -922,7 +917,6 @@ void ALeffectslot::updateProps(ALCcontext *context)
* freelist.
*/
props->State = nullptr;
- props->Buffer = nullptr;
AtomicReplaceHead(context->mFreeEffectslotProps, props);
}
}