Fix and clarify the peaking biquad filter

This commit is contained in:
Chris Robinson
2019-08-09 20:09:47 -07:00
parent 8f93656f53
commit 98029d64b9
3 changed files with 12 additions and 11 deletions
+7 -6
View File
@@ -116,25 +116,26 @@ void EqualizerState::update(const ALCcontext *context, const ALeffectslot *slot,
ALfloat gain, f0norm;
/* 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.
* and peaking filters' gain is for the centerpoint of the transition band,
* meaning its dB needs to be doubled for the shelf or peak to reach the
* provided gain.
*/
gain = maxf(sqrtf(props->Equalizer.LowGain), 0.0625f); /* Limit -24dB */
gain = maxf(std::sqrt(props->Equalizer.LowGain), 0.0625f); /* Limit -24dB */
f0norm = props->Equalizer.LowCutoff/frequency;
mChans[0].filter[0].setParams(BiquadType::LowShelf, gain, f0norm,
BiquadFilter::rcpQFromSlope(gain, 0.75f));
gain = maxf(props->Equalizer.Mid1Gain, 0.0625f);
gain = maxf(std::sqrt(props->Equalizer.Mid1Gain), 0.0625f);
f0norm = props->Equalizer.Mid1Center/frequency;
mChans[0].filter[1].setParams(BiquadType::Peaking, gain, f0norm,
BiquadFilter::rcpQFromBandwidth(f0norm, props->Equalizer.Mid1Width));
gain = maxf(props->Equalizer.Mid2Gain, 0.0625f);
gain = maxf(std::sqrt(props->Equalizer.Mid2Gain), 0.0625f);
f0norm = props->Equalizer.Mid2Center/frequency;
mChans[0].filter[2].setParams(BiquadType::Peaking, gain, f0norm,
BiquadFilter::rcpQFromBandwidth(f0norm, props->Equalizer.Mid2Width));
gain = maxf(sqrtf(props->Equalizer.HighGain), 0.0625f);
gain = maxf(std::sqrt(props->Equalizer.HighGain), 0.0625f);
f0norm = props->Equalizer.HighCutoff/frequency;
mChans[0].filter[3].setParams(BiquadType::HighShelf, gain, f0norm,
BiquadFilter::rcpQFromSlope(gain, 0.75f));
-1
View File
@@ -47,7 +47,6 @@ void BiquadFilterR<Real>::setParams(BiquadType type, Real gain, Real f0norm, Rea
a[2] = (gain+1.0f) + (gain-1.0f)*cos_w0 - sqrtgain_alpha_2;
break;
case BiquadType::Peaking:
gain = std::sqrt(gain);
b[0] = 1.0f + alpha * gain;
b[1] = -2.0f * cos_w0;
b[2] = 1.0f - alpha * gain;
+5 -4
View File
@@ -11,10 +11,11 @@
* EQ biquad filter coefficients" by Robert Bristow-Johnson
* http://www.musicdsp.org/files/Audio-EQ-Cookbook.txt
*/
/* Implementation note: For the shelf filters, the specified gain is for the
* reference frequency, which is the centerpoint of the transition band. This
* better matches EFX filter design. To set the gain for the shelf itself, use
* the square root of the desired linear gain (or halve the dB gain).
/* Implementation note: For the shelf and peaking filters, the specified gain
* is for the centerpoint of the transition band. This better fits EFX filter
* behavior, which expects the shelf's reference frequency to reach the given
* gain. To set the gain for the shelf or peak itself, use the square root of
* the desired linear gain (or halve the dB gain).
*/
enum class BiquadType {