Home Information Classes Download Usage Mail List Requirements Links FAQ Tutorial

# FMVoices.h

    00001 #ifndef STK_FMVOICES_H
    00002 #define STK_FMVOICES_H
    00003
    00004 #include "FM.h"
    00005
    00006 namespace stk {
    00007
    00008 /***************************************************/
    00038 /***************************************************/
    00039
    00040 class FMVoices : public FM
    00041 {
    00042  public:
    00044
    00047   FMVoices( void );
    00048
    00050   ~FMVoices( void );
    00051
    00053   void setFrequency( StkFloat frequency );
    00054
    00056   void noteOn( StkFloat frequency, StkFloat amplitude );
    00057
    00059   void controlChange( int number, StkFloat value );
    00060
    00062   StkFloat tick( unsigned int channel = 0 );
    00063
    00065
    00072   StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
    00073
    00074  protected:
    00075
    00076   int currentVowel_;
    00077   StkFloat tilt_[3];
    00078   StkFloat mods_[3];
    00079 };
    00080
    00081 inline StkFloat FMVoices :: tick( unsigned int )
    00082 {
    00083   register StkFloat temp, temp2;
    00084
    00085   temp = gains_[3] * adsr_[3]->tick() * waves_[3]->tick();
    00086   temp2 = vibrato_.tick() * modDepth_ * 0.1;
    00087
    00088   waves_[0]->setFrequency(baseFrequency_ * (1.0 + temp2) * ratios_[0]);
    00089   waves_[1]->setFrequency(baseFrequency_ * (1.0 + temp2) * ratios_[1]);
    00090   waves_[2]->setFrequency(baseFrequency_ * (1.0 + temp2) * ratios_[2]);
    00091   waves_[3]->setFrequency(baseFrequency_ * (1.0 + temp2) * ratios_[3]);
    00092
    00093   waves_[0]->addPhaseOffset(temp * mods_[0]);
    00094   waves_[1]->addPhaseOffset(temp * mods_[1]);
    00095   waves_[2]->addPhaseOffset(temp * mods_[2]);
    00096   waves_[3]->addPhaseOffset( twozero_.lastOut() );
    00097   twozero_.tick( temp );
    00098   temp =  gains_[0] * tilt_[0] * adsr_[0]->tick() * waves_[0]->tick();
    00099   temp += gains_[1] * tilt_[1] * adsr_[1]->tick() * waves_[1]->tick();
    00100   temp += gains_[2] * tilt_[2] * adsr_[2]->tick() * waves_[2]->tick();
    00101
    00102   lastFrame_[0] = temp * 0.33;
    00103   return lastFrame_[0];
    00104 }
    00105
    00106 inline StkFrames& FMVoices :: tick( StkFrames& frames, unsigned int channel )
    00107 {
    00108   unsigned int nChannels = lastFrame_.channels();
    00109 #if defined(_STK_DEBUG_)
    00110   if ( channel > frames.channels() - nChannels ) {
    00111     oStream_ << "FMVoices::tick(): channel and StkFrames arguments are incompatible!";
    00112     handleError( StkError::FUNCTION_ARGUMENT );
    00113   }
    00114 #endif
    00115
    00116   StkFloat *samples = &frames[channel];
    00117   unsigned int j, hop = frames.channels() - nChannels;
    00118   if ( nChannels == 1 ) {
    00119     for ( unsigned int i=0; i<frames.frames(); i++, samples += hop )
    00120       *samples++ = tick();
    00121   }
    00122   else {
    00123     for ( unsigned int i=0; i<frames.frames(); i++, samples += hop ) {
    00124       *samples++ = tick();
    00125       for ( j=1; j<nChannels; j++ )
    00126         *samples++ = lastFrame_[j];
    00127     }
    00128   }
    00129
    00130   return frames;
    00131 }
    00132
    00133 } // stk namespace
    00134
    00135 #endif

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