Home Information Classes Download Usage Mail List Requirements Links FAQ Tutorial
00001 #ifndef STK_FORMSWEP_H 00002 #define STK_FORMSWEP_H 00003 00004 #include "Filter.h" 00005 00006 namespace stk { 00007 00008 /***************************************************/ 00018 /***************************************************/ 00019 00020 class FormSwep : public Filter 00021 { 00022 public: 00023 00025 FormSwep( void ); 00026 00028 ~FormSwep(); 00029 00031 void ignoreSampleRateChange( bool ignore = true ) { ignoreSampleRateChange_ = ignore; }; 00032 00034 00045 void setResonance( StkFloat frequency, StkFloat radius ); 00046 00048 void setStates( StkFloat frequency, StkFloat radius, StkFloat gain = 1.0 ); 00049 00051 void setTargets( StkFloat frequency, StkFloat radius, StkFloat gain = 1.0 ); 00052 00054 00062 void setSweepRate( StkFloat rate ); 00063 00065 00070 void setSweepTime( StkFloat time ); 00071 00073 StkFloat lastOut( void ) const { return lastFrame_[0]; }; 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 virtual void sampleRateChanged( StkFloat newRate, StkFloat oldRate ); 00103 00104 bool dirty_; 00105 StkFloat frequency_; 00106 StkFloat radius_; 00107 StkFloat startFrequency_; 00108 StkFloat startRadius_; 00109 StkFloat startGain_; 00110 StkFloat targetFrequency_; 00111 StkFloat targetRadius_; 00112 StkFloat targetGain_; 00113 StkFloat deltaFrequency_; 00114 StkFloat deltaRadius_; 00115 StkFloat deltaGain_; 00116 StkFloat sweepState_; 00117 StkFloat sweepRate_; 00118 00119 }; 00120 00121 inline StkFloat FormSwep :: tick( StkFloat input ) 00122 { 00123 if ( dirty_ ) { 00124 sweepState_ += sweepRate_; 00125 if ( sweepState_ >= 1.0 ) { 00126 sweepState_ = 1.0; 00127 dirty_ = false; 00128 radius_ = targetRadius_; 00129 frequency_ = targetFrequency_; 00130 gain_ = targetGain_; 00131 } 00132 else { 00133 radius_ = startRadius_ + (deltaRadius_ * sweepState_); 00134 frequency_ = startFrequency_ + (deltaFrequency_ * sweepState_); 00135 gain_ = startGain_ + (deltaGain_ * sweepState_); 00136 } 00137 this->setResonance( frequency_, radius_ ); 00138 } 00139 00140 inputs_[0] = gain_ * input; 00141 lastFrame_[0] = b_[0] * inputs_[0] + b_[1] * inputs_[1] + b_[2] * inputs_[2]; 00142 lastFrame_[0] -= a_[2] * outputs_[2] + a_[1] * outputs_[1]; 00143 inputs_[2] = inputs_[1]; 00144 inputs_[1] = inputs_[0]; 00145 outputs_[2] = outputs_[1]; 00146 outputs_[1] = lastFrame_[0]; 00147 00148 return lastFrame_[0]; 00149 } 00150 00151 inline StkFrames& FormSwep :: tick( StkFrames& frames, unsigned int channel ) 00152 { 00153 #if defined(_STK_DEBUG_) 00154 if ( channel >= frames.channels() ) { 00155 errorString_ << "FormSwep::tick(): channel and StkFrames arguments are incompatible!"; 00156 handleError( StkError::FUNCTION_ARGUMENT ); 00157 } 00158 #endif 00159 00160 StkFloat *samples = &frames[channel]; 00161 unsigned int hop = frames.channels(); 00162 for ( unsigned int i=0; i<frames.frames(); i++, samples += hop ) 00163 *samples = tick( *samples ); 00164 00165 return frames; 00166 } 00167 00168 inline StkFrames& FormSwep :: tick( StkFrames& iFrames, StkFrames& oFrames, unsigned int iChannel, unsigned int oChannel ) 00169 { 00170 #if defined(_STK_DEBUG_) 00171 if ( iChannel >= iFrames.channels() || oChannel >= oFrames.channels() ) { 00172 errorString_ << "FormSwep::tick(): channel and StkFrames arguments are incompatible!"; 00173 handleError( StkError::FUNCTION_ARGUMENT ); 00174 } 00175 #endif 00176 00177 StkFloat *iSamples = &iFrames[iChannel]; 00178 StkFloat *oSamples = &oFrames[oChannel]; 00179 unsigned int iHop = iFrames.channels(), oHop = oFrames.channels(); 00180 for ( unsigned int i=0; i<iFrames.frames(); i++, iSamples += iHop, oSamples += oHop ) 00181 *oSamples = tick( *iSamples ); 00182 00183 return iFrames; 00184 } 00185 00186 } // stk namespace 00187 00188 #endif
The Synthesis ToolKit in C++ (STK) |
©1995-2010 Perry R. Cook and Gary P. Scavone. All Rights Reserved. |