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 = 8.0 );
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 
00075 
00082   StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
00083 
00084  protected:
00085 
00086   DelayA   delayLine_;
00087   BiQuad   lipFilter_;
00088   PoleZero dcBlock_;
00089   ADSR     adsr_;
00090   SineWave vibrato_;
00091 
00092   StkFloat lipTarget_;
00093   StkFloat slideTarget_;
00094   StkFloat vibratoGain_;
00095   StkFloat maxPressure_;
00096 
00097 };
00098 
00099 inline StkFloat Brass :: tick( unsigned int )
00100 {
00101   StkFloat breathPressure = maxPressure_ * adsr_.tick();
00102   breathPressure += vibratoGain_ * vibrato_.tick();
00103 
00104   StkFloat mouthPressure = 0.3 * breathPressure;
00105   StkFloat borePressure = 0.85 * delayLine_.lastOut();
00106   StkFloat deltaPressure = mouthPressure - borePressure; // Differential pressure.
00107   deltaPressure = lipFilter_.tick( deltaPressure );      // Force - > position.
00108   deltaPressure *= deltaPressure;                        // Basic position to area mapping.
00109   if ( deltaPressure > 1.0 ) deltaPressure = 1.0;        // Non-linear saturation.
00110 
00111   // The following input scattering assumes the mouthPressure = area.
00112   lastFrame_[0] = deltaPressure * mouthPressure + ( 1.0 - deltaPressure) * borePressure;
00113   lastFrame_[0] = delayLine_.tick( dcBlock_.tick( lastFrame_[0] ) );
00114 
00115   return lastFrame_[0];
00116 }
00117 
00118 inline StkFrames& Brass :: tick( StkFrames& frames, unsigned int channel )
00119 {
00120   unsigned int nChannels = lastFrame_.channels();
00121 #if defined(_STK_DEBUG_)
00122   if ( channel > frames.channels() - nChannels ) {
00123     oStream_ << "Brass::tick(): channel and StkFrames arguments are incompatible!";
00124     handleError( StkError::FUNCTION_ARGUMENT );
00125   }
00126 #endif
00127 
00128   StkFloat *samples = &frames[channel];
00129   unsigned int j, hop = frames.channels() - nChannels;
00130   if ( nChannels == 1 ) {
00131     for ( unsigned int i=0; i<frames.frames(); i++, samples += hop )
00132       *samples++ = tick();
00133   }
00134   else {
00135     for ( unsigned int i=0; i<frames.frames(); i++, samples += hop ) {
00136       *samples++ = tick();
00137       for ( j=1; j<nChannels; j++ )
00138         *samples++ = lastFrame_[j];
00139     }
00140   }
00141 
00142   return frames;
00143 }
00144 
00145 } // stk namespace
00146 
00147 #endif

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