aboutsummaryrefslogtreecommitdiffstats
path: root/Alc/effects/equalizer.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/equalizer.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/equalizer.c')
-rw-r--r--Alc/effects/equalizer.c29
1 files changed, 17 insertions, 12 deletions
diff --git a/Alc/effects/equalizer.c b/Alc/effects/equalizer.c
index e0fa010e..94ee1853 100644
--- a/Alc/effects/equalizer.c
+++ b/Alc/effects/equalizer.c
@@ -87,8 +87,9 @@ typedef struct ALequalizerState {
ALfloat SampleBuffer[4][MAX_EFFECT_CHANNELS][MAX_UPDATE_SAMPLES];
} ALequalizerState;
-static ALvoid ALequalizerState_Destruct(ALequalizerState *UNUSED(state))
+static ALvoid ALequalizerState_Destruct(ALequalizerState *state)
{
+ ALeffectState_Destruct(STATIC_CAST(ALeffectState,state));
}
static ALboolean ALequalizerState_deviceUpdate(ALequalizerState *UNUSED(state), ALCdevice *UNUSED(device))
@@ -113,15 +114,15 @@ static ALvoid ALequalizerState_update(ALequalizerState *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]);
/* Calculate coefficients for the each type of filter. Note that the shelf
* filters' gain is for the reference frequency, which is the centerpoint
* of the transition band.
*/
- gain = sqrtf(slot->EffectProps.Equalizer.LowGain);
- freq_mult = slot->EffectProps.Equalizer.LowCutoff/frequency;
+ gain = sqrtf(slot->Params.EffectProps.Equalizer.LowGain);
+ freq_mult = slot->Params.EffectProps.Equalizer.LowCutoff/frequency;
ALfilterState_setParams(&state->filter[0][0], ALfilterType_LowShelf,
gain, freq_mult, calc_rcpQ_from_slope(gain, 0.75f)
);
@@ -136,10 +137,12 @@ static ALvoid ALequalizerState_update(ALequalizerState *state, const ALCdevice *
state->filter[0][i].process = state->filter[0][0].process;
}
- gain = slot->EffectProps.Equalizer.Mid1Gain;
- freq_mult = slot->EffectProps.Equalizer.Mid1Center/frequency;
+ gain = slot->Params.EffectProps.Equalizer.Mid1Gain;
+ freq_mult = slot->Params.EffectProps.Equalizer.Mid1Center/frequency;
ALfilterState_setParams(&state->filter[1][0], ALfilterType_Peaking,
- gain, freq_mult, calc_rcpQ_from_bandwidth(freq_mult, slot->EffectProps.Equalizer.Mid1Width)
+ gain, freq_mult, calc_rcpQ_from_bandwidth(
+ freq_mult, slot->Params.EffectProps.Equalizer.Mid1Width
+ )
);
for(i = 1;i < MAX_EFFECT_CHANNELS;i++)
{
@@ -151,10 +154,12 @@ static ALvoid ALequalizerState_update(ALequalizerState *state, const ALCdevice *
state->filter[1][i].process = state->filter[1][0].process;
}
- gain = slot->EffectProps.Equalizer.Mid2Gain;
- freq_mult = slot->EffectProps.Equalizer.Mid2Center/frequency;
+ gain = slot->Params.EffectProps.Equalizer.Mid2Gain;
+ freq_mult = slot->Params.EffectProps.Equalizer.Mid2Center/frequency;
ALfilterState_setParams(&state->filter[2][0], ALfilterType_Peaking,
- gain, freq_mult, calc_rcpQ_from_bandwidth(freq_mult, slot->EffectProps.Equalizer.Mid2Width)
+ gain, freq_mult, calc_rcpQ_from_bandwidth(
+ freq_mult, slot->Params.EffectProps.Equalizer.Mid2Width
+ )
);
for(i = 1;i < MAX_EFFECT_CHANNELS;i++)
{
@@ -166,8 +171,8 @@ static ALvoid ALequalizerState_update(ALequalizerState *state, const ALCdevice *
state->filter[2][i].process = state->filter[2][0].process;
}
- gain = sqrtf(slot->EffectProps.Equalizer.HighGain);
- freq_mult = slot->EffectProps.Equalizer.HighCutoff/frequency;
+ gain = sqrtf(slot->Params.EffectProps.Equalizer.HighGain);
+ freq_mult = slot->Params.EffectProps.Equalizer.HighCutoff/frequency;
ALfilterState_setParams(&state->filter[3][0], ALfilterType_HighShelf,
gain, freq_mult, calc_rcpQ_from_slope(gain, 0.75f)
);