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
17 #include <xmmintrin.h>
35 #define FILTER_MAX_ORDER 4
39 friend class StereoFilter;
40 friend class SplittingStereoFilter;
44 void init(FilterType type, int new_order);
46 void update(); //update coefficients
50 std::complex<double> evaluate_transfer_function(float omega);
52 FilterType get_type() { return filtertype; }
53 unsigned get_order() { return filter_order; }
55 // cutoff is taken to be in the [0..pi> (see set_linear_cutoff, below).
56 void render(float *inout_array, unsigned int buf_size, float cutoff, float resonance);
58 // Set cutoff, from [0..pi> (where pi is the Nyquist frequency).
59 // Overridden by render() if you use that.
60 void set_linear_cutoff(float new_omega)
65 void set_resonance(float new_resonance)
67 resonance = new_resonance;
70 // For EQ filters only.
71 void set_dbgain_normalized(float db_gain_div_40)
73 A = pow(10.0f, db_gain_div_40);
77 // We don't need the stride argument for SSE, as StereoFilter
78 // has its own SSE implementations.
79 void render_chunk(float *inout_buf, unsigned nSamples);
81 void render_chunk(float *inout_buf, unsigned nSamples, unsigned stride = 1);
84 FilterType filtertype;
86 float omega; //which is 2*Pi*frequency /SAMPLE_RATE
88 float A; // which is 10^(db_gain / 40)
91 unsigned filter_order;
93 float b0, b1, b2, a1, a2; //filter coefs
95 struct FeedbackBuffer {
96 float d0,d1; //feedback buffers
97 } feedback[FILTER_MAX_ORDER];
99 void calcSinCos(float omega, float *sinVal, float *cosVal)
101 *sinVal = (float)sin(omega);
102 *cosVal = (float)cos(omega);
110 void init(FilterType type, int new_order);
112 void render(float *inout_left_ptr, unsigned n_samples, float cutoff, float resonance, float dbgain_normalized = 0.0f);
115 void debug() { parm_filter.debug(); }
117 void debug() { filters[0].debug(); }
121 FilterType get_type() { return parm_filter.get_type(); }
123 FilterType get_type() { return filters[0].get_type(); }
128 // We only use the filter to calculate coefficients; we don't actually
129 // use its feedbacks.
131 struct SIMDFeedbackBuffer {
133 } feedback[FILTER_MAX_ORDER];
139 #endif // !defined(_FILTER_H)