Home Information Classes Download Usage Mail List Requirements Links FAQ Tutorial

# Plucked.h

    00001 #ifndef STK_PLUCKED_H
    00002 #define STK_PLUCKED_H
    00003
    00004 #include "Instrmnt.h"
    00005 #include "DelayA.h"
    00006 #include "OneZero.h"
    00007 #include "OnePole.h"
    00008 #include "Noise.h"
    00009
    00010 namespace stk {
    00011
    00012 /***************************************************/
    00032 /***************************************************/
    00033
    00034 class Plucked : public Instrmnt
    00035 {
    00036  public:
    00038   Plucked( StkFloat lowestFrequency = 10.0 );
    00039
    00041   ~Plucked( void );
    00042
    00044   void clear( void );
    00045
    00047   void setFrequency( StkFloat frequency );
    00048
    00050   void pluck( StkFloat amplitude );
    00051
    00053   void noteOn( StkFloat frequency, StkFloat amplitude );
    00054
    00056   void noteOff( StkFloat amplitude );
    00057
    00059   StkFloat tick( unsigned int channel = 0 );
    00060
    00062
    00069   StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
    00070
    00071  protected:
    00072
    00073   DelayA   delayLine_;
    00074   OneZero  loopFilter_;
    00075   OnePole  pickFilter_;
    00076   Noise    noise_;
    00077
    00078   StkFloat loopGain_;
    00079 };
    00080
    00081 inline StkFloat Plucked :: tick( unsigned int )
    00082 {
    00083   // Here's the whole inner loop of the instrument!!
    00084   return lastFrame_[0] = 3.0 * delayLine_.tick( loopFilter_.tick( delayLine_.lastOut() * loopGain_ ) );
    00085 }
    00086
    00087 inline StkFrames& Plucked :: tick( StkFrames& frames, unsigned int channel )
    00088 {
    00089   unsigned int nChannels = lastFrame_.channels();
    00090 #if defined(_STK_DEBUG_)
    00091   if ( channel > frames.channels() - nChannels ) {
    00092     oStream_ << "Plucked::tick(): channel and StkFrames arguments are incompatible!";
    00093     handleError( StkError::FUNCTION_ARGUMENT );
    00094   }
    00095 #endif
    00096
    00097   StkFloat *samples = &frames[channel];
    00098   unsigned int j, hop = frames.channels() - nChannels;
    00099   if ( nChannels == 1 ) {
    00100     for ( unsigned int i=0; i<frames.frames(); i++, samples += hop )
    00101       *samples++ = tick();
    00102   }
    00103   else {
    00104     for ( unsigned int i=0; i<frames.frames(); i++, samples += hop ) {
    00105       *samples++ = tick();
    00106       for ( j=1; j<nChannels; j++ )
    00107         *samples++ = lastFrame_[j];
    00108     }
    00109   }
    00110
    00111   return frames;
    00112 }
    00113
    00114 } // stk namespace
    00115
    00116 #endif
    00117

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