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;
37 #define FILTER_MAX_ORDER 4
41 friend class StereoFilter;
42 friend class SplittingStereoFilter;
46 void init(FilterType type, int new_order);
48 void update(); //update coefficients
52 std::complex<double> evaluate_transfer_function(float omega);
54 FilterType get_type() { return filtertype; }
55 unsigned get_order() { return filter_order; }
57 // cutoff is taken to be in the [0..pi> (see set_linear_cutoff, below).
58 void render(float *inout_array, unsigned int buf_size, float cutoff, float resonance);
60 // Set cutoff, from [0..pi> (where pi is the Nyquist frequency).
61 // Overridden by render() if you use that.
62 void set_linear_cutoff(float new_omega)
67 void set_resonance(float new_resonance)
69 resonance = new_resonance;
73 // We don't need the stride argument for SSE, as StereoFilter
74 // has its own SSE implementations.
75 void render_chunk(float *inout_buf, unsigned nSamples);
77 void render_chunk(float *inout_buf, unsigned nSamples, unsigned stride = 1);
80 FilterType filtertype;
82 float omega; //which is 2*Pi*frequency /SAMPLE_RATE
86 unsigned filter_order;
88 float b0, b1, b2, a1, a2; //filter coefs
90 struct FeedbackBuffer {
91 float d0,d1; //feedback buffers
92 } feedback[FILTER_MAX_ORDER];
94 void calcSinCos(float omega, float *sinVal, float *cosVal)
96 *sinVal = (float)sin(omega);
97 *cosVal = (float)cos(omega);
105 void init(FilterType type, int new_order);
107 void render(float *inout_left_ptr, unsigned n_samples, float cutoff, float resonance);
110 void debug() { parm_filter.debug(); }
112 void debug() { filters[0].debug(); }
116 FilterType get_type() { return parm_filter.get_type(); }
118 FilterType get_type() { return filters[0].get_type(); }
123 // We only use the filter to calculate coefficients; we don't actually
124 // use its feedbacks.
126 struct SIMDFeedbackBuffer {
128 } feedback[FILTER_MAX_ORDER];
134 #endif // !defined(_FILTER_H)