Home Information Classes Download Usage Mail List Requirements Links FAQ Tutorial

# Modal.h

    00001 #ifndef STK_MODAL_H
    00002 #define STK_MODAL_H
    00003
    00004 #include "Instrmnt.h"
    00005 #include "Envelope.h"
    00006 #include "FileLoop.h"
    00007 #include "SineWave.h"
    00008 #include "BiQuad.h"
    00009 #include "OnePole.h"
    00010
    00011 namespace stk {
    00012
    00013 /***************************************************/
    00024 /***************************************************/
    00025
    00026 class Modal : public Instrmnt
    00027 {
    00028 public:
    00030
    00033   Modal( unsigned int modes = 4 );
    00034
    00036   virtual ~Modal( void );
    00037
    00039   void clear( void );
    00040
    00042   virtual void setFrequency( StkFloat frequency );
    00043
    00045   void setRatioAndRadius( unsigned int modeIndex, StkFloat ratio, StkFloat radius );
    00046
    00048   void setMasterGain( StkFloat aGain ) { masterGain_ = aGain; };
    00049
    00051   void setDirectGain( StkFloat aGain ) { directGain_ = aGain; };
    00052
    00054   void setModeGain( unsigned int modeIndex, StkFloat gain );
    00055
    00057   virtual void strike( StkFloat amplitude );
    00058
    00060   void damp( StkFloat amplitude );
    00061
    00063   void noteOn( StkFloat frequency, StkFloat amplitude );
    00064
    00066   void noteOff( StkFloat amplitude );
    00067
    00069   virtual void controlChange( int number, StkFloat value ) = 0;
    00070
    00072   StkFloat tick( unsigned int channel = 0 );
    00073
    00074 protected:
    00075
    00076   Envelope envelope_;
    00077   FileWvIn *wave_;
    00078   BiQuad **filters_;
    00079   OnePole  onepole_;
    00080   SineWave vibrato_;
    00081
    00082   unsigned int nModes_;
    00083   std::vector<StkFloat> ratios_;
    00084   std::vector<StkFloat> radii_;
    00085
    00086   StkFloat vibratoGain_;
    00087   StkFloat masterGain_;
    00088   StkFloat directGain_;
    00089   StkFloat stickHardness_;
    00090   StkFloat strikePosition_;
    00091   StkFloat baseFrequency_;
    00092 };
    00093
    00094 inline StkFloat Modal :: tick( unsigned int )
    00095 {
    00096   StkFloat temp = masterGain_ * onepole_.tick( wave_->tick() * envelope_.tick() );
    00097
    00098   StkFloat temp2 = 0.0;
    00099   for ( unsigned int i=0; i<nModes_; i++ )
    00100     temp2 += filters_[i]->tick(temp);
    00101
    00102   temp2  -= temp2 * directGain_;
    00103   temp2 += directGain_ * temp;
    00104
    00105   if ( vibratoGain_ != 0.0 ) {
    00106     // Calculate AM and apply to master out
    00107     temp = 1.0 + ( vibrato_.tick() * vibratoGain_ );
    00108     temp2 = temp * temp2;
    00109   }
    00110
    00111   lastFrame_[0] = temp2;
    00112   return lastFrame_[0];
    00113 }
    00114
    00115 } // stk namespace
    00116
    00117 #endif

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