Home   Information   Classes   Download   Usage   Mail List   Requirements   Links   FAQ   Tutorial


BlowBotl.h

00001 #ifndef STK_BLOWBOTL_H
00002 #define STK_BLOWBOTL_H
00003 
00004 #include "Instrmnt.h"
00005 #include "JetTable.h"
00006 #include "BiQuad.h"
00007 #include "PoleZero.h"
00008 #include "Noise.h"
00009 #include "ADSR.h"
00010 #include "SineWave.h"
00011 
00012 namespace stk {
00013 
00014 /***************************************************/
00030 /***************************************************/
00031 
00032 class BlowBotl : public Instrmnt
00033 {
00034  public:
00036 
00039   BlowBotl( void );
00040 
00042   ~BlowBotl( void );
00043 
00045   void clear( void );
00046 
00048   void setFrequency( StkFloat frequency );
00049 
00051   void startBlowing( StkFloat amplitude, StkFloat rate );
00052 
00054   void stopBlowing( StkFloat rate );
00055 
00057   void noteOn( StkFloat frequency, StkFloat amplitude );
00058 
00060   void noteOff( StkFloat amplitude );
00061 
00063   void controlChange( int number, StkFloat value );
00064 
00066   StkFloat tick( unsigned int channel = 0 );
00067 
00069 
00076   StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
00077 
00078  protected:
00079 
00080   JetTable jetTable_;
00081   BiQuad resonator_;
00082   PoleZero dcBlock_;
00083   Noise noise_;
00084   ADSR adsr_;
00085   SineWave vibrato_;
00086   StkFloat maxPressure_;
00087   StkFloat noiseGain_;
00088   StkFloat vibratoGain_;
00089   StkFloat outputGain_;
00090 
00091 };
00092 
00093 inline StkFloat BlowBotl :: tick( unsigned int )
00094 {
00095   StkFloat breathPressure;
00096   StkFloat randPressure;
00097   StkFloat pressureDiff;
00098 
00099   // Calculate the breath pressure (envelope + vibrato)
00100   breathPressure = maxPressure_ * adsr_.tick();
00101   breathPressure += vibratoGain_ * vibrato_.tick();
00102 
00103   pressureDiff = breathPressure - resonator_.lastOut();
00104 
00105   randPressure = noiseGain_ * noise_.tick();
00106   randPressure *= breathPressure;
00107   randPressure *= (1.0 + pressureDiff);
00108 
00109   resonator_.tick( breathPressure + randPressure - ( jetTable_.tick( pressureDiff ) * pressureDiff ) );
00110   lastFrame_[0] = 0.2 * outputGain_ * dcBlock_.tick( pressureDiff );
00111 
00112   return lastFrame_[0];
00113 }
00114 
00115 inline StkFrames& BlowBotl :: tick( StkFrames& frames, unsigned int channel )
00116 {
00117   unsigned int nChannels = lastFrame_.channels();
00118 #if defined(_STK_DEBUG_)
00119   if ( channel > frames.channels() - nChannels ) {
00120     oStream_ << "BlowBotl::tick(): channel and StkFrames arguments are incompatible!";
00121     handleError( StkError::FUNCTION_ARGUMENT );
00122   }
00123 #endif
00124 
00125   StkFloat *samples = &frames[channel];
00126   unsigned int j, hop = frames.channels() - nChannels;
00127   if ( nChannels == 1 ) {
00128     for ( unsigned int i=0; i<frames.frames(); i++, samples += hop )
00129       *samples++ = tick();
00130   }
00131   else {
00132     for ( unsigned int i=0; i<frames.frames(); i++, samples += hop ) {
00133       *samples++ = tick();
00134       for ( j=1; j<nChannels; j++ )
00135         *samples++ = lastFrame_[j];
00136     }
00137   }
00138 
00139   return frames;
00140 }
00141 
00142 } // stk namespace
00143 
00144 #endif

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