1 #ifndef __BiquadFilter_h__
2 #define __BiquadFilter_h__
12 static constexpr
float BESSEL_Q = 0.57735026919f;
38 void setPeak(
float fc,
float q,
float gain,
float sr){
60 float K = tanf(omega);
61 float norm = 1 / (1 + K / q + K * K);
70 float K = tanf(omega);
71 float norm = 1 / (1 + K / q + K * K);
80 float K = tanf(omega);
81 float norm = 1 / (1 + K / q + K * K);
90 float K = tanf(omega);
91 float norm = 1 / (1 + K / q + K * K);
100 float K = tanf(omega);
101 float norm = 1 / (1 + K / q + K * K);
110 float K = tanf(omega);
111 float V = exp10f(fabsf(gain)/20);
114 norm = 1 / (1 + 1/q * K + K * K);
122 norm = 1 / (1 + V/q * K + K * K);
132 float K = tanf(omega);
133 float V = exp10f(fabsf(gain)/20);
136 norm = 1 / (1 +
M_SQRT2 * K + K * K);
137 coefficients[0] = (1 + sqrtf(2*V) * K + V * K * K) * norm;
139 coefficients[2] = (1 - sqrtf(2*V) * K + V * K * K) * norm;
143 norm = 1 / (1 + sqrtf(2*V) * K + V * K * K);
148 coefficients[4] = - (1 - sqrtf(2*V) * K + V * K * K) * norm;
153 float K = tanf(omega);
154 float V = exp10f(fabsf(gain)/20);
157 norm = 1 / (1 +
M_SQRT2 * K + K * K);
164 norm = 1 / (V + sqrtf(2*V) * K + K * K);
169 coefficients[4] = - (V - sqrtf(2*V) * K + K * K) * norm;
179 #define BIQUAD_COEFFICIENTS_PER_STAGE 5
180 #define BIQUAD_STATE_VARIABLES_PER_STAGE 2
186 arm_biquad_cascade_df2T_instance_f32 df2;
202 for(
size_t i=1; i<
stages; ++i)
229 return M_PI / pioversr;
276 void process(
float* input,
float* output,
size_t size){
279 arm_biquad_cascade_df2T_f32(&df2, input, output, size);
281 for(
size_t k=0; k<
stages; k++){
283 float b0 = *coeffs++;
284 float b1 = *coeffs++;
285 float b2 = *coeffs++;
286 float a1 = *coeffs++;
287 float a2 = *coeffs++;
290 for(
size_t n=0; n<size; n++){
291 float out=b0 * input[n] + d1;
292 d1 = b1 * input[n] + a1 * out + d2;
293 d2 = b2 * input[n] + a2 * out;
313 for(
size_t i = 0; i < in.
getSize(); i++){
320 for(
size_t i = 0; i < in.
getSize(); i++){
327 for(
size_t i = 0; i < in.
getSize(); i++){
334 for(
size_t i = 0; i < in.
getSize(); i++){
423 delete[] filter->
state;
442 float* mystate = states;
443 for(
size_t ch=1; ch<channels; ++ch){
454 delete[] filter->
state;
455 delete[] filter->filters;
461 if(channel < channels)
462 return &filters[channel-1];
468 for(
size_t ch=1; ch<len; ++ch)
483 float* mystate = states;
484 for(
size_t ch=1; ch<channels; ++ch){
#define BIQUAD_COEFFICIENTS_PER_STAGE
Cascaded Biquad Filter.
#define BIQUAD_STATE_VARIABLES_PER_STAGE
virtual int getChannels()=0
virtual FloatArray getSamples(int channel)=0
void setState(FloatArray newState)
Sets state to point to a different set of values.
void setHighShelf(float fc, float gain)
Configure a high shelf filter with variable gain.
void setHighPass(float fc, float q)
void setStages(size_t newStages)
BiquadFilter(float sr, float *coefs, float *ste, size_t sgs)
void setLowShelf(float fc, float gain)
Configure a low shelf filter with variable gain.
void processLowPass(FloatArray in, FloatArray fc, float q, FloatArray out)
void processBandPass(FloatArray in, FloatArray fc, float q, FloatArray out)
void processAllPass(FloatArray in, FloatArray fc, float q, FloatArray out)
void setAllPass(float fc, float q)
void setPeak(float fc, float q, float gain)
Configure a peaking filter with resonance and variable gain.
void setCoefficients(FloatArray newCoefficients)
Sets coefficients to point to a different set of values.
void setLowPass(float fc, float q)
void processHighPass(FloatArray in, FloatArray fc, float q, FloatArray out)
static BiquadFilter * create(float sr, size_t stages=1)
void process(FloatArray in)
void copyCoefficients(FloatArray newCoefficients)
Copies coefficient values from an array.
float process(float input)
static size_t getCoefficientsPerStage()
static void destroy(BiquadFilter *filter)
void setNotch(float fc, float q)
FloatArray getCoefficients()
FilterStage getFilterStage(size_t stage)
void setBandPass(float fc, float q)
void process(FloatArray in, FloatArray out)
void copyState(FloatArray newState)
Copies state values from an array.
void process(float *input, float *output, size_t size)
void setSampleRate(float sr)
void setAllPass(float fc, float q, float sr)
void setHighShelf(float fc, float gain, float sr)
static void setHighPass(float *coefficients, float omega, float q)
static void setNotch(float *coefficients, float omega, float q)
static void setHighShelf(float *coefficients, float omega, float gain)
void setBandPass(float fc, float q, float sr)
void setLowPass(float fc, float q, float sr)
void setNotch(float fc, float q, float sr)
static void setLowPass(float *coefficients, float omega, float q)
static void setAllPass(float *coefficients, float omega, float q)
void setPeak(float fc, float q, float gain, float sr)
static constexpr float SALLEN_KEY_Q
FloatArray getCoefficients()
static constexpr float BESSEL_Q
void setHighPass(float fc, float q, float sr)
static void setPeak(float *coefficients, float omega, float q, float gain)
static void setBandPass(float *coefficients, float omega, float q)
static constexpr float BUTTERWORTH_Q
void copyCoefficients(FloatArray newCoefficients)
FilterStage(FloatArray co, FloatArray st)
static void setLowShelf(float *coefficients, float omega, float gain)
void setLowShelf(float fc, float gain, float sr)
This class contains useful methods for manipulating arrays of floats.
void process(AudioBuffer &input, AudioBuffer &output)
BiquadFilter * getFilter(size_t channel)
static void destroy(MultiBiquadFilter *filter)
MultiBiquadFilter(float sr, float *coefs, float *states, size_t stages, BiquadFilter *filters, size_t len)
static MultiBiquadFilter * create(float sr, size_t channels, size_t stages=1)
virtual ~MultiBiquadFilter()
Base class for signal processors such as Filters.
void copyFrom(SimpleArray< T > source)
Copies the content of another array into this array.
T * getData()
Get the data stored in the Array.
static StereoBiquadFilter * create(float sr, size_t stages=1)
static void destroy(StereoBiquadFilter *filter)
StereoBiquadFilter(float sr, float *coefs, float *states, size_t stages, BiquadFilter *filters)
#define ASSERT(cond, msg)