Home Information Classes Download Usage Mail List Requirements Links FAQ Tutorial

# TubeBell.h

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

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