Home Information Classes Download Usage Mail List Requirements Links FAQ Tutorial

# Twang.h

    00001 #ifndef STK_TWANG_H
    00002 #define STK_TWANG_H
    00003
    00004 #include "Stk.h"
    00005 #include "DelayA.h"
    00006 #include "DelayL.h"
    00007 #include "Fir.h"
    00008
    00009 namespace stk {
    00010
    00011 /***************************************************/
    00032 /***************************************************/
    00033
    00034 class Twang : public Stk
    00035 {
    00036  public:
    00038   Twang( StkFloat lowestFrequency = 50.0 );
    00039
    00041   void clear( void );
    00042
    00044   void setLowestFrequency( StkFloat frequency );
    00045
    00047   void setFrequency( StkFloat frequency );
    00048
    00050   void setPluckPosition( StkFloat position );
    00051
    00053
    00059   void setLoopGain( StkFloat loopGain );
    00060
    00062
    00067   void setLoopFilter( std::vector<StkFloat> coefficients );
    00068
    00070   //const StkFrames& lastFrame( void ) const { return lastFrame_; };
    00071
    00073   // StkFloat lastOut( void ) { return lastFrame_[0]; };
    00074   StkFloat lastOut( void ) { return lastOutput_; };
    00075
    00077   StkFloat tick( StkFloat input );
    00078
    00080
    00088   StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
    00089
    00091
    00099   StkFrames& tick( StkFrames& iFrames, StkFrames &oFrames, unsigned int iChannel = 0, unsigned int oChannel = 0 );
    00100
    00101  protected:
    00102
    00103   DelayA   delayLine_;
    00104   DelayL   combDelay_;
    00105   Fir      loopFilter_;
    00106
    00107   StkFloat lastOutput_;
    00108   StkFloat frequency_;
    00109   StkFloat loopGain_;
    00110   StkFloat pluckPosition_;
    00111 };
    00112
    00113 inline StkFloat Twang :: tick( StkFloat input )
    00114 {
    00115   lastOutput_ = delayLine_.tick( input + loopFilter_.tick( delayLine_.lastOut() ) );
    00116   lastOutput_ -= combDelay_.tick( lastOutput_ ); // comb filtering on output
    00117   lastOutput_ *= 0.5;
    00118
    00119   return lastOutput_;
    00120 }
    00121
    00122 inline StkFrames& Twang :: tick( StkFrames& frames, unsigned int channel )
    00123 {
    00124 #if defined(_STK_DEBUG_)
    00125   if ( channel >= frames.channels() ) {
    00126     oStream_ << "Twang::tick(): channel and StkFrames arguments are incompatible!";
    00127     handleError( StkError::FUNCTION_ARGUMENT );
    00128   }
    00129 #endif
    00130
    00131   StkFloat *samples = &frames[channel];
    00132   unsigned int hop = frames.channels();
    00133   for ( unsigned int i=0; i<frames.frames(); i++, samples += hop )
    00134     *samples = tick( *samples );
    00135
    00136   return frames;
    00137 }
    00138
    00139 inline StkFrames& Twang :: tick( StkFrames& iFrames, StkFrames& oFrames, unsigned int iChannel, unsigned int oChannel )
    00140 {
    00141 #if defined(_STK_DEBUG_)
    00142   if ( iChannel >= iFrames.channels() || oChannel >= oFrames.channels() ) {
    00143     oStream_ << "Twang::tick(): channel and StkFrames arguments are incompatible!";
    00144     handleError( StkError::FUNCTION_ARGUMENT );
    00145   }
    00146 #endif
    00147
    00148   StkFloat *iSamples = &iFrames[iChannel];
    00149   StkFloat *oSamples = &oFrames[oChannel];
    00150   unsigned int iHop = iFrames.channels(), oHop = oFrames.channels();
    00151   for ( unsigned int i=0; i<iFrames.frames(); i++, iSamples += iHop, oSamples += oHop )
    00152     *oSamples = tick( *iSamples );
    00153
    00154   return iFrames;
    00155 }
    00156
    00157 } // stk namespace
    00158
    00159 #endif
    00160

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