Home Information Classes Download Usage Mail List Requirements Links FAQ Tutorial

# Flute.h

    00001 #ifndef STK_FLUTE_H
    00002 #define STK_FLUTE_H
    00003
    00004 #include "Instrmnt.h"
    00005 #include "JetTable.h"
    00006 #include "DelayL.h"
    00007 #include "OnePole.h"
    00008 #include "PoleZero.h"
    00009 #include "Noise.h"
    00010 #include "ADSR.h"
    00011 #include "SineWave.h"
    00012
    00013 namespace stk {
    00014
    00015 /***************************************************/
    00037 /***************************************************/
    00038
    00039 class Flute : public Instrmnt
    00040 {
    00041  public:
    00043
    00046   Flute( StkFloat lowestFrequency );
    00047
    00049   ~Flute( void );
    00050
    00052   void clear( void );
    00053
    00055   void setFrequency( StkFloat frequency );
    00056
    00058   void setJetReflection( StkFloat coefficient ) { jetReflection_ = coefficient; };
    00059
    00061   void setEndReflection( StkFloat coefficient ) { endReflection_ = coefficient; };
    00062
    00064   void setJetDelay( StkFloat aRatio );
    00065
    00067   void startBlowing( StkFloat amplitude, StkFloat rate );
    00068
    00070   void stopBlowing( StkFloat rate );
    00071
    00073   void noteOn( StkFloat frequency, StkFloat amplitude );
    00074
    00076   void noteOff( StkFloat amplitude );
    00077
    00079   void controlChange( int number, StkFloat value );
    00080
    00082   StkFloat tick( unsigned int channel = 0 );
    00083
    00085
    00092   StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
    00093
    00094  protected:
    00095
    00096   DelayL   jetDelay_;
    00097   DelayL   boreDelay_;
    00098   JetTable jetTable_;
    00099   OnePole  filter_;
    00100   PoleZero dcBlock_;
    00101   Noise    noise_;
    00102   ADSR     adsr_;
    00103   SineWave vibrato_;
    00104
    00105   StkFloat lastFrequency_;
    00106   StkFloat maxPressure_;
    00107   StkFloat jetReflection_;
    00108   StkFloat endReflection_;
    00109   StkFloat noiseGain_;
    00110   StkFloat vibratoGain_;
    00111   StkFloat outputGain_;
    00112   StkFloat jetRatio_;
    00113
    00114 };
    00115
    00116 inline StkFloat Flute :: tick( unsigned int )
    00117 {
    00118   StkFloat pressureDiff;
    00119   StkFloat breathPressure;
    00120
    00121   // Calculate the breath pressure (envelope + noise + vibrato)
    00122   breathPressure = maxPressure_ * adsr_.tick();
    00123   breathPressure += breathPressure * ( noiseGain_ * noise_.tick() + vibratoGain_ * vibrato_.tick() );
    00124
    00125   StkFloat temp = -filter_.tick( boreDelay_.lastOut() );
    00126   temp = dcBlock_.tick( temp ); // Block DC on reflection.
    00127
    00128   pressureDiff = breathPressure - (jetReflection_ * temp);
    00129   pressureDiff = jetDelay_.tick( pressureDiff );
    00130   pressureDiff = jetTable_.tick( pressureDiff ) + (endReflection_ * temp);
    00131   lastFrame_[0] = (StkFloat) 0.3 * boreDelay_.tick( pressureDiff );
    00132
    00133   lastFrame_[0] *= outputGain_;
    00134   return lastFrame_[0];
    00135 }
    00136
    00137 inline StkFrames& Flute :: tick( StkFrames& frames, unsigned int channel )
    00138 {
    00139   unsigned int nChannels = lastFrame_.channels();
    00140 #if defined(_STK_DEBUG_)
    00141   if ( channel > frames.channels() - nChannels ) {
    00142     oStream_ << "Flute::tick(): channel and StkFrames arguments are incompatible!";
    00143     handleError( StkError::FUNCTION_ARGUMENT );
    00144   }
    00145 #endif
    00146
    00147   StkFloat *samples = &frames[channel];
    00148   unsigned int j, hop = frames.channels() - nChannels;
    00149   if ( nChannels == 1 ) {
    00150     for ( unsigned int i=0; i<frames.frames(); i++, samples += hop )
    00151       *samples++ = tick();
    00152   }
    00153   else {
    00154     for ( unsigned int i=0; i<frames.frames(); i++, samples += hop ) {
    00155       *samples++ = tick();
    00156       for ( j=1; j<nChannels; j++ )
    00157         *samples++ = lastFrame_[j];
    00158     }
    00159   }
    00160
    00161   return frames;
    00162 }
    00163
    00164 } // stk namespace
    00165
    00166 #endif

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