The Synthesis ToolKit in C++ (STK)

Home Information Classes Download Usage Mail List Requirements Links FAQ Tutorial

# PitShift.h

    00001 #ifndef STK_PITSHIFT_H
    00002 #define STK_PITSHIFT_H
    00003
    00004 #include "Effect.h"
    00005 #include "DelayL.h"
    00006
    00007 namespace stk {
    00008
    00009 /***************************************************/
    00018 /***************************************************/
    00019
    00020 const int maxDelay = 5024;
    00021
    00022 class PitShift : public Effect
    00023 {
    00024  public:
    00026   PitShift( void );
    00027
    00029   void clear( void );
    00030
    00032   void setShift( StkFloat shift );
    00033
    00035   StkFloat lastOut( void ) const { return lastFrame_[0]; };
    00036
    00038   StkFloat tick( StkFloat input );
    00039
    00041
    00049   StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
    00050
    00052
    00060   StkFrames& tick( StkFrames& iFrames, StkFrames &oFrames, unsigned int iChannel = 0, unsigned int oChannel = 0 );
    00061
    00062  protected:
    00063
    00064   DelayL delayLine_[2];
    00065   StkFloat delay_[2];
    00066   StkFloat env_[2];
    00067   StkFloat rate_;
    00068   unsigned long delayLength_;
    00069   unsigned long halfLength_;
    00070
    00071 };
    00072
    00073 inline StkFloat PitShift :: tick( StkFloat input )
    00074 {
    00075   // Calculate the two delay length values, keeping them within the
    00076   // range 12 to maxDelay-12.
    00077   delay_[0] += rate_;
    00078   while ( delay_[0] > maxDelay-12 ) delay_[0] -= delayLength_;
    00079   while ( delay_[0] < 12 ) delay_[0] += delayLength_;
    00080
    00081   delay_[1] = delay_[0] + halfLength_;
    00082   while ( delay_[1] > maxDelay-12 ) delay_[1] -= delayLength_;
    00083   while ( delay_[1] < 12 ) delay_[1] += delayLength_;
    00084
    00085   // Set the new delay line lengths.
    00086   delayLine_[0].setDelay( delay_[0] );
    00087   delayLine_[1].setDelay( delay_[1] );
    00088
    00089   // Calculate a triangular envelope.
    00090   env_[1] = fabs( ( delay_[0] - halfLength_ + 12 ) * ( 1.0 / (halfLength_ + 12 ) ) );
    00091   env_[0] = 1.0 - env_[1];
    00092
    00093   // Delay input and apply envelope.
    00094   lastFrame_[0] =  env_[0] * delayLine_[0].tick( input );
    00095   lastFrame_[0] += env_[1] * delayLine_[1].tick( input );
    00096
    00097   // Compute effect mix and output.
    00098   lastFrame_[0] *= effectMix_;
    00099   lastFrame_[0] += ( 1.0 - effectMix_ ) * input;
    00100
    00101   return lastFrame_[0];
    00102 }
    00103
    00104 } // stk namespace
    00105
    00106 #endif
    00107

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