Home   Information   Classes   Download   Usage   Mail List   Requirements   Links   FAQ   Tutorial


Simple.h

00001 #ifndef STK_SIMPLE_H
00002 #define STK_SIMPLE_H
00003 
00004 #include "Instrmnt.h"
00005 #include "ADSR.h"
00006 #include "FileLoop.h"
00007 #include "OnePole.h"
00008 #include "BiQuad.h"
00009 #include "Noise.h"
00010 
00011 namespace stk {
00012 
00013 /***************************************************/
00030 /***************************************************/
00031 
00032 class Simple : public Instrmnt
00033 {
00034  public:
00036 
00039   Simple( void );
00040 
00042   ~Simple( void );
00043 
00045   void clear( void );
00046 
00048   void setFrequency( StkFloat frequency );
00049 
00051   void keyOn( void );
00052 
00054   void keyOff( void );
00055 
00057   void noteOn( StkFloat frequency, StkFloat amplitude );
00058 
00060   void noteOff( StkFloat amplitude );
00061 
00063   void controlChange( int number, StkFloat value );
00064 
00066   StkFloat tick( unsigned int channel = 0 );
00067 
00069 
00076   StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
00077 
00078  protected:
00079 
00080   ADSR      adsr_; 
00081   FileLoop *loop_;
00082   OnePole   filter_;
00083   BiQuad    biquad_;
00084   Noise     noise_;
00085   StkFloat  baseFrequency_;
00086   StkFloat  loopGain_;
00087 
00088 };
00089 
00090 inline StkFloat Simple :: tick( unsigned int )
00091 {
00092   lastFrame_[0] = loopGain_ * loop_->tick();
00093   biquad_.tick( noise_.tick() );
00094   lastFrame_[0] += (1.0 - loopGain_) * biquad_.lastOut();
00095   lastFrame_[0] = filter_.tick( lastFrame_[0] );
00096   lastFrame_[0] *= adsr_.tick();
00097   return lastFrame_[0];
00098 }
00099 
00100 inline StkFrames& Simple :: tick( StkFrames& frames, unsigned int channel )
00101 {
00102   unsigned int nChannels = lastFrame_.channels();
00103 #if defined(_STK_DEBUG_)
00104   if ( channel > frames.channels() - nChannels ) {
00105     oStream_ << "Simple::tick(): channel and StkFrames arguments are incompatible!";
00106     handleError( StkError::FUNCTION_ARGUMENT );
00107   }
00108 #endif
00109 
00110   StkFloat *samples = &frames[channel];
00111   unsigned int j, hop = frames.channels() - nChannels;
00112   if ( nChannels == 1 ) {
00113     for ( unsigned int i=0; i<frames.frames(); i++, samples += hop )
00114       *samples++ = tick();
00115   }
00116   else {
00117     for ( unsigned int i=0; i<frames.frames(); i++, samples += hop ) {
00118       *samples++ = tick();
00119       for ( j=1; j<nChannels; j++ )
00120         *samples++ = lastFrame_[j];
00121     }
00122   }
00123 
00124   return frames;
00125 }
00126 
00127 } // stk namespace
00128 
00129 #endif

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