From 54e7f48df9366db30e4e7f5f3cca1d7a3ca9a1b4 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sat, 21 Dec 2019 02:02:57 -0800 Subject: Use unique setters for biquad filter parameters One for whether a slope parameter is used, and one for bandwidth. --- alc/filters/biquad.cpp | 2 +- alc/filters/biquad.h | 38 +++++++++++++++++++++++++++++--------- 2 files changed, 30 insertions(+), 10 deletions(-) (limited to 'alc/filters') diff --git a/alc/filters/biquad.cpp b/alc/filters/biquad.cpp index 8a8810e2..13cbca3f 100644 --- a/alc/filters/biquad.cpp +++ b/alc/filters/biquad.cpp @@ -11,7 +11,7 @@ template -void BiquadFilterR::setParams(BiquadType type, Real gain, Real f0norm, Real rcpQ) +void BiquadFilterR::setParams(BiquadType type, Real f0norm, Real gain, Real rcpQ) { // Limit gain to -100dB assert(gain > 0.00001f); diff --git a/alc/filters/biquad.h b/alc/filters/biquad.h index 9af954ae..d7a195a9 100644 --- a/alc/filters/biquad.h +++ b/alc/filters/biquad.h @@ -1,6 +1,7 @@ #ifndef FILTERS_BIQUAD_H #define FILTERS_BIQUAD_H +#include #include #include #include @@ -44,6 +45,8 @@ class BiquadFilterR { /* Transfer function coefficients "a" (denominator; a0 is pre-applied). */ Real mA1{0.0f}, mA2{0.0f}; + void setParams(BiquadType type, Real f0norm, Real gain, Real rcpQ); + public: void clear() noexcept { mZ1 = mZ2 = 0.0f; } @@ -51,17 +54,34 @@ public: * Sets the filter state for the specified filter type and its parameters. * * \param type The type of filter to apply. + * \param f0norm The normalized reference frequency (ref / sample_rate). + * This is the center point for the Shelf, Peaking, and BandPass filter + * types, or the cutoff frequency for the LowPass and HighPass filter + * types. + * \param gain The gain for the reference frequency response. Only used by + * the Shelf and Peaking filter types. + * \param slope Slope steepness of the transition band. + */ + void setParamsFromSlope(BiquadType type, Real f0norm, Real gain, Real slope) + { + gain = std::max(gain, 0.001f); /* Limit -60dB */ + setParams(type, gain, f0norm, rcpQFromSlope(gain, slope)); + } + + /** + * Sets the filter state for the specified filter type and its parameters. + * + * \param type The type of filter to apply. + * \param f0norm The normalized reference frequency (ref / sample_rate). + * This is the center point for the Shelf, Peaking, and BandPass filter + * types, or the cutoff frequency for the LowPass and HighPass filter + * types. * \param gain The gain for the reference frequency response. Only used by - * the Shelf and Peaking filter types. - * \param f0norm The reference frequency normal (ref_freq / sample_rate). - * This is the center point for the Shelf, Peaking, and - * BandPass filter types, or the cutoff frequency for the - * LowPass and HighPass filter types. - * \param rcpQ The reciprocal of the Q coefficient for the filter's - * transition band. Can be generated from rcpQFromSlope or - * rcpQFromBandwidth as needed. + * the Shelf and Peaking filter types. + * \param bandwidth Normalized bandwidth of the transition band. */ - void setParams(BiquadType type, Real gain, Real f0norm, Real rcpQ); + void setParamsFromBandwidth(BiquadType type, Real f0norm, Real gain, Real bandwidth) + { setParams(type, gain, f0norm, rcpQFromBandwidth(f0norm, bandwidth)); } void copyParamsFrom(const BiquadFilterR &other) { -- cgit v1.2.3