Home Information Classes Download Usage Mail List Requirements Links FAQ Tutorial

# Resonate.h

    00001 #ifndef STK_RESONATE_H
    00002 #define STK_RESONATE_H
    00003
    00004 #include "Instrmnt.h"
    00005 #include "ADSR.h"
    00006 #include "BiQuad.h"
    00007 #include "Noise.h"
    00008
    00009 namespace stk {
    00010
    00011 /***************************************************/
    00028 /***************************************************/
    00029
    00030 class Resonate : public Instrmnt
    00031 {
    00032  public:
    00034   Resonate( void );
    00035
    00037   ~Resonate( void );
    00038
    00040   void clear( void );
    00041
    00043   void setResonance( StkFloat frequency, StkFloat radius );
    00044
    00046   void setNotch( StkFloat frequency, StkFloat radius );
    00047
    00049   void setEqualGainZeroes( void ) { filter_.setEqualGainZeroes(); };
    00050
    00052   void keyOn( void ) { adsr_.keyOn(); };
    00053
    00055   void keyOff( void ) { adsr_.keyOff(); };
    00056
    00058   void noteOn( StkFloat frequency, StkFloat amplitude );
    00059
    00061   void noteOff( StkFloat amplitude );
    00062
    00064   void controlChange( int number, StkFloat value );
    00065
    00067   StkFloat tick( unsigned int channel = 0 );
    00068
    00070
    00077   StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
    00078
    00079  protected:
    00080
    00081   ADSR     adsr_;
    00082   BiQuad   filter_;
    00083   Noise    noise_;
    00084   StkFloat poleFrequency_;
    00085   StkFloat poleRadius_;
    00086   StkFloat zeroFrequency_;
    00087   StkFloat zeroRadius_;
    00088
    00089 };
    00090
    00091 inline StkFloat Resonate :: tick( unsigned int )
    00092 {
    00093   lastFrame_[0] = filter_.tick( noise_.tick() );
    00094   lastFrame_[0] *= adsr_.tick();
    00095   return lastFrame_[0];
    00096 }
    00097
    00098 inline StkFrames& Resonate :: tick( StkFrames& frames, unsigned int channel )
    00099 {
    00100   unsigned int nChannels = lastFrame_.channels();
    00101 #if defined(_STK_DEBUG_)
    00102   if ( channel > frames.channels() - nChannels ) {
    00103     oStream_ << "Resonate::tick(): channel and StkFrames arguments are incompatible!";
    00104     handleError( StkError::FUNCTION_ARGUMENT );
    00105   }
    00106 #endif
    00107
    00108   StkFloat *samples = &frames[channel];
    00109   unsigned int j, hop = frames.channels() - nChannels;
    00110   if ( nChannels == 1 ) {
    00111     for ( unsigned int i=0; i<frames.frames(); i++, samples += hop )
    00112       *samples++ = tick();
    00113   }
    00114   else {
    00115     for ( unsigned int i=0; i<frames.frames(); i++, samples += hop ) {
    00116       *samples++ = tick();
    00117       for ( j=1; j<nChannels; j++ )
    00118         *samples++ = lastFrame_[j];
    00119     }
    00120   }
    00121
    00122   return frames;
    00123 }
    00124
    00125 } // stk namespace
    00126
    00127 #endif

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