Home   Information   Classes   Download   Usage   Mail List   Requirements   Links   FAQ   Tutorial


Saxofony.h

00001 #ifndef STK_SAXOFONY_H
00002 #define STK_SAXOFONY_H
00003 
00004 #include "Instrmnt.h"
00005 #include "DelayL.h"
00006 #include "ReedTable.h"
00007 #include "OneZero.h"
00008 #include "Envelope.h"
00009 #include "Noise.h"
00010 #include "SineWave.h"
00011 
00012 namespace stk {
00013 
00014 /***************************************************/
00049 /***************************************************/
00050 
00051 class Saxofony : public Instrmnt
00052 {
00053  public:
00055 
00058   Saxofony( StkFloat lowestFrequency );
00059 
00061   ~Saxofony( void );
00062 
00064   void clear( void );
00065 
00067   void setFrequency( StkFloat frequency );
00068 
00070   void setBlowPosition( StkFloat aPosition );
00071 
00073   void startBlowing( StkFloat amplitude, StkFloat rate );
00074 
00076   void stopBlowing( StkFloat rate );
00077 
00079   void noteOn( StkFloat frequency, StkFloat amplitude );
00080 
00082   void noteOff( StkFloat amplitude );
00083 
00085   void controlChange( int number, StkFloat value );
00086 
00088   StkFloat tick( unsigned int channel = 0 );
00089 
00090  protected:
00091 
00092   DelayL    delays_[2];
00093   ReedTable reedTable_;
00094   OneZero   filter_;
00095   Envelope  envelope_;
00096   Noise     noise_;
00097   SineWave vibrato_;
00098   unsigned long length_;
00099   StkFloat outputGain_;
00100   StkFloat noiseGain_;
00101   StkFloat vibratoGain_;
00102   StkFloat position_;
00103 
00104 };
00105 
00106 inline StkFloat Saxofony :: tick( unsigned int )
00107 {
00108   StkFloat pressureDiff;
00109   StkFloat breathPressure;
00110   StkFloat temp;
00111 
00112   // Calculate the breath pressure (envelope + noise + vibrato)
00113   breathPressure = envelope_.tick(); 
00114   breathPressure += breathPressure * noiseGain_ * noise_.tick();
00115   breathPressure += breathPressure * vibratoGain_ * vibrato_.tick();
00116 
00117   temp = -0.95 * filter_.tick( delays_[0].lastOut() );
00118   lastFrame_[0] = temp - delays_[1].lastOut();
00119   pressureDiff = breathPressure - lastFrame_[0];
00120   delays_[1].tick( temp );
00121   delays_[0].tick( breathPressure - (pressureDiff * reedTable_.tick(pressureDiff)) - temp );
00122 
00123   lastFrame_[0] *= outputGain_;
00124   return lastFrame_[0];
00125 }
00126 
00127 } // stk namespace
00128 
00129 #endif

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