Home   Information   Classes   Download   Usage   Mail List   Requirements   Links   FAQ   Tutorial


HevyMetl.h

00001 #ifndef STK_HEVYMETL_H
00002 #define STK_HEVYMETL_H
00003 
00004 #include "FM.h"
00005 
00006 namespace stk {
00007 
00008 /***************************************************/
00036 /***************************************************/
00037 
00038 class HevyMetl : public FM
00039 {
00040  public:
00042 
00045   HevyMetl( void );
00046 
00048   ~HevyMetl( void );
00049 
00051   void noteOn( StkFloat frequency, StkFloat amplitude );
00052 
00054   StkFloat tick( unsigned int channel = 0 );
00055 
00057 
00064   StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
00065 
00066  protected:
00067 
00068 };
00069 
00070 inline StkFloat HevyMetl :: tick( unsigned int )
00071 {
00072   register StkFloat temp;
00073 
00074   temp = vibrato_.tick() * modDepth_ * 0.2;    
00075   waves_[0]->setFrequency(baseFrequency_ * (1.0 + temp) * ratios_[0]);
00076   waves_[1]->setFrequency(baseFrequency_ * (1.0 + temp) * ratios_[1]);
00077   waves_[2]->setFrequency(baseFrequency_ * (1.0 + temp) * ratios_[2]);
00078   waves_[3]->setFrequency(baseFrequency_ * (1.0 + temp) * ratios_[3]);
00079     
00080   temp = gains_[2] * adsr_[2]->tick() * waves_[2]->tick();
00081   waves_[1]->addPhaseOffset( temp );
00082     
00083   waves_[3]->addPhaseOffset( twozero_.lastOut() );
00084   temp = (1.0 - (control2_ * 0.5)) * gains_[3] * adsr_[3]->tick() * waves_[3]->tick();
00085   twozero_.tick(temp);
00086     
00087   temp += control2_ * 0.5 * gains_[1] * adsr_[1]->tick() * waves_[1]->tick();
00088   temp = temp * control1_;
00089     
00090   waves_[0]->addPhaseOffset( temp );
00091   temp = gains_[0] * adsr_[0]->tick() * waves_[0]->tick();
00092     
00093   lastFrame_[0] = temp * 0.5;
00094   return lastFrame_[0];
00095 }
00096 
00097 inline StkFrames& HevyMetl :: tick( StkFrames& frames, unsigned int channel )
00098 {
00099   unsigned int nChannels = lastFrame_.channels();
00100 #if defined(_STK_DEBUG_)
00101   if ( channel > frames.channels() - nChannels ) {
00102     oStream_ << "HevyMetl::tick(): channel and StkFrames arguments are incompatible!";
00103     handleError( StkError::FUNCTION_ARGUMENT );
00104   }
00105 #endif
00106 
00107   StkFloat *samples = &frames[channel];
00108   unsigned int j, hop = frames.channels() - nChannels;
00109   if ( nChannels == 1 ) {
00110     for ( unsigned int i=0; i<frames.frames(); i++, samples += hop )
00111       *samples++ = tick();
00112   }
00113   else {
00114     for ( unsigned int i=0; i<frames.frames(); i++, samples += hop ) {
00115       *samples++ = tick();
00116       for ( j=1; j<nChannels; j++ )
00117         *samples++ = lastFrame_[j];
00118     }
00119   }
00120 
00121   return frames;
00122 }
00123 
00124 } // stk namespace
00125 
00126 #endif

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