1 /***************************************************/ 2 /*! \class BiQuad 3 \brief STK biquad (two-pole, two-zero) filter class. 4 5 This protected Filter subclass implements a 6 two-pole, two-zero digital filter. A method 7 is provided for creating a resonance in the 8 frequency response while maintaining a constant 9 filter gain. 10 11 by Perry R. Cook and Gary P. Scavone, 1995 - 2005. 12 */ 13 /***************************************************/ 14 15 #ifndef STK_BIQUAD_H 16 #define STK_BIQUAD_H 17 18 #include "Filter.h" 19 20 namespace Nyq 21 { 22 23 class BiQuad : protected Filter 24 { 25 public: 26 27 //! Default constructor creates a second-order pass-through filter. 28 BiQuad(); 29 30 //! Class destructor. 31 virtual ~BiQuad(); 32 33 //! Clears all internal states of the filter. 34 void clear(void); 35 36 //! Set the b[0] coefficient value. 37 void setB0(StkFloat b0); 38 39 //! Set the b[1] coefficient value. 40 void setB1(StkFloat b1); 41 42 //! Set the b[2] coefficient value. 43 void setB2(StkFloat b2); 44 45 //! Set the a[1] coefficient value. 46 void setA1(StkFloat a1); 47 48 //! Set the a[2] coefficient value. 49 void setA2(StkFloat a2); 50 51 //! Sets the filter coefficients for a resonance at \e frequency (in Hz). 52 /*! 53 This method determines the filter coefficients corresponding to 54 two complex-conjugate poles with the given \e frequency (in Hz) 55 and \e radius from the z-plane origin. If \e normalize is true, 56 the filter zeros are placed at z = 1, z = -1, and the coefficients 57 are then normalized to produce a constant unity peak gain 58 (independent of the filter \e gain parameter). The resulting 59 filter frequency response has a resonance at the given \e 60 frequency. The closer the poles are to the unit-circle (\e radius 61 close to one), the narrower the resulting resonance width. 62 */ 63 void setResonance(StkFloat frequency, StkFloat radius, bool normalize = false); 64 65 //! Set the filter coefficients for a notch at \e frequency (in Hz). 66 /*! 67 This method determines the filter coefficients corresponding to 68 two complex-conjugate zeros with the given \e frequency (in Hz) 69 and \e radius from the z-plane origin. No filter normalization 70 is attempted. 71 */ 72 void setNotch(StkFloat frequency, StkFloat radius); 73 74 //! Sets the filter zeroes for equal resonance gain. 75 /*! 76 When using the filter as a resonator, zeroes places at z = 1, z 77 = -1 will result in a constant gain at resonance of 1 / (1 - R), 78 where R is the pole radius setting. 79 80 */ 81 void setEqualGainZeroes(); 82 83 //! Set the filter gain. 84 /*! 85 The gain is applied at the filter input and does not affect the 86 coefficient values. The default gain value is 1.0. 87 */ 88 void setGain(StkFloat gain); 89 90 //! Return the current filter gain. 91 StkFloat getGain(void) const; 92 93 //! Return the last computed output value. 94 StkFloat lastOut(void) const; 95 96 //! Input one sample to the filter and return one output. 97 virtual StkFloat tick(StkFloat sample); 98 99 //! Take a channel of the StkFrames object as inputs to the filter and replace with corresponding outputs. 100 /*! 101 The \c channel argument should be zero or greater (the first 102 channel is specified by 0). An StkError will be thrown if the \c 103 channel argument is equal to or greater than the number of 104 channels in the StkFrames object. 105 */ 106 virtual StkFrames& tick( StkFrames& frames, unsigned int channel = 0 ); 107 108 protected: 109 110 // This function must be implemented in all subclasses. It is used 111 // to get around a C++ problem with overloaded virtual functions. 112 virtual StkFloat computeSample( StkFloat input ); 113 }; 114 115 } // namespace Nyq 116 117 #endif 118