class FilterSmoothingDemo final {
public:
void initialise(double sampleRate) {
constexpr static auto periodMs{ 5.0f };
m_sampleRate = sampleRate;
m_updateRate = static_cast<int>((periodMs / 1000.0f) * static_cast<float>(sampleRate));
m_smoothedCoeffs.reset(sampleRate, periodMs);
m_smoothedCoeffs.setCurrentAndTargetCoeffs(lpfCoeffs, 0);
m_smoothedCoeffs.setCurrentAndTargetCoeffs(hpfCoeffs, 1);
m_filter.setCoeffs(0, m_smoothedCoeffs.current(0));
m_filter.setCoeffs(1, m_smoothedCoeffs.current(1));
}
[[nodiscard]] float operator()(float x, float newLpfCutoff, float newHpfCutoff) noexcept {
if(m_samplesUntilUpdate == 0) {
m_smoothedCoeffs.setTargetCoeffs(newLpfCoeffs, 0);
m_smoothedCoeffs.setTargetCoeffs(newHpfCoeffs, 1);
m_samplesUntilUpdate = m_updateRate;
}
m_smoothedCoeffs();
m_filter.setCoeffs(0, m_smoothedCoeffs.current(0));
m_filter.setCoeffs(1, m_smoothedCoeffs.current(1));
const auto filtered = m_filter(x);
--m_samplesUntilUpdate;
return filtered;
}
void reset() noexcept {
m_filter.reset();
}
private:
double m_sampleRate;
int m_updateRate;
int m_samplesUntilUpdate{ 0 };
Biquad<float, 2> m_filter;
SmoothedBiquadCoefficients<float, SmoothingType::Exponential, 2> m_smoothedCoeffs{};
};
BiquadCoefficients< SampleType > highpass(double sampleRate, SampleType cutoff, SampleType q) noexcept
Definition marvin_RBJCoefficients.h:56
BiquadCoefficients< SampleType > lowpass(double sampleRate, SampleType cutoff, SampleType q) noexcept
Definition marvin_RBJCoefficients.h:25
Digital filter functions and classes.
Definition marvin_SVF.h:15
Utility helper functions and classes.
Definition marvin_Utils.h:21