diff options
author | Chris Robinson <[email protected]> | 2016-05-12 18:26:33 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2016-05-12 18:41:33 -0700 |
commit | ef0d4f8210fe6aa65b9df96f3b64bf6f355e845a (patch) | |
tree | 401b74c7c7291229397883c73d4ad2c382275b7e /Alc/effects/modulator.c | |
parent | 186b54aa3d5f1398a384fa318aa000210d82437e (diff) |
Provide (mostly) lockless updates for effect slots
Similar to the listener, separate containers are provided atomically for the
mixer thread to apply updates without needing to block, and a free-list is used
to reuse container objects.
A couple things to note. First, the lock is still used when the effect state's
deviceUpdate method is called to prevent asynchronous calls to reset the device
from interfering. This can be fixed by using the list lock in ALc.c instead.
Secondly, old effect states aren't immediately deleted when the effect type
changes (the actual type, not just its properties). This is because the mixer
thread is intended to be real-time safe, and so can't be freeing anything. They
are cleared away when updates reuse the container they were kept in, and they
don't incur any extra processing cost, but there may be cases where the memory
is kept around until the effect slot is deleted.
Diffstat (limited to 'Alc/effects/modulator.c')
-rw-r--r-- | Alc/effects/modulator.c | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/Alc/effects/modulator.c b/Alc/effects/modulator.c index fb75043a..5a96bb9d 100644 --- a/Alc/effects/modulator.c +++ b/Alc/effects/modulator.c @@ -82,8 +82,9 @@ DECL_TEMPLATE(Square) #undef DECL_TEMPLATE -static ALvoid ALmodulatorState_Destruct(ALmodulatorState *UNUSED(state)) +static ALvoid ALmodulatorState_Destruct(ALmodulatorState *state) { + ALeffectState_Destruct(STATIC_CAST(ALeffectState,state)); } static ALboolean ALmodulatorState_deviceUpdate(ALmodulatorState *UNUSED(state), ALCdevice *UNUSED(device)) @@ -97,19 +98,19 @@ static ALvoid ALmodulatorState_update(ALmodulatorState *state, const ALCdevice * ALfloat cw, a; ALuint i; - if(Slot->EffectProps.Modulator.Waveform == AL_RING_MODULATOR_SINUSOID) + if(Slot->Params.EffectProps.Modulator.Waveform == AL_RING_MODULATOR_SINUSOID) state->Process = ModulateSin; - else if(Slot->EffectProps.Modulator.Waveform == AL_RING_MODULATOR_SAWTOOTH) + else if(Slot->Params.EffectProps.Modulator.Waveform == AL_RING_MODULATOR_SAWTOOTH) state->Process = ModulateSaw; - else /*if(Slot->EffectProps.Modulator.Waveform == AL_RING_MODULATOR_SQUARE)*/ + else /*if(Slot->Params.EffectProps.Modulator.Waveform == AL_RING_MODULATOR_SQUARE)*/ state->Process = ModulateSquare; - state->step = fastf2u(Slot->EffectProps.Modulator.Frequency*WAVEFORM_FRACONE / + state->step = fastf2u(Slot->Params.EffectProps.Modulator.Frequency*WAVEFORM_FRACONE / Device->Frequency); if(state->step == 0) state->step = 1; /* Custom filter coeffs, which match the old version instead of a low-shelf. */ - cw = cosf(F_TAU * Slot->EffectProps.Modulator.HighPassCutoff / Device->Frequency); + cw = cosf(F_TAU * Slot->Params.EffectProps.Modulator.HighPassCutoff / Device->Frequency); a = (2.0f-cw) - sqrtf(powf(2.0f-cw, 2.0f) - 1.0f); for(i = 0;i < MAX_EFFECT_CHANNELS;i++) @@ -132,7 +133,7 @@ static ALvoid ALmodulatorState_update(ALmodulatorState *state, const ALCdevice * STATIC_CAST(ALeffectState,state)->OutBuffer = Device->FOAOut.Buffer; STATIC_CAST(ALeffectState,state)->OutChannels = Device->FOAOut.NumChannels; for(i = 0;i < MAX_EFFECT_CHANNELS;i++) - ComputeFirstOrderGains(Device->FOAOut, matrix.m[i], Slot->Gain, + ComputeFirstOrderGains(Device->FOAOut, matrix.m[i], Slot->Params.Gain, state->Gain[i]); } |