Home Information Classes Download Usage Mail List Requirements Links FAQ Tutorial

# ReedTable.h

    00001 #ifndef STK_REEDTABLE_H
    00002 #define STK_REEDTABLE_H
    00003
    00004 #include "Function.h"
    00005
    00006 namespace stk {
    00007
    00008 /***************************************************/
    00025 /***************************************************/
    00026
    00027 class ReedTable : public Function
    00028 {
    00029 public:
    00031   ReedTable( void ) : offset_(0.6), slope_(-0.8) {};
    00032
    00034
    00039   void setOffset( StkFloat offset ) { offset_ = offset; };
    00040
    00042
    00047   void setSlope( StkFloat slope ) { slope_ = slope; };
    00048
    00050   StkFloat tick( StkFloat input );
    00051
    00053
    00061   StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
    00062
    00064
    00072   StkFrames& tick( StkFrames& iFrames, StkFrames &oFrames, unsigned int iChannel = 0, unsigned int oChannel = 0 );
    00073
    00074 protected:
    00075
    00076   StkFloat offset_;
    00077   StkFloat slope_;
    00078
    00079 };
    00080
    00081 inline StkFloat ReedTable :: tick( StkFloat input )
    00082 {
    00083   // The input is differential pressure across the reed.
    00084   lastFrame_[0] = offset_ + (slope_ * input);
    00085
    00086   // If output is > 1, the reed has slammed shut and the
    00087   // reflection function value saturates at 1.0.
    00088   if ( lastFrame_[0] > 1.0) lastFrame_[0] = (StkFloat) 1.0;
    00089
    00090   // This is nearly impossible in a physical system, but
    00091   // a reflection function value of -1.0 corresponds to
    00092   // an open end (and no discontinuity in bore profile).
    00093   if ( lastFrame_[0] < -1.0) lastFrame_[0] = (StkFloat) -1.0;
    00094
    00095   return lastFrame_[0];
    00096 }
    00097
    00098 inline StkFrames& ReedTable :: tick( StkFrames& frames, unsigned int channel )
    00099 {
    00100 #if defined(_STK_DEBUG_)
    00101   if ( channel >= frames.channels() ) {
    00102     errorString_ << "ReedTable::tick(): channel and StkFrames arguments are incompatible!";
    00103     handleError( StkError::FUNCTION_ARGUMENT );
    00104   }
    00105 #endif
    00106
    00107   StkFloat *samples = &frames[channel];
    00108   unsigned int hop = frames.channels();
    00109   for ( unsigned int i=0; i<frames.frames(); i++, samples += hop ) {
    00110     *samples = offset_ + (slope_ * *samples);
    00111     if ( *samples > 1.0) *samples = 1.0;
    00112     if ( *samples < -1.0) *samples = -1.0;
    00113   }
    00114
    00115   lastFrame_[0] = *(samples-hop);
    00116   return frames;
    00117 }
    00118
    00119 inline StkFrames& ReedTable :: tick( StkFrames& iFrames, StkFrames& oFrames, unsigned int iChannel, unsigned int oChannel )
    00120 {
    00121 #if defined(_STK_DEBUG_)
    00122   if ( iChannel >= iFrames.channels() || oChannel >= oFrames.channels() ) {
    00123     errorString_ << "ReedTable::tick(): channel and StkFrames arguments are incompatible!";
    00124     handleError( StkError::FUNCTION_ARGUMENT );
    00125   }
    00126 #endif
    00127
    00128   StkFloat *iSamples = &iFrames[iChannel];
    00129   StkFloat *oSamples = &oFrames[oChannel];
    00130   unsigned int iHop = iFrames.channels(), oHop = oFrames.channels();
    00131   for ( unsigned int i=0; i<iFrames.frames(); i++, iSamples += iHop, oSamples += oHop ) {
    00132     *oSamples = offset_ + (slope_ * *iSamples);
    00133     if ( *oSamples > 1.0) *oSamples = 1.0;
    00134     if ( *oSamples < -1.0) *oSamples = -1.0;
    00135   }
    00136
    00137   lastFrame_[0] = *(oSamples-oHop);
    00138   return iFrames;
    00139 }
    00140
    00141 } // stk namespace
    00142
    00143 #endif

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