Home   Information   Classes   Download   Usage   Mail List   Requirements   Links   FAQ   Tutorial


Flute.h

00001 #ifndef STK_FLUTE_H
00002 #define STK_FLUTE_H
00003 
00004 #include "Instrmnt.h"
00005 #include "JetTable.h"
00006 #include "DelayL.h"
00007 #include "OnePole.h"
00008 #include "PoleZero.h"
00009 #include "Noise.h"
00010 #include "ADSR.h"
00011 #include "SineWave.h"
00012 
00013 namespace stk {
00014 
00015 /***************************************************/
00037 /***************************************************/
00038 
00039 class Flute : public Instrmnt
00040 {
00041  public:
00043 
00046   Flute( StkFloat lowestFrequency );
00047 
00049   ~Flute( void );
00050 
00052   void clear( void );
00053 
00055   void setFrequency( StkFloat frequency );
00056 
00058   void setJetReflection( StkFloat coefficient );
00059 
00061   void setEndReflection( StkFloat coefficient );
00062 
00064   void setJetDelay( StkFloat aRatio );
00065 
00067   void startBlowing( StkFloat amplitude, StkFloat rate );
00068 
00070   void stopBlowing( StkFloat rate );
00071 
00073   void noteOn( StkFloat frequency, StkFloat amplitude );
00074 
00076   void noteOff( StkFloat amplitude );
00077 
00079   void controlChange( int number, StkFloat value );
00080 
00082   StkFloat tick( unsigned int channel = 0 );
00083 
00084  protected:
00085 
00086   DelayL   jetDelay_;
00087   DelayL   boreDelay_;
00088   JetTable jetTable_;
00089   OnePole  filter_;
00090   PoleZero dcBlock_;
00091   Noise    noise_;
00092   ADSR     adsr_;
00093   SineWave vibrato_;
00094   unsigned long length_;
00095   StkFloat lastFrequency_;
00096   StkFloat maxPressure_;
00097   StkFloat jetReflection_;
00098   StkFloat endReflection_;
00099   StkFloat noiseGain_;
00100   StkFloat vibratoGain_;
00101   StkFloat outputGain_;
00102   StkFloat jetRatio_;
00103 
00104 };
00105 
00106 inline StkFloat Flute :: tick( unsigned int )
00107 {
00108   StkFloat pressureDiff;
00109   StkFloat breathPressure;
00110 
00111   // Calculate the breath pressure (envelope + noise + vibrato)
00112   breathPressure = maxPressure_ * adsr_.tick();
00113   breathPressure += breathPressure * ( noiseGain_ * noise_.tick() + vibratoGain_ * vibrato_.tick() );
00114 
00115   StkFloat temp = filter_.tick( boreDelay_.lastOut() );
00116   temp = dcBlock_.tick( temp ); // Block DC on reflection.
00117 
00118   pressureDiff = breathPressure - (jetReflection_ * temp);
00119   pressureDiff = jetDelay_.tick( pressureDiff );
00120   pressureDiff = jetTable_.tick( pressureDiff ) + (endReflection_ * temp);
00121   lastFrame_[0] = (StkFloat) 0.3 * boreDelay_.tick( pressureDiff );
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.