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 00061 void setResonance(StkFloat frequency, StkFloat radius, bool normalize = false); 00062 00064 StkFloat lastOut( void ) const { return lastFrame_[0]; }; 00065 00067 StkFloat tick( StkFloat input ); 00068 00070 00078 StkFrames& tick( StkFrames& frames, unsigned int channel = 0 ); 00079 00081 00089 StkFrames& tick( StkFrames& iFrames, StkFrames &oFrames, unsigned int iChannel = 0, unsigned int oChannel = 0 ); 00090 00091 protected: 00092 00093 virtual void sampleRateChanged( StkFloat newRate, StkFloat oldRate ); 00094 }; 00095 00096 inline StkFloat TwoPole :: tick( StkFloat input ) 00097 { 00098 inputs_[0] = gain_ * input; 00099 lastFrame_[0] = b_[0] * inputs_[0] - a_[1] * outputs_[1] - a_[2] * outputs_[2]; 00100 outputs_[2] = outputs_[1]; 00101 outputs_[1] = lastFrame_[0]; 00102 00103 return lastFrame_[0]; 00104 } 00105 00106 inline StkFrames& TwoPole :: tick( StkFrames& frames, unsigned int channel ) 00107 { 00108 #if defined(_STK_DEBUG_) 00109 if ( channel >= frames.channels() ) { 00110 oStream_ << "TwoPole::tick(): channel and StkFrames arguments are incompatible!"; 00111 handleError( StkError::FUNCTION_ARGUMENT ); 00112 } 00113 #endif 00114 00115 StkFloat *samples = &frames[channel]; 00116 unsigned int hop = frames.channels(); 00117 for ( unsigned int i=0; i<frames.frames(); i++, samples += hop ) { 00118 inputs_[0] = gain_ * *samples; 00119 *samples = b_[0] * inputs_[0] - a_[1] * outputs_[1] - a_[2] * outputs_[2]; 00120 outputs_[2] = outputs_[1]; 00121 outputs_[1] = *samples; 00122 } 00123 00124 lastFrame_[0] = outputs_[1]; 00125 return frames; 00126 } 00127 00128 inline StkFrames& TwoPole :: tick( StkFrames& iFrames, StkFrames& oFrames, unsigned int iChannel, unsigned int oChannel ) 00129 { 00130 #if defined(_STK_DEBUG_) 00131 if ( iChannel >= iFrames.channels() || oChannel >= oFrames.channels() ) { 00132 oStream_ << "TwoPole::tick(): channel and StkFrames arguments are incompatible!"; 00133 handleError( StkError::FUNCTION_ARGUMENT ); 00134 } 00135 #endif 00136 00137 StkFloat *iSamples = &iFrames[iChannel]; 00138 StkFloat *oSamples = &oFrames[oChannel]; 00139 unsigned int iHop = iFrames.channels(), oHop = oFrames.channels(); 00140 for ( unsigned int i=0; i<iFrames.frames(); i++, iSamples += iHop, oSamples += oHop ) { 00141 inputs_[0] = gain_ * *iSamples; 00142 *oSamples = b_[0] * inputs_[0] - a_[1] * outputs_[1] - a_[2] * outputs_[2]; 00143 outputs_[2] = outputs_[1]; 00144 outputs_[1] = *oSamples; 00145 } 00146 00147 lastFrame_[0] = outputs_[1]; 00148 return iFrames; 00149 } 00150 00151 } // stk namespace 00152 00153 #endif
The Synthesis ToolKit in C++ (STK) |
©1995-2012 Perry R. Cook and Gary P. Scavone. All Rights Reserved. |