Home   Information   Classes   Download   Usage   Mail List   Requirements   Links   FAQ   Tutorial


Moog.h

00001 #ifndef STK_MOOG_H
00002 #define STK_MOOG_H
00003 
00004 #include "Sampler.h"
00005 #include "FormSwep.h"
00006 
00007 namespace stk {
00008 
00009 /***************************************************/
00027 /***************************************************/
00028 
00029 class Moog : public Sampler
00030 {
00031  public:
00033 
00036   Moog( void );
00037 
00039   ~Moog( void );
00040 
00042   void setFrequency( StkFloat frequency );
00043 
00045   void noteOn( StkFloat frequency, StkFloat amplitude );
00046 
00048   void setModulationSpeed( StkFloat mSpeed ) { loops_[1]->setFrequency( mSpeed ); };
00049 
00051   void setModulationDepth( StkFloat mDepth ) { modDepth_ = mDepth * 0.5; };
00052 
00054   void controlChange( int number, StkFloat value );
00055 
00057   StkFloat tick( unsigned int channel = 0 );
00058 
00060 
00067   StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
00068 
00069  protected:
00070 
00071   FormSwep filters_[2];
00072   StkFloat modDepth_;
00073   StkFloat filterQ_;
00074   StkFloat filterRate_;
00075 
00076 };
00077 
00078 inline StkFloat Moog :: tick( unsigned int )
00079 {
00080   StkFloat temp;
00081 
00082   if ( modDepth_ != 0.0 ) {
00083     temp = loops_[1]->tick() * modDepth_;    
00084     loops_[0]->setFrequency( baseFrequency_ * (1.0 + temp) );
00085   }
00086 
00087   temp = attackGain_ * attacks_[0]->tick();
00088   temp += loopGain_ * loops_[0]->tick();
00089   temp = filter_.tick( temp );
00090   temp *= adsr_.tick();
00091   temp = filters_[0].tick( temp );
00092   lastFrame_[0] = filters_[1].tick( temp );
00093   return lastFrame_[0] * 6.0;
00094 }
00095 
00096 inline StkFrames& Moog :: tick( StkFrames& frames, unsigned int channel )
00097 {
00098   unsigned int nChannels = lastFrame_.channels();
00099 #if defined(_STK_DEBUG_)
00100   if ( channel > frames.channels() - nChannels ) {
00101     oStream_ << "Moog::tick(): channel and StkFrames arguments are incompatible!";
00102     handleError( StkError::FUNCTION_ARGUMENT );
00103   }
00104 #endif
00105 
00106   StkFloat *samples = &frames[channel];
00107   unsigned int j, hop = frames.channels() - nChannels;
00108   if ( nChannels == 1 ) {
00109     for ( unsigned int i=0; i<frames.frames(); i++, samples += hop )
00110       *samples++ = tick();
00111   }
00112   else {
00113     for ( unsigned int i=0; i<frames.frames(); i++, samples += hop ) {
00114       *samples++ = tick();
00115       for ( j=1; j<nChannels; j++ )
00116         *samples++ = lastFrame_[j];
00117     }
00118   }
00119 
00120   return frames;
00121 }
00122 
00123 } // stk namespace
00124 
00125 #endif

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