diff options
author | Chris Robinson <[email protected]> | 2019-08-09 20:09:47 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2019-08-10 14:41:55 -0700 |
commit | 98029d64b96c2f5edc5dc1e290fa4d30a1338bb4 (patch) | |
tree | 20af999604ece4f66564a129484a8606931e7c69 | |
parent | 8f93656f5301b0db1bda15b4c79397f322cf18fe (diff) |
Fix and clarify the peaking biquad filter
-rw-r--r-- | alc/effects/equalizer.cpp | 13 | ||||
-rw-r--r-- | alc/filters/biquad.cpp | 1 | ||||
-rw-r--r-- | alc/filters/biquad.h | 9 |
3 files changed, 12 insertions, 11 deletions
diff --git a/alc/effects/equalizer.cpp b/alc/effects/equalizer.cpp index a8e81b37..12183814 100644 --- a/alc/effects/equalizer.cpp +++ b/alc/effects/equalizer.cpp @@ -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)); diff --git a/alc/filters/biquad.cpp b/alc/filters/biquad.cpp index 6a3cef64..871c4af4 100644 --- a/alc/filters/biquad.cpp +++ b/alc/filters/biquad.cpp @@ -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; diff --git a/alc/filters/biquad.h b/alc/filters/biquad.h index 893a69a9..f8d7f0ba 100644 --- a/alc/filters/biquad.h +++ b/alc/filters/biquad.h @@ -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 { |