Home Information Classes Download Usage Mail List Requirements Links FAQ Tutorial

# StifKarp.h

    00001 #ifndef STK_STIFKARP_H
    00002 #define STK_STIFKARP_H
    00003
    00004 #include "Instrmnt.h"
    00005 #include "DelayL.h"
    00006 #include "DelayA.h"
    00007 #include "OneZero.h"
    00008 #include "Noise.h"
    00009 #include "BiQuad.h"
    00010
    00011 namespace stk {
    00012
    00013 /***************************************************/
    00034 /***************************************************/
    00035
    00036 class StifKarp : public Instrmnt
    00037 {
    00038  public:
    00040   StifKarp( StkFloat lowestFrequency = 8.0 );
    00041
    00043   ~StifKarp( void );
    00044
    00046   void clear( void );
    00047
    00049   void setFrequency( StkFloat frequency );
    00050
    00052   void setStretch( StkFloat stretch );
    00053
    00055   void setPickupPosition( StkFloat position );
    00056
    00058
    00063   void setBaseLoopGain( StkFloat aGain );
    00064
    00066   void pluck( StkFloat amplitude );
    00067
    00069   void noteOn( StkFloat frequency, StkFloat amplitude );
    00070
    00072   void noteOff( StkFloat amplitude );
    00073
    00075   void controlChange( int number, StkFloat value );
    00076
    00078   StkFloat tick( unsigned int channel = 0 );
    00079
    00081
    00088   StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
    00089
    00090  protected:
    00091
    00092   DelayA  delayLine_;
    00093   DelayL  combDelay_;
    00094   OneZero filter_;
    00095   Noise   noise_;
    00096   BiQuad  biquad_[4];
    00097
    00098   unsigned long length_;
    00099   StkFloat loopGain_;
    00100   StkFloat baseLoopGain_;
    00101   StkFloat lastFrequency_;
    00102   StkFloat lastLength_;
    00103   StkFloat stretching_;
    00104   StkFloat pluckAmplitude_;
    00105   StkFloat pickupPosition_;
    00106
    00107 };
    00108
    00109 inline StkFloat StifKarp :: tick( unsigned int )
    00110 {
    00111   StkFloat temp = delayLine_.lastOut() * loopGain_;
    00112
    00113   // Calculate allpass stretching.
    00114   for (int i=0; i<4; i++)
    00115     temp = biquad_[i].tick(temp);
    00116
    00117   // Moving average filter.
    00118   temp = filter_.tick(temp);
    00119
    00120   lastFrame_[0] = delayLine_.tick(temp);
    00121   lastFrame_[0] = lastFrame_[0] - combDelay_.tick( lastFrame_[0] );
    00122   return lastFrame_[0];
    00123 }
    00124
    00125 inline StkFrames& StifKarp :: tick( StkFrames& frames, unsigned int channel )
    00126 {
    00127   unsigned int nChannels = lastFrame_.channels();
    00128 #if defined(_STK_DEBUG_)
    00129   if ( channel > frames.channels() - nChannels ) {
    00130     oStream_ << "StifKarp::tick(): channel and StkFrames arguments are incompatible!";
    00131     handleError( StkError::FUNCTION_ARGUMENT );
    00132   }
    00133 #endif
    00134
    00135   StkFloat *samples = &frames[channel];
    00136   unsigned int j, hop = frames.channels() - nChannels;
    00137   if ( nChannels == 1 ) {
    00138     for ( unsigned int i=0; i<frames.frames(); i++, samples += hop )
    00139       *samples++ = tick();
    00140   }
    00141   else {
    00142     for ( unsigned int i=0; i<frames.frames(); i++, samples += hop ) {
    00143       *samples++ = tick();
    00144       for ( j=1; j<nChannels; j++ )
    00145         *samples++ = lastFrame_[j];
    00146     }
    00147   }
    00148
    00149   return frames;
    00150 }
    00151
    00152 } // stk namespace
    00153
    00154 #endif

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