Home Information Classes Download Usage Mail List Requirements Links FAQ Tutorial
00001 #ifndef STK_TWOPOLE_H 00002 #define STK_TWOPOLE_H 00003 00004 #include "Filter.h" 00005 00006 namespace stk { 00007 00008 /***************************************************/ 00018 /***************************************************/ 00019 00020 class TwoPole : public Filter 00021 { 00022 public: 00023 00025 TwoPole( void ); 00026 00028 ~TwoPole(); 00029 00031 void ignoreSampleRateChange( bool ignore = true ) { ignoreSampleRateChange_ = ignore; }; 00032 00034 void setB0( StkFloat b0 ) { b_[0] = b0; }; 00035 00037 void setA1( StkFloat a1 ) { a_[1] = a1; }; 00038 00040 void setA2( StkFloat a2 ) { a_[2] = a2; }; 00041 00043 void setCoefficients( StkFloat b0, StkFloat a1, StkFloat a2, bool clearState = false ); 00044 00046 00059 void setResonance(StkFloat frequency, StkFloat radius, bool normalize = false); 00060 00062 StkFloat lastOut( void ) const { return lastFrame_[0]; }; 00063 00065 StkFloat tick( StkFloat input ); 00066 00068 00076 StkFrames& tick( StkFrames& frames, unsigned int channel = 0 ); 00077 00079 00087 StkFrames& tick( StkFrames& iFrames, StkFrames &oFrames, unsigned int iChannel = 0, unsigned int oChannel = 0 ); 00088 00089 protected: 00090 00091 virtual void sampleRateChanged( StkFloat newRate, StkFloat oldRate ); 00092 }; 00093 00094 inline StkFloat TwoPole :: tick( StkFloat input ) 00095 { 00096 inputs_[0] = gain_ * input; 00097 lastFrame_[0] = b_[0] * inputs_[0] - a_[1] * outputs_[1] - a_[2] * outputs_[2]; 00098 outputs_[2] = outputs_[1]; 00099 outputs_[1] = lastFrame_[0]; 00100 00101 return lastFrame_[0]; 00102 } 00103 00104 inline StkFrames& TwoPole :: tick( StkFrames& frames, unsigned int channel ) 00105 { 00106 #if defined(_STK_DEBUG_) 00107 if ( channel >= frames.channels() ) { 00108 errorString_ << "TwoPole::tick(): channel and StkFrames arguments are incompatible!"; 00109 handleError( StkError::FUNCTION_ARGUMENT ); 00110 } 00111 #endif 00112 00113 StkFloat *samples = &frames[channel]; 00114 unsigned int hop = frames.channels(); 00115 for ( unsigned int i=0; i<frames.frames(); i++, samples += hop ) { 00116 inputs_[0] = gain_ * *samples; 00117 *samples = b_[0] * inputs_[0] - a_[1] * outputs_[1] - a_[2] * outputs_[2]; 00118 outputs_[2] = outputs_[1]; 00119 outputs_[1] = *samples; 00120 } 00121 00122 lastFrame_[0] = outputs_[1]; 00123 return frames; 00124 } 00125 00126 inline StkFrames& TwoPole :: tick( StkFrames& iFrames, StkFrames& oFrames, unsigned int iChannel, unsigned int oChannel ) 00127 { 00128 #if defined(_STK_DEBUG_) 00129 if ( iChannel >= iFrames.channels() || oChannel >= oFrames.channels() ) { 00130 errorString_ << "TwoPole::tick(): channel and StkFrames arguments are incompatible!"; 00131 handleError( StkError::FUNCTION_ARGUMENT ); 00132 } 00133 #endif 00134 00135 StkFloat *iSamples = &iFrames[iChannel]; 00136 StkFloat *oSamples = &oFrames[oChannel]; 00137 unsigned int iHop = iFrames.channels(), oHop = oFrames.channels(); 00138 for ( unsigned int i=0; i<iFrames.frames(); i++, iSamples += iHop, oSamples += oHop ) { 00139 inputs_[0] = gain_ * *iSamples; 00140 *oSamples = b_[0] * inputs_[0] - a_[1] * outputs_[1] - a_[2] * outputs_[2]; 00141 outputs_[2] = outputs_[1]; 00142 outputs_[1] = *oSamples; 00143 } 00144 00145 lastFrame_[0] = outputs_[1]; 00146 return iFrames; 00147 } 00148 00149 } // stk namespace 00150 00151 #endif
The Synthesis ToolKit in C++ (STK) |
©1995-2010 Perry R. Cook and Gary P. Scavone. All Rights Reserved. |