2 // a cascaded biquad IIR filter
4 // Special cases for type=LPF/BPF/HPF:
6 // Butterworth filter: order=1, resonance=1/sqrt(2)
7 // Linkwitz-Riley filter: order=2, resonance=1/2
12 #define _USE_MATH_DEFINES
18 #include <xmmintrin.h>
24 template <typename _Tp> struct complex;
42 #define FILTER_MAX_ORDER 4
46 friend class StereoFilter;
47 friend class SplittingStereoFilter;
51 void init(FilterType type, int new_order);
53 void update(); //update coefficients
57 std::complex<double> evaluate_transfer_function(float omega);
59 FilterType get_type() { return filtertype; }
60 unsigned get_order() { return filter_order; }
62 // cutoff is taken to be in the [0..pi> (see set_linear_cutoff, below).
63 void render(float *inout_array, unsigned int buf_size, float cutoff, float resonance);
65 // Set cutoff, from [0..pi> (where pi is the Nyquist frequency).
66 // Overridden by render() if you use that.
67 void set_linear_cutoff(float new_omega)
72 void set_resonance(float new_resonance)
74 resonance = new_resonance;
77 // For EQ filters only.
78 void set_dbgain_normalized(float db_gain_div_40)
80 A = pow(10.0f, db_gain_div_40);
84 // We don't need the stride argument for SSE, as StereoFilter
85 // has its own SSE implementations.
86 void render_chunk(float *inout_buf, unsigned nSamples);
88 void render_chunk(float *inout_buf, unsigned nSamples, unsigned stride = 1);
91 FilterType filtertype;
93 float omega; //which is 2*Pi*frequency /SAMPLE_RATE
95 float A; // which is 10^(db_gain / 40)
98 unsigned filter_order;
100 float b0, b1, b2, a1, a2; //filter coefs
102 struct FeedbackBuffer {
103 float d0,d1; //feedback buffers
104 } feedback[FILTER_MAX_ORDER];
106 void calcSinCos(float omega, float *sinVal, float *cosVal)
108 *sinVal = (float)sin(omega);
109 *cosVal = (float)cos(omega);
117 void init(FilterType type, int new_order);
119 void render(float *inout_left_ptr, unsigned n_samples, float cutoff, float resonance, float dbgain_normalized = 0.0f);
122 void debug() { parm_filter.debug(); }
124 void debug() { filters[0].debug(); }
128 FilterType get_type() { return parm_filter.get_type(); }
130 FilterType get_type() { return filters[0].get_type(); }
135 // We only use the filter to calculate coefficients; we don't actually
136 // use its feedbacks.
138 struct SIMDFeedbackBuffer {
140 } feedback[FILTER_MAX_ORDER];
146 #endif // !defined(_FILTER_H)