Home Information Classes Download Usage Mail List Requirements Links FAQ Tutorial
00001 #ifndef STK_WURLEY_H 00002 #define STK_WURLEY_H 00003 00004 #include "FM.h" 00005 00006 namespace stk { 00007 00008 /***************************************************/ 00038 /***************************************************/ 00039 00040 class Wurley : public FM 00041 { 00042 public: 00044 00047 Wurley( void ); 00048 00050 ~Wurley( void ); 00051 00053 void setFrequency( StkFloat frequency ); 00054 00056 void noteOn( StkFloat frequency, StkFloat amplitude ); 00057 00059 StkFloat tick( unsigned int channel = 0 ); 00060 00062 00069 StkFrames& tick( StkFrames& frames, unsigned int channel = 0 ); 00070 00071 protected: 00072 00073 }; 00074 00075 inline StkFloat Wurley :: tick( unsigned int ) 00076 { 00077 StkFloat temp, temp2; 00078 00079 temp = gains_[1] * adsr_[1]->tick() * waves_[1]->tick(); 00080 temp = temp * control1_; 00081 00082 waves_[0]->addPhaseOffset( temp ); 00083 waves_[3]->addPhaseOffset( twozero_.lastOut() ); 00084 temp = gains_[3] * adsr_[3]->tick() * waves_[3]->tick(); 00085 twozero_.tick(temp); 00086 00087 waves_[2]->addPhaseOffset( temp ); 00088 temp = ( 1.0 - (control2_ * 0.5)) * gains_[0] * adsr_[0]->tick() * waves_[0]->tick(); 00089 temp += control2_ * 0.5 * gains_[2] * adsr_[2]->tick() * waves_[2]->tick(); 00090 00091 // Calculate amplitude modulation and apply it to output. 00092 temp2 = vibrato_.tick() * modDepth_; 00093 temp = temp * (1.0 + temp2); 00094 00095 lastFrame_[0] = temp * 0.5; 00096 return lastFrame_[0]; 00097 } 00098 00099 inline StkFrames& Wurley :: tick( StkFrames& frames, unsigned int channel ) 00100 { 00101 unsigned int nChannels = lastFrame_.channels(); 00102 #if defined(_STK_DEBUG_) 00103 if ( channel > frames.channels() - nChannels ) { 00104 oStream_ << "Wurley::tick(): channel and StkFrames arguments are incompatible!"; 00105 handleError( StkError::FUNCTION_ARGUMENT ); 00106 } 00107 #endif 00108 00109 StkFloat *samples = &frames[channel]; 00110 unsigned int j, hop = frames.channels() - nChannels; 00111 if ( nChannels == 1 ) { 00112 for ( unsigned int i=0; i<frames.frames(); i++, samples += hop ) 00113 *samples++ = tick(); 00114 } 00115 else { 00116 for ( unsigned int i=0; i<frames.frames(); i++, samples += hop ) { 00117 *samples++ = tick(); 00118 for ( j=1; j<nChannels; j++ ) 00119 *samples++ = lastFrame_[j]; 00120 } 00121 } 00122 00123 return frames; 00124 } 00125 00126 } // stk namespace 00127 00128 #endif
The Synthesis ToolKit in C++ (STK) |
©1995-2012 Perry R. Cook and Gary P. Scavone. All Rights Reserved. |