MostlyHarmless 0.0.1
 
Loading...
Searching...
No Matches
marvin::dsp::filters::SmoothedBiquadCoefficients< SampleType, InterpolationType, NumStages > Class Template Referencefinal

Helper class to simplify smoothly changing BiquadCoefficients with no zippering. More...

#include <marvin_SmoothedBiquadCoefficients.h>

Public Member Functions

void reset (int periodSamples) noexcept
 
void reset (double sampleRate, double timeMs) noexcept
 
void setCurrentAndTargetCoeffs (size_t stage, BiquadCoefficients< SampleType > target) noexcept
 
void setTargetCoeffs (size_t stage, BiquadCoefficients< SampleType > target) noexcept
 
BiquadCoefficients< SampleType > current (size_t stage) const noexcept
 
BiquadCoefficients< SampleType > target (size_t stage) const noexcept
 
void interpolate () noexcept
 

Detailed Description

template<FloatType SampleType, utils::SmoothingType InterpolationType, size_t NumStages>
requires (NumStages > 0)
class marvin::dsp::filters::SmoothedBiquadCoefficients< SampleType, InterpolationType, NumStages >

Helper class to simplify smoothly changing BiquadCoefficients with no zippering.

See marvin::utils::SmoothingType for options for smoothing. Internally just runs a marvin::utils::SmoothedValue per biquad coefficient.
Usage example:

using namespace marvin::dsp::filters;
using namespace marvin::utils;
class FilterSmoothingDemo final {
public:
void initialise(double sampleRate) {
constexpr static auto periodMs{ 5.0f }; // 5ms duration
m_sampleRate = sampleRate;
m_updateRate = static_cast<int>((periodMs / 1000.0f) * static_cast<float>(sampleRate));
const auto lpfCoeffs = rbj::lowpass<float>(sampleRate, 2000.0f, 0.5f);
const auto hpfCoeffs = rbj::highpass<float>(sampleRate, 200.0f, 0.5f);
m_smoothedCoeffs.reset(sampleRate, periodMs);
m_smoothedCoeffs.setCurrentAndTargetCoeffs(lpfCoeffs, 0); // stage 0
m_smoothedCoeffs.setCurrentAndTargetCoeffs(hpfCoeffs, 1); // stage 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) {
const auto newLpfCoeffs = rbj::lowpass<float>(m_sampleRate, newLpfCutoff, 0.5f);
const auto newHpfCoeffs = rbj::highpass<float>(m_sampleRate, newHpfCutoff, 0.5f);
m_smoothedCoeffs.setTargetCoeffs(newLpfCoeffs, 0);
m_smoothedCoeffs.setTargetCoeffs(newHpfCoeffs, 1);
m_samplesUntilUpdate = m_updateRate;
}
m_smoothedCoeffs(); // Interpolate the coeffs
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

Member Function Documentation

◆ current()

template<FloatType SampleType, utils::SmoothingType InterpolationType, size_t NumStages>
BiquadCoefficients< SampleType > marvin::dsp::filters::SmoothedBiquadCoefficients< SampleType, InterpolationType, NumStages >::current ( size_t stage) const
inlinenodiscardnoexcept

Retrieves the smoothed coeffs for a given stage.

Parameters
stageThe index of the stage to retrieve.
Returns
The smoothed coefficients for the target stage.

◆ interpolate()

template<FloatType SampleType, utils::SmoothingType InterpolationType, size_t NumStages>
void marvin::dsp::filters::SmoothedBiquadCoefficients< SampleType, InterpolationType, NumStages >::interpolate ( )
inlinenoexcept

Performs a single tick of smoothing towards the target in all stages.

◆ reset() [1/2]

template<FloatType SampleType, utils::SmoothingType InterpolationType, size_t NumStages>
void marvin::dsp::filters::SmoothedBiquadCoefficients< SampleType, InterpolationType, NumStages >::reset ( double sampleRate,
double timeMs )
inlinenoexcept

Sets the duration of the smoothing, and sets the target value to the current value.

Parameters
sampleRateThe currently used sample rate.
timeMsThe duration of the smoothing, in milliseconds.

◆ reset() [2/2]

template<FloatType SampleType, utils::SmoothingType InterpolationType, size_t NumStages>
void marvin::dsp::filters::SmoothedBiquadCoefficients< SampleType, InterpolationType, NumStages >::reset ( int periodSamples)
inlinenoexcept

Sets the duration of the smoothing, and sets the target value to the current value.

Parameters
periodSamplesThe duration of the smoothing, in samples.

◆ setCurrentAndTargetCoeffs()

template<FloatType SampleType, utils::SmoothingType InterpolationType, size_t NumStages>
void marvin::dsp::filters::SmoothedBiquadCoefficients< SampleType, InterpolationType, NumStages >::setCurrentAndTargetCoeffs ( size_t stage,
BiquadCoefficients< SampleType > target )
inlinenoexcept

Sets both the current value of the coeffs, and the target value of the coeffs for a given stage.

Parameters
stageThe stage index to target.
targetThe coeffs to set.

◆ setTargetCoeffs()

template<FloatType SampleType, utils::SmoothingType InterpolationType, size_t NumStages>
void marvin::dsp::filters::SmoothedBiquadCoefficients< SampleType, InterpolationType, NumStages >::setTargetCoeffs ( size_t stage,
BiquadCoefficients< SampleType > target )
inlinenoexcept

Sets the target value for the coeffs to smooth to for a give stage.

Parameters
stageThe stage index to target.
targetThe coeffs to set.

◆ target()

template<FloatType SampleType, utils::SmoothingType InterpolationType, size_t NumStages>
BiquadCoefficients< SampleType > marvin::dsp::filters::SmoothedBiquadCoefficients< SampleType, InterpolationType, NumStages >::target ( size_t stage) const
inlinenodiscardnoexcept

Retrieves the target coeffs for a given stage.

Parameters
stageThe index of the stage to retrieve.
Returns
The target coefficients for the given stage.

The documentation for this class was generated from the following file: