The Synthesis ToolKit in C++ (STK)

Home Information Classes Download Usage Mail List Requirements Links FAQ Tutorial

# Saxofony.h

    00001 #ifndef STK_SAXOFONY_H
    00002 #define STK_SAXOFONY_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 /***************************************************/
    00049 /***************************************************/
    00050
    00051 class Saxofony : public Instrmnt
    00052 {
    00053  public:
    00055
    00058   Saxofony( StkFloat lowestFrequency );
    00059
    00061   ~Saxofony( void );
    00062
    00064   void clear( void );
    00065
    00067   void setFrequency( StkFloat frequency );
    00068
    00070   void setBlowPosition( StkFloat aPosition );
    00071
    00073   void startBlowing( StkFloat amplitude, StkFloat rate );
    00074
    00076   void stopBlowing( StkFloat rate );
    00077
    00079   void noteOn( StkFloat frequency, StkFloat amplitude );
    00080
    00082   void noteOff( StkFloat amplitude );
    00083
    00085   void controlChange( int number, StkFloat value );
    00086
    00088   StkFloat tick( unsigned int channel = 0 );
    00089
    00091
    00098   StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
    00099
    00100  protected:
    00101
    00102   DelayL    delays_[2];
    00103   ReedTable reedTable_;
    00104   OneZero   filter_;
    00105   Envelope  envelope_;
    00106   Noise     noise_;
    00107   SineWave vibrato_;
    00108
    00109   StkFloat outputGain_;
    00110   StkFloat noiseGain_;
    00111   StkFloat vibratoGain_;
    00112   StkFloat position_;
    00113
    00114 };
    00115
    00116 inline StkFloat Saxofony :: tick( unsigned int )
    00117 {
    00118   StkFloat pressureDiff;
    00119   StkFloat breathPressure;
    00120   StkFloat temp;
    00121
    00122   // Calculate the breath pressure (envelope + noise + vibrato)
    00123   breathPressure = envelope_.tick();
    00124   breathPressure += breathPressure * noiseGain_ * noise_.tick();
    00125   breathPressure += breathPressure * vibratoGain_ * vibrato_.tick();
    00126
    00127   temp = -0.95 * filter_.tick( delays_[0].lastOut() );
    00128   lastFrame_[0] = temp - delays_[1].lastOut();
    00129   pressureDiff = breathPressure - lastFrame_[0];
    00130   delays_[1].tick( temp );
    00131   delays_[0].tick( breathPressure - (pressureDiff * reedTable_.tick(pressureDiff)) - temp );
    00132
    00133   lastFrame_[0] *= outputGain_;
    00134   return lastFrame_[0];
    00135 }
    00136
    00137 inline StkFrames& Saxofony :: 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_ << "Saxofony::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.