Home   Information   Classes   Download   Usage   Mail List   Requirements   Links   FAQ   Tutorial


SingWave.h

00001 #ifndef STK_SINGWAVE_H
00002 #define STK_SINGWAVE_H
00003 
00004 #include "FileLoop.h"
00005 #include "Modulate.h"
00006 #include "Envelope.h"
00007 
00008 namespace stk {
00009 
00010 /***************************************************/
00023 /***************************************************/
00024 
00025 class SingWave : public Generator
00026 {
00027  public:
00029 
00036   SingWave( std::string fileName, bool raw = false );
00037 
00039   ~SingWave( void );
00040 
00042   void reset( void ) { wave_.reset(); lastFrame_[0] = 0.0; };
00043 
00045   void normalize( void ) { wave_.normalize(); };
00046 
00048   void normalize( StkFloat peak ) { wave_.normalize( peak ); };
00049 
00051   void setFrequency( StkFloat frequency );
00052 
00054   void setVibratoRate( StkFloat rate ) { modulator_.setVibratoRate( rate ); };
00055 
00057   void setVibratoGain( StkFloat gain ) { modulator_.setVibratoGain( gain ); };
00058 
00060   void setRandomGain( StkFloat gain ) { modulator_.setRandomGain( gain ); };
00061 
00063   void setSweepRate( StkFloat rate ) { sweepRate_ = rate; };
00064 
00066   void setGainRate( StkFloat rate ) { envelope_.setRate( rate ); };
00067 
00069   void setGainTarget( StkFloat target ) { envelope_.setTarget( target ); };
00070 
00072   void noteOn( void ) { envelope_.keyOn(); };
00073 
00075   void noteOff( void ) { envelope_.keyOff(); };
00076 
00078   StkFloat lastOut( void ) const { return lastFrame_[0]; };
00079 
00081   StkFloat tick( void );
00082 
00084 
00091   StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
00092 
00093  protected:
00094 
00095   FileLoop wave_;
00096   Modulate modulator_;
00097   Envelope envelope_;
00098   Envelope pitchEnvelope_;
00099   StkFloat rate_;
00100   StkFloat sweepRate_;
00101 
00102 };
00103 
00104 inline StkFloat SingWave :: tick( void )
00105 {
00106   // Set the wave rate.
00107   StkFloat newRate = pitchEnvelope_.tick();
00108   newRate += newRate * modulator_.tick();
00109   wave_.setRate( newRate );
00110 
00111   lastFrame_[0] = wave_.tick();
00112   lastFrame_[0] *= envelope_.tick();
00113 
00114   return lastFrame_[0];
00115 }
00116 
00117 inline StkFrames& SingWave :: tick( StkFrames& frames, unsigned int channel )
00118 {
00119 #if defined(_STK_DEBUG_)
00120   if ( channel >= frames.channels() ) {
00121     oStream_ << "SingWave::tick(): channel and StkFrames arguments are incompatible!";
00122     handleError( StkError::FUNCTION_ARGUMENT );
00123   }
00124 #endif
00125 
00126   StkFloat *samples = &frames[channel];
00127   unsigned int hop = frames.channels();
00128   for ( unsigned int i=0; i<frames.frames(); i++, samples += hop )
00129     *samples = SingWave::tick();
00130 
00131   return frames;
00132 }
00133 
00134 } // stk namespace
00135 
00136 #endif

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