Home Information Classes Download Usage Mail List Requirements Links FAQ Tutorial
00001 #ifndef STK_CLARINET_H 00002 #define STK_CLARINET_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 /***************************************************/ 00036 /***************************************************/ 00037 00038 class Clarinet : public Instrmnt 00039 { 00040 public: 00042 00045 Clarinet( StkFloat lowestFrequency ); 00046 00048 ~Clarinet( void ); 00049 00051 void clear( void ); 00052 00054 void setFrequency( 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 DelayL delayLine_; 00077 ReedTable reedTable_; 00078 OneZero filter_; 00079 Envelope envelope_; 00080 Noise noise_; 00081 SineWave vibrato_; 00082 long length_; 00083 StkFloat outputGain_; 00084 StkFloat noiseGain_; 00085 StkFloat vibratoGain_; 00086 00087 }; 00088 00089 inline StkFloat Clarinet :: tick( unsigned int ) 00090 { 00091 StkFloat pressureDiff; 00092 StkFloat breathPressure; 00093 00094 // Calculate the breath pressure (envelope + noise + vibrato) 00095 breathPressure = envelope_.tick(); 00096 breathPressure += breathPressure * noiseGain_ * noise_.tick(); 00097 breathPressure += breathPressure * vibratoGain_ * vibrato_.tick(); 00098 00099 // Perform commuted loss filtering. 00100 pressureDiff = -0.95 * filter_.tick( delayLine_.lastOut() ); 00101 00102 // Calculate pressure difference of reflected and mouthpiece pressures. 00103 pressureDiff = pressureDiff - breathPressure; 00104 00105 // Perform non-linear scattering using pressure difference in reed function. 00106 lastFrame_[0] = delayLine_.tick(breathPressure + pressureDiff * reedTable_.tick(pressureDiff)); 00107 00108 // Apply output gain. 00109 lastFrame_[0] *= outputGain_; 00110 00111 return lastFrame_[0]; 00112 } 00113 00114 } // stk namespace 00115 00116 #endif
The Synthesis ToolKit in C++ (STK) |
©1995-2010 Perry R. Cook and Gary P. Scavone. All Rights Reserved. |