Home   Information   Classes   Download   Usage   Mail List   Requirements   Links   FAQ   Tutorial


FormSwep.h

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 
00047   void setResonance( StkFloat frequency, StkFloat radius );
00048 
00050   void setStates( StkFloat frequency, StkFloat radius, StkFloat gain = 1.0 );
00051 
00053   void setTargets( StkFloat frequency, StkFloat radius, StkFloat gain = 1.0 );
00054 
00056 
00064   void setSweepRate( StkFloat rate );
00065 
00067 
00072   void setSweepTime( StkFloat time );
00073 
00075   StkFloat lastOut( void ) const { return lastFrame_[0]; };
00076 
00078   StkFloat tick( StkFloat input );
00079 
00081 
00089   StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
00090 
00092 
00100   StkFrames& tick( StkFrames& iFrames, StkFrames &oFrames, unsigned int iChannel = 0, unsigned int oChannel = 0 );
00101 
00102  protected:
00103 
00104   virtual void sampleRateChanged( StkFloat newRate, StkFloat oldRate );
00105 
00106   bool dirty_;
00107   StkFloat frequency_;
00108   StkFloat radius_;
00109   StkFloat startFrequency_;
00110   StkFloat startRadius_;
00111   StkFloat startGain_;
00112   StkFloat targetFrequency_;
00113   StkFloat targetRadius_;
00114   StkFloat targetGain_;
00115   StkFloat deltaFrequency_;
00116   StkFloat deltaRadius_;
00117   StkFloat deltaGain_;
00118   StkFloat sweepState_;
00119   StkFloat sweepRate_;
00120 
00121 };
00122 
00123 inline StkFloat FormSwep :: tick( StkFloat input )
00124 {                                     
00125   if ( dirty_ )  {
00126     sweepState_ += sweepRate_;
00127     if ( sweepState_ >= 1.0 )   {
00128       sweepState_ = 1.0;
00129       dirty_ = false;
00130       radius_ = targetRadius_;
00131       frequency_ = targetFrequency_;
00132       gain_ = targetGain_;
00133     }
00134     else {
00135       radius_ = startRadius_ + (deltaRadius_ * sweepState_);
00136       frequency_ = startFrequency_ + (deltaFrequency_ * sweepState_);
00137       gain_ = startGain_ + (deltaGain_ * sweepState_);
00138     }
00139     this->setResonance( frequency_, radius_ );
00140   }
00141 
00142   inputs_[0] = gain_ * input;
00143   lastFrame_[0] = b_[0] * inputs_[0] + b_[1] * inputs_[1] + b_[2] * inputs_[2];
00144   lastFrame_[0] -= a_[2] * outputs_[2] + a_[1] * outputs_[1];
00145   inputs_[2] = inputs_[1];
00146   inputs_[1] = inputs_[0];
00147   outputs_[2] = outputs_[1];
00148   outputs_[1] = lastFrame_[0];
00149 
00150   return lastFrame_[0];
00151 }
00152 
00153 inline StkFrames& FormSwep :: tick( StkFrames& frames, unsigned int channel )
00154 {
00155 #if defined(_STK_DEBUG_)
00156   if ( channel >= frames.channels() ) {
00157     oStream_ << "FormSwep::tick(): channel and StkFrames arguments are incompatible!";
00158     handleError( StkError::FUNCTION_ARGUMENT );
00159   }
00160 #endif
00161 
00162   StkFloat *samples = &frames[channel];
00163   unsigned int hop = frames.channels();
00164   for ( unsigned int i=0; i<frames.frames(); i++, samples += hop )
00165     *samples = tick( *samples );
00166 
00167   return frames;
00168 }
00169 
00170 inline StkFrames& FormSwep :: tick( StkFrames& iFrames, StkFrames& oFrames, unsigned int iChannel, unsigned int oChannel )
00171 {
00172 #if defined(_STK_DEBUG_)
00173   if ( iChannel >= iFrames.channels() || oChannel >= oFrames.channels() ) {
00174     oStream_ << "FormSwep::tick(): channel and StkFrames arguments are incompatible!";
00175     handleError( StkError::FUNCTION_ARGUMENT );
00176   }
00177 #endif
00178 
00179   StkFloat *iSamples = &iFrames[iChannel];
00180   StkFloat *oSamples = &oFrames[oChannel];
00181   unsigned int iHop = iFrames.channels(), oHop = oFrames.channels();
00182   for ( unsigned int i=0; i<iFrames.frames(); i++, iSamples += iHop, oSamples += oHop )
00183     *oSamples = tick( *iSamples );
00184 
00185   return iFrames;
00186 }
00187 
00188 } // stk namespace
00189 
00190 #endif

The Synthesis ToolKit in C++ (STK)
©1995-2012 Perry R. Cook and Gary P. Scavone. All Rights Reserved.