aboutsummaryrefslogtreecommitdiffstats
path: root/Alc/effects/distortion.c
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2016-05-12 18:26:33 -0700
committerChris Robinson <[email protected]>2016-05-12 18:41:33 -0700
commitef0d4f8210fe6aa65b9df96f3b64bf6f355e845a (patch)
tree401b74c7c7291229397883c73d4ad2c382275b7e /Alc/effects/distortion.c
parent186b54aa3d5f1398a384fa318aa000210d82437e (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/distortion.c')
-rw-r--r--Alc/effects/distortion.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/Alc/effects/distortion.c b/Alc/effects/distortion.c
index 7a4c2f62..534a817c 100644
--- a/Alc/effects/distortion.c
+++ b/Alc/effects/distortion.c
@@ -43,8 +43,9 @@ typedef struct ALdistortionState {
ALfloat edge_coeff;
} ALdistortionState;
-static ALvoid ALdistortionState_Destruct(ALdistortionState *UNUSED(state))
+static ALvoid ALdistortionState_Destruct(ALdistortionState *state)
{
+ ALeffectState_Destruct(STATIC_CAST(ALeffectState,state));
}
static ALboolean ALdistortionState_deviceUpdate(ALdistortionState *UNUSED(state), ALCdevice *UNUSED(device))
@@ -60,15 +61,15 @@ static ALvoid ALdistortionState_update(ALdistortionState *state, const ALCdevice
ALfloat edge;
/* Store distorted signal attenuation settings */
- state->attenuation = Slot->EffectProps.Distortion.Gain;
+ state->attenuation = Slot->Params.EffectProps.Distortion.Gain;
/* Store waveshaper edge settings */
- edge = sinf(Slot->EffectProps.Distortion.Edge * (F_PI_2));
+ edge = sinf(Slot->Params.EffectProps.Distortion.Edge * (F_PI_2));
edge = minf(edge, 0.99f);
state->edge_coeff = 2.0f * edge / (1.0f-edge);
/* Lowpass filter */
- cutoff = Slot->EffectProps.Distortion.LowpassCutoff;
+ cutoff = Slot->Params.EffectProps.Distortion.LowpassCutoff;
/* Bandwidth value is constant in octaves */
bandwidth = (cutoff / 2.0f) / (cutoff * 0.67f);
ALfilterState_setParams(&state->lowpass, ALfilterType_LowPass, 1.0f,
@@ -76,14 +77,14 @@ static ALvoid ALdistortionState_update(ALdistortionState *state, const ALCdevice
);
/* Bandpass filter */
- cutoff = Slot->EffectProps.Distortion.EQCenter;
+ cutoff = Slot->Params.EffectProps.Distortion.EQCenter;
/* Convert bandwidth in Hz to octaves */
- bandwidth = Slot->EffectProps.Distortion.EQBandwidth / (cutoff * 0.67f);
+ bandwidth = Slot->Params.EffectProps.Distortion.EQBandwidth / (cutoff * 0.67f);
ALfilterState_setParams(&state->bandpass, ALfilterType_BandPass, 1.0f,
cutoff / (frequency*4.0f), calc_rcpQ_from_bandwidth(cutoff / (frequency*4.0f), bandwidth)
);
- ComputeAmbientGains(Device->Dry, Slot->Gain, state->Gain);
+ ComputeAmbientGains(Device->Dry, Slot->Params.Gain, state->Gain);
}
static ALvoid ALdistortionState_process(ALdistortionState *state, ALuint SamplesToDo, const ALfloat (*restrict SamplesIn)[BUFFERSIZE], ALfloat (*restrict SamplesOut)[BUFFERSIZE], ALuint NumChannels)