Home Information Classes Download Usage Mail List Requirements Links FAQ Tutorial
00001 #ifndef STK_POLEZERO_H 00002 #define STK_POLEZERO_H 00003 00004 #include "Filter.h" 00005 00006 namespace stk { 00007 00008 /***************************************************/ 00019 /***************************************************/ 00020 00021 class PoleZero : public Filter 00022 { 00023 public: 00024 00026 PoleZero(); 00027 00029 ~PoleZero(); 00030 00032 void setB0( StkFloat b0 ) { b_[0] = b0; }; 00033 00035 void setB1( StkFloat b1 ) { b_[1] = b1; }; 00036 00038 void setA1( StkFloat a1 ) { a_[1] = a1; }; 00039 00041 void setCoefficients( StkFloat b0, StkFloat b1, StkFloat a1, bool clearState = false ); 00042 00044 00050 void setAllpass( StkFloat coefficient ); 00051 00053 00059 void setBlockZero( StkFloat thePole = 0.99 ); 00060 00062 StkFloat lastOut( void ) const { return lastFrame_[0]; }; 00063 00065 StkFloat tick( StkFloat input ); 00066 00068 00075 StkFrames& tick( StkFrames& frames, unsigned int channel = 0 ); 00076 00077 }; 00078 00079 inline StkFloat PoleZero :: tick( StkFloat input ) 00080 { 00081 inputs_[0] = gain_ * input; 00082 lastFrame_[0] = b_[0] * inputs_[0] + b_[1] * inputs_[1] - a_[1] * outputs_[1]; 00083 inputs_[1] = inputs_[0]; 00084 outputs_[1] = lastFrame_[0]; 00085 00086 return lastFrame_[0]; 00087 } 00088 00089 inline StkFrames& PoleZero :: tick( StkFrames& frames, unsigned int channel ) 00090 { 00091 #if defined(_STK_DEBUG_) 00092 if ( channel >= frames.channels() ) { 00093 oStream_ << "PoleZero::tick(): channel and StkFrames arguments are incompatible!"; 00094 handleError( StkError::FUNCTION_ARGUMENT ); 00095 } 00096 #endif 00097 00098 StkFloat *samples = &frames[channel]; 00099 unsigned int hop = frames.channels(); 00100 for ( unsigned int i=0; i<frames.frames(); i++, samples += hop ) { 00101 inputs_[0] = gain_ * *samples; 00102 *samples = b_[0] * inputs_[0] + b_[1] * inputs_[1] - a_[1] * outputs_[1]; 00103 inputs_[1] = inputs_[0]; 00104 outputs_[1] = *samples; 00105 } 00106 00107 lastFrame_[0] = outputs_[1]; 00108 return frames; 00109 } 00110 00111 } // stk namespace 00112 00113 #endif
The Synthesis ToolKit in C++ (STK) |
©1995-2011 Perry R. Cook and Gary P. Scavone. All Rights Reserved. |