The Synthesis ToolKit in C++ (STK)

Home Information Classes Download Usage Mail List Requirements Links FAQ Tutorial

# BowTable.h

    00001 #ifndef STK_BOWTABL_H
    00002 #define STK_BOWTABL_H
    00003
    00004 #include "Function.h"
    00005 #include <cmath>
    00006
    00007 namespace stk {
    00008
    00009 /***************************************************/
    00020 /***************************************************/
    00021
    00022 class BowTable : public Function
    00023 {
    00024 public:
    00026   BowTable( void ) : offset_(0.0), slope_(0.1), minOutput_(0.01), maxOutput_(0.98) {};
    00027
    00029
    00035   void setOffset( StkFloat offset ) { offset_ = offset; };
    00036
    00038
    00042   void setSlope( StkFloat slope ) { slope_ = slope; };
    00043
    00045   void setMinOutput( StkFloat minimum ) { minOutput_ = minimum; };
    00046
    00048   void setMaxOutput( StkFloat maximum ) { maxOutput_ = maximum; };
    00049
    00051   StkFloat tick( StkFloat input );
    00052
    00054
    00062   StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
    00063
    00065
    00073   StkFrames& tick( StkFrames& iFrames, StkFrames &oFrames, unsigned int iChannel = 0, unsigned int oChannel = 0 );
    00074
    00075 protected:
    00076
    00077   StkFloat offset_;
    00078   StkFloat slope_;
    00079   StkFloat minOutput_;
    00080   StkFloat maxOutput_;
    00081
    00082 };
    00083
    00084 inline StkFloat BowTable :: tick( StkFloat input )
    00085 {
    00086   // The input represents differential string vs. bow velocity.
    00087   StkFloat sample  = input + offset_;  // add bias to input
    00088   sample *= slope_;          // then scale it
    00089   lastFrame_[0] = (StkFloat) fabs( (double) sample ) + (StkFloat) 0.75;
    00090   lastFrame_[0] = (StkFloat) pow( lastFrame_[0], (StkFloat) -4.0 );
    00091
    00092   // Set minimum threshold
    00093   if ( lastFrame_[0] < minOutput_ ) lastFrame_[0] = minOutput_;
    00094
    00095   // Set maximum threshold
    00096   if ( lastFrame_[0] > maxOutput_ ) lastFrame_[0] = maxOutput_;
    00097
    00098   return lastFrame_[0];
    00099 }
    00100
    00101 inline StkFrames& BowTable :: tick( StkFrames& frames, unsigned int channel )
    00102 {
    00103 #if defined(_STK_DEBUG_)
    00104   if ( channel >= frames.channels() ) {
    00105     oStream_ << "BowTable::tick(): channel and StkFrames arguments are incompatible!";
    00106     handleError( StkError::FUNCTION_ARGUMENT );
    00107   }
    00108 #endif
    00109
    00110   StkFloat *samples = &frames[channel];
    00111   unsigned int hop = frames.channels();
    00112   for ( unsigned int i=0; i<frames.frames(); i++, samples += hop ) {
    00113     *samples = *samples + offset_;
    00114     *samples *= slope_;
    00115     *samples = (StkFloat) fabs( (double) *samples ) + 0.75;
    00116     *samples = (StkFloat) pow( *samples, (StkFloat) -4.0 );
    00117     if ( *samples > 1.0) *samples = 1.0;
    00118   }
    00119
    00120   lastFrame_[0] = *(samples-hop);
    00121   return frames;
    00122 }
    00123
    00124 inline StkFrames& BowTable :: tick( StkFrames& iFrames, StkFrames& oFrames, unsigned int iChannel, unsigned int oChannel )
    00125 {
    00126 #if defined(_STK_DEBUG_)
    00127   if ( iChannel >= iFrames.channels() || oChannel >= oFrames.channels() ) {
    00128     oStream_ << "BowTable::tick(): channel and StkFrames arguments are incompatible!";
    00129     handleError( StkError::FUNCTION_ARGUMENT );
    00130   }
    00131 #endif
    00132
    00133   StkFloat *iSamples = &iFrames[iChannel];
    00134   StkFloat *oSamples = &oFrames[oChannel];
    00135   unsigned int iHop = iFrames.channels(), oHop = oFrames.channels();
    00136   for ( unsigned int i=0; i<iFrames.frames(); i++, iSamples += iHop, oSamples += oHop ) {
    00137     *oSamples = *iSamples + offset_;
    00138     *oSamples *= slope_;
    00139     *oSamples = (StkFloat) fabs( (double) *oSamples ) + 0.75;
    00140     *oSamples = (StkFloat) pow( *oSamples, (StkFloat) -4.0 );
    00141     if ( *oSamples > 1.0) *oSamples = 1.0;
    00142   }
    00143
    00144   lastFrame_[0] = *(oSamples-oHop);
    00145   return iFrames;
    00146 }
    00147
    00148 } // stk namespace
    00149
    00150 #endif

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