Home   Information   Classes   Download   Usage   Mail List   Requirements   Links   FAQ   Tutorial


Sitar.h

00001 #ifndef STK_SITAR_H
00002 #define STK_SITAR_H
00003 
00004 #include "Instrmnt.h"
00005 #include "DelayA.h"
00006 #include "OneZero.h"
00007 #include "Noise.h"
00008 #include "ADSR.h"
00009 #include <cmath>
00010 
00011 namespace stk {
00012 
00013 /***************************************************/
00030 /***************************************************/
00031 
00032 class Sitar : public Instrmnt
00033 {
00034  public:
00036   Sitar( StkFloat lowestFrequency = 20 );
00037 
00039   ~Sitar( void );
00040 
00042   void clear( void );
00043 
00045   void setFrequency( StkFloat frequency );
00046 
00048   void pluck( StkFloat amplitude );
00049 
00051   void noteOn( StkFloat frequency, StkFloat amplitude );
00052 
00054   void noteOff( StkFloat amplitude );
00055 
00057   StkFloat tick( unsigned int channel = 0 );
00058 
00059  protected:
00060 
00061   DelayA  delayLine_;
00062   OneZero loopFilter_;
00063   Noise   noise_;
00064   ADSR    envelope_;
00065 
00066   StkFloat loopGain_;
00067   StkFloat amGain_;
00068   StkFloat delay_;
00069   StkFloat targetDelay_;
00070 
00071 };
00072 
00073 inline StkFloat Sitar :: tick( unsigned int )
00074 {
00075   if ( fabs(targetDelay_ - delay_) > 0.001 ) {
00076     if ( targetDelay_ < delay_ )
00077       delay_ *= 0.99999;
00078     else
00079       delay_ *= 1.00001;
00080     delayLine_.setDelay( delay_ );
00081   }
00082 
00083   lastFrame_[0] = delayLine_.tick( loopFilter_.tick( delayLine_.lastOut() * loopGain_ ) + 
00084                                 (amGain_ * envelope_.tick() * noise_.tick()));
00085   
00086   return lastFrame_[0];
00087 }
00088 
00089 } // stk namespace
00090 
00091 #endif
00092 

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