Home   Information   Classes   Download   Usage   Mail List   Requirements   Links   FAQ   Tutorial


Brass.h

00001 #ifndef STK_BRASS_H
00002 #define STK_BRASS_H
00003 
00004 #include "Instrmnt.h"
00005 #include "DelayA.h"
00006 #include "BiQuad.h"
00007 #include "PoleZero.h"
00008 #include "ADSR.h"
00009 #include "SineWave.h"
00010 
00011 namespace stk {
00012 
00013 /***************************************************/
00033 /***************************************************/
00034 
00035 class Brass: public Instrmnt
00036 {
00037  public:
00039 
00042   Brass( StkFloat lowestFrequency );
00043 
00045   ~Brass(  );
00046 
00048   void clear(  );
00049 
00051   void setFrequency( StkFloat frequency );
00052 
00054   void setLip( StkFloat frequency );
00055 
00057   void startBlowing( StkFloat amplitude, StkFloat rate );
00058 
00060   void stopBlowing( StkFloat rate );
00061 
00063   void noteOn( StkFloat frequency, StkFloat amplitude );
00064 
00066   void noteOff( StkFloat amplitude );
00067 
00069   void controlChange( int number, StkFloat value );
00070 
00072   StkFloat tick( unsigned int channel = 0 );
00073 
00074  protected:
00075 
00076   DelayA   delayLine_;
00077   BiQuad   lipFilter_;
00078   PoleZero dcBlock_;
00079   ADSR     adsr_;
00080   SineWave vibrato_;
00081   unsigned long length_;
00082   StkFloat lipTarget_;
00083   StkFloat slideTarget_;
00084   StkFloat vibratoGain_;
00085   StkFloat maxPressure_;
00086 
00087 };
00088 
00089 inline StkFloat Brass :: tick( unsigned int )
00090 {
00091   StkFloat breathPressure = maxPressure_ * adsr_.tick();
00092   breathPressure += vibratoGain_ * vibrato_.tick();
00093 
00094   StkFloat mouthPressure = 0.3 * breathPressure;
00095   StkFloat borePressure = 0.85 * delayLine_.lastOut();
00096   StkFloat deltaPressure = mouthPressure - borePressure; // Differential pressure.
00097   deltaPressure = lipFilter_.tick( deltaPressure );      // Force - > position.
00098   deltaPressure *= deltaPressure;                        // Basic position to area mapping.
00099   if ( deltaPressure > 1.0 ) deltaPressure = 1.0;        // Non-linear saturation.
00100 
00101   // The following input scattering assumes the mouthPressure = area.
00102   lastFrame_[0] = deltaPressure * mouthPressure + ( 1.0 - deltaPressure) * borePressure;
00103   lastFrame_[0] = delayLine_.tick( dcBlock_.tick( lastFrame_[0] ) );
00104 
00105   return lastFrame_[0];
00106 }
00107 
00108 } // stk namespace
00109 
00110 #endif

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