Home Information Classes Download Usage Mail List Requirements Links FAQ Tutorial

# Bowed.h

    00001 #ifndef STK_BOWED_H
    00002 #define STK_BOWED_H
    00003
    00004 #include "Instrmnt.h"
    00005 #include "DelayL.h"
    00006 #include "BowTable.h"
    00007 #include "OnePole.h"
    00008 #include "BiQuad.h"
    00009 #include "SineWave.h"
    00010 #include "ADSR.h"
    00011
    00012 namespace stk {
    00013
    00014 /***************************************************/
    00038 /***************************************************/
    00039
    00040 class Bowed : public Instrmnt
    00041 {
    00042  public:
    00044   Bowed( StkFloat lowestFrequency = 8.0 );
    00045
    00047   ~Bowed( void );
    00048
    00050   void clear( void );
    00051
    00053   void setFrequency( StkFloat frequency );
    00054
    00056   void setVibrato( StkFloat gain ) { vibratoGain_ = gain; };
    00057
    00059   void startBowing( StkFloat amplitude, StkFloat rate );
    00060
    00062   void stopBowing( StkFloat rate );
    00063
    00065   void noteOn( StkFloat frequency, StkFloat amplitude );
    00066
    00068   void noteOff( StkFloat amplitude );
    00069
    00071   void controlChange( int number, StkFloat value );
    00072
    00074   StkFloat tick( unsigned int channel = 0 );
    00075
    00077
    00084   StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
    00085
    00086  protected:
    00087
    00088   DelayL   neckDelay_;
    00089   DelayL   bridgeDelay_;
    00090   BowTable bowTable_;
    00091   OnePole  stringFilter_;
    00092   BiQuad   bodyFilters_[6];
    00093   SineWave vibrato_;
    00094   ADSR     adsr_;
    00095
    00096   bool     bowDown_;
    00097   StkFloat maxVelocity_;
    00098   StkFloat baseDelay_;
    00099   StkFloat vibratoGain_;
    00100   StkFloat betaRatio_;
    00101
    00102 };
    00103
    00104 inline StkFloat Bowed :: tick( unsigned int )
    00105 {
    00106   StkFloat bowVelocity = maxVelocity_ * adsr_.tick();
    00107   StkFloat bridgeReflection = -stringFilter_.tick( bridgeDelay_.lastOut() );
    00108   StkFloat nutReflection = -neckDelay_.lastOut();
    00109   StkFloat stringVelocity = bridgeReflection + nutReflection;
    00110   StkFloat deltaV = bowVelocity - stringVelocity;             // Differential velocity
    00111
    00112   StkFloat newVelocity = 0.0;
    00113   if ( bowDown_ )
    00114     newVelocity = deltaV * bowTable_.tick( deltaV );     // Non-Linear bow function
    00115   neckDelay_.tick( bridgeReflection + newVelocity);      // Do string propagations
    00116   bridgeDelay_.tick(nutReflection + newVelocity);
    00117
    00118   if ( vibratoGain_ > 0.0 )  {
    00119     neckDelay_.setDelay( (baseDelay_ * (1.0 - betaRatio_) ) +
    00120                          (baseDelay_ * vibratoGain_ * vibrato_.tick()) );
    00121   }
    00122
    00123   lastFrame_[0] = 0.1248 * bodyFilters_[5].tick( bodyFilters_[4].tick( bodyFilters_[3].tick( bodyFilters_[2].tick( bodyFilters_[1].tick( bodyFilters_[0].tick( bridgeDelay_.lastOut() ) ) ) ) ) );
    00124
    00125   return lastFrame_[0];
    00126 }
    00127
    00128 inline StkFrames& Bowed :: tick( StkFrames& frames, unsigned int channel )
    00129 {
    00130   unsigned int nChannels = lastFrame_.channels();
    00131 #if defined(_STK_DEBUG_)
    00132   if ( channel > frames.channels() - nChannels ) {
    00133     oStream_ << "Bowed::tick(): channel and StkFrames arguments are incompatible!";
    00134     handleError( StkError::FUNCTION_ARGUMENT );
    00135   }
    00136 #endif
    00137
    00138   StkFloat *samples = &frames[channel];
    00139   unsigned int j, hop = frames.channels() - nChannels;
    00140   if ( nChannels == 1 ) {
    00141     for ( unsigned int i=0; i<frames.frames(); i++, samples += hop )
    00142       *samples++ = tick();
    00143   }
    00144   else {
    00145     for ( unsigned int i=0; i<frames.frames(); i++, samples += hop ) {
    00146       *samples++ = tick();
    00147       for ( j=1; j<nChannels; j++ )
    00148         *samples++ = lastFrame_[j];
    00149     }
    00150   }
    00151
    00152   return frames;
    00153 }
    00154
    00155 } // stk namespace
    00156
    00157 #endif

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