Home   Information   Classes   Download   Usage   Mail List   Requirements   Links   FAQ   Tutorial


Chorus.h

00001 #ifndef STK_CHORUS_H
00002 #define STK_CHORUS_H
00003 
00004 #include "Effect.h"
00005 #include "DelayL.h"
00006 #include "SineWave.h"
00007 
00008 namespace stk {
00009 
00010 /***************************************************/
00019 /***************************************************/
00020 
00021 class Chorus : public Effect
00022 {
00023  public:
00025 
00028   Chorus( StkFloat baseDelay = 6000 );
00029 
00031   void clear( void );
00032 
00034   void setModDepth( StkFloat depth ) { modDepth_ = depth; };
00035 
00037   void setModFrequency( StkFloat frequency );
00038 
00040 
00048   StkFloat lastOut( unsigned int channel = 0 );
00049 
00051 
00058   StkFloat tick( StkFloat input, unsigned int channel = 0 );
00059 
00061 
00070   StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
00071 
00073 
00082   StkFrames& tick( StkFrames& iFrames, StkFrames &oFrames, unsigned int iChannel = 0, unsigned int oChannel = 0 );
00083 
00084  protected:
00085 
00086   DelayL delayLine_[2];
00087   SineWave mods_[2];
00088   StkFloat baseLength_;
00089   StkFloat modDepth_;
00090 
00091 };
00092 
00093 inline StkFloat Chorus :: lastOut( unsigned int channel )
00094 {
00095 #if defined(_STK_DEBUG_)
00096   if ( channel > 1 ) {
00097     errorString_ << "Chorus::lastOut(): channel argument must be less than 2!";
00098     handleError( StkError::FUNCTION_ARGUMENT );
00099   }
00100 #endif
00101 
00102   return lastFrame_[channel];
00103 }
00104 
00105 inline StkFloat Chorus :: tick( StkFloat input, unsigned int channel )
00106 {
00107 #if defined(_STK_DEBUG_)
00108   if ( channel > 1 ) {
00109     errorString_ << "Chorus::tick(): channel argument must be less than 2!";
00110     handleError( StkError::FUNCTION_ARGUMENT );
00111   }
00112 #endif
00113 
00114   delayLine_[0].setDelay( baseLength_ * 0.707 * ( 1.0 + modDepth_ * mods_[0].tick() ) );
00115   delayLine_[1].setDelay( baseLength_  * 0.5 *  ( 1.0 - modDepth_ * mods_[1].tick() ) );
00116   lastFrame_[0] = effectMix_ * ( delayLine_[0].tick( input ) - input ) + input;
00117   lastFrame_[1] = effectMix_ * ( delayLine_[1].tick( input ) - input ) + input;
00118   return lastFrame_[channel];
00119 }
00120 
00121 inline StkFrames& Chorus :: tick( StkFrames& frames, unsigned int channel )
00122 {
00123 #if defined(_STK_DEBUG_)
00124   if ( channel >= frames.channels() - 1 ) {
00125     errorString_ << "Chorus::tick(): channel and StkFrames arguments are incompatible!";
00126     handleError( StkError::FUNCTION_ARGUMENT );
00127   }
00128 #endif
00129 
00130   StkFloat *samples = &frames[channel];
00131   unsigned int hop = frames.channels() - 1;
00132   for ( unsigned int i=0; i<frames.frames(); i++, samples += hop ) {
00133     *samples = effectMix_ * ( delayLine_[0].tick( *samples ) - *samples ) + *samples;
00134     samples++;
00135     *samples = effectMix_ * ( delayLine_[1].tick( *samples ) - *samples ) + *samples;
00136   }
00137 
00138   lastFrame_[0] = *(samples-hop);
00139   lastFrame_[1] = *(samples-hop+1);
00140   return frames;
00141 }
00142 
00143 inline StkFrames& Chorus :: tick( StkFrames& iFrames, StkFrames& oFrames, unsigned int iChannel, unsigned int oChannel )
00144 {
00145 #if defined(_STK_DEBUG_)
00146   if ( iChannel >= iFrames.channels() || oChannel >= oFrames.channels() - 1 ) {
00147     errorString_ << "Chorus::tick(): channel and StkFrames arguments are incompatible!";
00148     handleError( StkError::FUNCTION_ARGUMENT );
00149   }
00150 #endif
00151 
00152   StkFloat *iSamples = &iFrames[iChannel];
00153   StkFloat *oSamples = &oFrames[oChannel];
00154   unsigned int iHop = iFrames.channels(), oHop = oFrames.channels();
00155   for ( unsigned int i=0; i<iFrames.frames(); i++, iSamples += iHop, oSamples += oHop ) {
00156     *oSamples++ = effectMix_ * ( delayLine_[0].tick( *iSamples ) - *iSamples ) + *iSamples;
00157     *oSamples = effectMix_ * ( delayLine_[1].tick( *iSamples ) - *iSamples ) + *iSamples;
00158   }
00159 
00160   lastFrame_[0] = *(oSamples-oHop);
00161   lastFrame_[1] = *(oSamples-oHop+1);
00162   return iFrames;
00163 }
00164 
00165 } // stk namespace
00166 
00167 #endif
00168 

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