Home   Information   Classes   Download   Usage   Mail List   Requirements   Links   FAQ   Tutorial


Echo.h

00001 #ifndef STK_ECHO_H
00002 #define STK_ECHO_H
00003 
00004 #include "Effect.h" 
00005 #include "Delay.h" 
00006 
00007 namespace stk {
00008 
00009 /***************************************************/
00017 /***************************************************/
00018 
00019 class Echo : public Effect
00020 {
00021  public:
00023 
00026   Echo( unsigned long maximumDelay = (unsigned long) Stk::sampleRate() );
00027 
00029   void clear();
00030 
00032   void setMaximumDelay( unsigned long delay );
00033 
00035   void setDelay( unsigned long delay );
00036 
00038   StkFloat lastOut( void ) const { return lastFrame_[0]; };
00039 
00041   StkFloat tick( StkFloat input );
00042 
00044 
00052   StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
00053 
00055 
00063   StkFrames& tick( StkFrames& iFrames, StkFrames &oFrames, unsigned int iChannel = 0, unsigned int oChannel = 0 );
00064 
00065  protected:
00066 
00067   Delay delayLine_;
00068   unsigned long length_;
00069 
00070 };
00071 
00072 inline StkFloat Echo :: tick( StkFloat input )
00073 {
00074   lastFrame_[0] = effectMix_ * ( delayLine_.tick( input ) - input ) + input;
00075   return lastFrame_[0];
00076 }
00077 
00078 inline StkFrames& Echo :: tick( StkFrames& frames, unsigned int channel )
00079 {
00080 #if defined(_STK_DEBUG_)
00081   if ( channel >= frames.channels() ) {
00082     oStream_ << "Echo::tick(): channel and StkFrames arguments are incompatible!";
00083     handleError( StkError::FUNCTION_ARGUMENT );
00084   }
00085 #endif
00086 
00087   StkFloat *samples = &frames[channel];
00088   unsigned int hop = frames.channels();
00089   for ( unsigned int i=0; i<frames.frames(); i++, samples += hop ) {
00090     *samples = effectMix_ * ( delayLine_.tick( *samples ) - *samples ) + *samples;
00091   }
00092 
00093   lastFrame_[0] = *(samples-hop);
00094   return frames;
00095 }
00096 
00097 inline StkFrames& Echo :: tick( StkFrames& iFrames, StkFrames& oFrames, unsigned int iChannel, unsigned int oChannel )
00098 {
00099 #if defined(_STK_DEBUG_)
00100   if ( iChannel >= iFrames.channels() || oChannel >= oFrames.channels() ) {
00101     oStream_ << "Echo::tick(): channel and StkFrames arguments are incompatible!";
00102     handleError( StkError::FUNCTION_ARGUMENT );
00103   }
00104 #endif
00105 
00106   StkFloat *iSamples = &iFrames[iChannel];
00107   StkFloat *oSamples = &oFrames[oChannel];
00108   unsigned int iHop = iFrames.channels(), oHop = oFrames.channels();
00109   for ( unsigned int i=0; i<iFrames.frames(); i++, iSamples += iHop, oSamples += oHop ) {
00110     *oSamples = effectMix_ * ( delayLine_.tick( *iSamples ) - *iSamples ) + *iSamples;
00111   }
00112 
00113   lastFrame_[0] = *(oSamples-oHop);
00114   return iFrames;
00115 }
00116 
00117 } // stk namespace
00118 
00119 #endif
00120 

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