The Synthesis ToolKit in C++ (STK)

Home Information Classes Download Usage Mail List Requirements Links FAQ Tutorial

# Modulate.h

    00001 #ifndef STK_MODULATE_H
    00002 #define STK_MODULATE_H
    00003
    00004 #include "Generator.h"
    00005 #include "SineWave.h"
    00006 #include "Noise.h"
    00007 #include "OnePole.h"
    00008
    00009 namespace stk {
    00010
    00011 /***************************************************/
    00021 /***************************************************/
    00022
    00023 class Modulate : public Generator
    00024 {
    00025  public:
    00027
    00030   Modulate( void );
    00031
    00033   ~Modulate( void );
    00034
    00036   void reset( void ) { lastFrame_[0] = 0.0; };
    00037
    00039   void setVibratoRate( StkFloat rate ) { vibrato_.setFrequency( rate ); };
    00040
    00042   void setVibratoGain( StkFloat gain ) { vibratoGain_ = gain; };
    00043
    00045   void setRandomGain( StkFloat gain );
    00046
    00048   StkFloat lastOut( void ) const { return lastFrame_[0]; };
    00049
    00051   StkFloat tick( void );
    00052
    00054
    00061   StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
    00062
    00063  protected:
    00064
    00065   void sampleRateChanged( StkFloat newRate, StkFloat oldRate );
    00066
    00067   SineWave vibrato_;
    00068   Noise noise_;
    00069   OnePole  filter_;
    00070   StkFloat vibratoGain_;
    00071   StkFloat randomGain_;
    00072   unsigned int noiseRate_;
    00073   unsigned int noiseCounter_;
    00074
    00075 };
    00076
    00077 inline StkFloat Modulate :: tick( void )
    00078 {
    00079   // Compute periodic and random modulations.
    00080   lastFrame_[0] = vibratoGain_ * vibrato_.tick();
    00081   if ( noiseCounter_++ >= noiseRate_ ) {
    00082     noise_.tick();
    00083     noiseCounter_ = 0;
    00084   }
    00085   lastFrame_[0] += filter_.tick( noise_.lastOut() );
    00086   return lastFrame_[0];
    00087 }
    00088
    00089 inline StkFrames& Modulate :: tick( StkFrames& frames, unsigned int channel )
    00090 {
    00091 #if defined(_STK_DEBUG_)
    00092   if ( channel >= frames.channels() ) {
    00093     oStream_ << "Modulate::tick(): channel and StkFrames arguments are incompatible!";
    00094     handleError( StkError::FUNCTION_ARGUMENT );
    00095   }
    00096 #endif
    00097
    00098   StkFloat *samples = &frames[channel];
    00099   unsigned int hop = frames.channels();
    00100   for ( unsigned int i=0; i<frames.frames(); i++, samples += hop )
    00101     *samples = Modulate::tick();
    00102
    00103   return frames;
    00104 }
    00105
    00106 } // stk namespace
    00107
    00108 #endif

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