diff options
author | Chris Robinson <[email protected]> | 2019-12-21 02:02:57 -0800 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2019-12-21 02:02:57 -0800 |
commit | 54e7f48df9366db30e4e7f5f3cca1d7a3ca9a1b4 (patch) | |
tree | 6b60392a0e355bcbaa0531c11677623ceb0b8f54 /alc/filters/biquad.h | |
parent | 274fd36eddb8d37dcbe44cea1117a7027a653a67 (diff) |
Use unique setters for biquad filter parameters
One for whether a slope parameter is used, and one for bandwidth.
Diffstat (limited to 'alc/filters/biquad.h')
-rw-r--r-- | alc/filters/biquad.h | 38 |
1 files changed, 29 insertions, 9 deletions
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 <algorithm> #include <cmath> #include <cstddef> #include <utility> @@ -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<Real>(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) { |