Home Information Classes Download Usage Mail List Requirements Links FAQ Tutorial

# BlowHole.h

    00001 #ifndef STK_BLOWHOLE_H
    00002 #define STK_BLOWHOLE_H
    00003
    00004 #include "Instrmnt.h"
    00005 #include "DelayL.h"
    00006 #include "ReedTable.h"
    00007 #include "OneZero.h"
    00008 #include "PoleZero.h"
    00009 #include "Envelope.h"
    00010 #include "Noise.h"
    00011 #include "SineWave.h"
    00012
    00013 namespace stk {
    00014
    00015 /***************************************************/
    00048 /***************************************************/
    00049
    00050 class BlowHole : public Instrmnt
    00051 {
    00052  public:
    00054
    00057   BlowHole( StkFloat lowestFrequency );
    00058
    00060   ~BlowHole( void );
    00061
    00063   void clear( void );
    00064
    00066   void setFrequency( StkFloat frequency );
    00067
    00069   void setTonehole( StkFloat newValue );
    00070
    00072   void setVent( StkFloat newValue );
    00073
    00075   void startBlowing( StkFloat amplitude, StkFloat rate );
    00076
    00078   void stopBlowing( StkFloat rate );
    00079
    00081   void noteOn( StkFloat frequency, StkFloat amplitude );
    00082
    00084   void noteOff( StkFloat amplitude );
    00085
    00087   void controlChange( int number, StkFloat value );
    00088
    00090   StkFloat tick( unsigned int channel = 0 );
    00091
    00092  protected:
    00093
    00094   DelayL    delays_[3];
    00095   ReedTable reedTable_;
    00096   OneZero   filter_;
    00097   PoleZero  tonehole_;
    00098   PoleZero  vent_;
    00099   Envelope  envelope_;
    00100   Noise     noise_;
    00101   SineWave vibrato_;
    00102   unsigned long length_;
    00103   StkFloat scatter_;
    00104   StkFloat thCoeff_;
    00105   StkFloat rhGain_;
    00106   StkFloat outputGain_;
    00107   StkFloat noiseGain_;
    00108   StkFloat vibratoGain_;
    00109
    00110 };
    00111
    00112   inline StkFloat BlowHole :: tick( unsigned int )
    00113 {
    00114   StkFloat pressureDiff;
    00115   StkFloat breathPressure;
    00116   StkFloat temp;
    00117
    00118   // Calculate the breath pressure (envelope + noise + vibrato)
    00119   breathPressure = envelope_.tick();
    00120   breathPressure += breathPressure * noiseGain_ * noise_.tick();
    00121   breathPressure += breathPressure * vibratoGain_ * vibrato_.tick();
    00122
    00123   // Calculate the differential pressure = reflected - mouthpiece pressures
    00124   pressureDiff = delays_[0].lastOut() - breathPressure;
    00125
    00126   // Do two-port junction scattering for register vent
    00127   StkFloat pa = breathPressure + pressureDiff * reedTable_.tick( pressureDiff );
    00128   StkFloat pb = delays_[1].lastOut();
    00129   vent_.tick( pa+pb );
    00130
    00131   lastFrame_[0] = delays_[0].tick( vent_.lastOut()+pb );
    00132   lastFrame_[0] *= outputGain_;
    00133
    00134   // Do three-port junction scattering (under tonehole)
    00135   pa += vent_.lastOut();
    00136   pb = delays_[2].lastOut();
    00137   StkFloat pth = tonehole_.lastOut();
    00138   temp = scatter_ * (pa + pb - 2 * pth);
    00139
    00140   delays_[2].tick( filter_.tick(pa + temp) * -0.95 );
    00141   delays_[1].tick( pb + temp );
    00142   tonehole_.tick( pa + pb - pth + temp );
    00143
    00144   return lastFrame_[0];
    00145 }
    00146
    00147 } // stk namespace
    00148
    00149 #endif

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