Home Information Classes Download Usage Mail List Requirements Links FAQ Tutorial
00001 #ifndef STK_TWANG_H 00002 #define STK_TWANG_H 00003 00004 #include "Stk.h" 00005 #include "DelayA.h" 00006 #include "DelayL.h" 00007 #include "Fir.h" 00008 00009 namespace stk { 00010 00011 /***************************************************/ 00032 /***************************************************/ 00033 00034 class Twang : public Stk 00035 { 00036 public: 00038 Twang( StkFloat lowestFrequency = 50.0 ); 00039 00041 ~Twang( void ); 00042 00044 void clear( void ); 00045 00047 void setLowestFrequency( StkFloat frequency ); 00048 00050 void setFrequency( StkFloat frequency ); 00051 00053 void setPluckPosition( StkFloat position ); 00054 00056 00062 void setLoopGain( StkFloat loopGain ); 00063 00065 00070 void setLoopFilter( std::vector<StkFloat> coefficients ); 00071 00073 const StkFrames& lastFrame( void ) const { return lastFrame_; }; 00074 00076 StkFloat tick( StkFloat input ); 00077 00079 00087 StkFrames& tick( StkFrames& frames, unsigned int channel = 0 ); 00088 00090 00098 StkFrames& tick( StkFrames& iFrames, StkFrames &oFrames, unsigned int iChannel = 0, unsigned int oChannel = 0 ); 00099 00100 protected: 00101 00102 DelayA delayLine_; 00103 DelayL combDelay_; 00104 Fir loopFilter_; 00105 00106 StkFrames lastFrame_; 00107 StkFloat frequency_; 00108 StkFloat loopGain_; 00109 StkFloat pluckPosition_; 00110 }; 00111 00112 inline StkFloat Twang :: tick( StkFloat input ) 00113 { 00114 lastFrame_[0] = delayLine_.tick( input + loopFilter_.tick( delayLine_.lastOut() ) ); 00115 lastFrame_[0] -= combDelay_.tick( lastFrame_[0] ); // comb filtering on output 00116 00117 return lastFrame_[0] * 0.5; 00118 } 00119 00120 inline StkFrames& Twang :: tick( StkFrames& frames, unsigned int channel ) 00121 { 00122 #if defined(_STK_DEBUG_) 00123 if ( channel >= frames.channels() ) { 00124 oStream_ << "Twang::tick(): channel and StkFrames arguments are incompatible!"; 00125 handleError( StkError::FUNCTION_ARGUMENT ); 00126 } 00127 #endif 00128 00129 StkFloat *samples = &frames[channel]; 00130 unsigned int hop = frames.channels(); 00131 for ( unsigned int i=0; i<frames.frames(); i++, samples += hop ) 00132 *samples = tick( *samples ); 00133 00134 return frames; 00135 } 00136 00137 inline StkFrames& Twang :: tick( StkFrames& iFrames, StkFrames& oFrames, unsigned int iChannel, unsigned int oChannel ) 00138 { 00139 #if defined(_STK_DEBUG_) 00140 if ( iChannel >= iFrames.channels() || oChannel >= oFrames.channels() ) { 00141 oStream_ << "Twang::tick(): channel and StkFrames arguments are incompatible!"; 00142 handleError( StkError::FUNCTION_ARGUMENT ); 00143 } 00144 #endif 00145 00146 StkFloat *iSamples = &iFrames[iChannel]; 00147 StkFloat *oSamples = &oFrames[oChannel]; 00148 unsigned int iHop = iFrames.channels(), oHop = oFrames.channels(); 00149 for ( unsigned int i=0; i<iFrames.frames(); i++, iSamples += iHop, oSamples += oHop ) 00150 *oSamples = tick( *iSamples ); 00151 00152 return iFrames; 00153 } 00154 00155 } // stk namespace 00156 00157 #endif 00158
The Synthesis ToolKit in C++ (STK) |
©1995-2011 Perry R. Cook and Gary P. Scavone. All Rights Reserved. |