The Synthesis ToolKit in C++ (STK)

Home Information Classes Download Usage Mail List Requirements Links FAQ Tutorial

# JetTable.h

    00001 #ifndef STK_JETTABL_H
    00002 #define STK_JETTABL_H
    00003
    00004 #include "Function.h"
    00005
    00006 namespace stk {
    00007
    00008 /***************************************************/
    00021 /***************************************************/
    00022
    00023 class JetTable : public Function
    00024 {
    00025 public:
    00026
    00028   StkFloat tick( StkFloat input );
    00029
    00031
    00039   StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
    00040
    00042
    00050   StkFrames& tick( StkFrames& iFrames, StkFrames &oFrames, unsigned int iChannel = 0, unsigned int oChannel = 0 );
    00051
    00052 };
    00053
    00054 inline StkFloat JetTable :: tick( StkFloat input )
    00055 {
    00056   // Perform "table lookup" using a polynomial
    00057   // calculation (x^3 - x), which approximates
    00058   // the jet sigmoid behavior.
    00059   lastFrame_[0] = input * (input * input - 1.0);
    00060
    00061   // Saturate at +/- 1.0.
    00062   if ( lastFrame_[0] > 1.0 ) lastFrame_[0] = 1.0;
    00063   if ( lastFrame_[0] < -1.0 ) lastFrame_[0] = -1.0;
    00064   return lastFrame_[0];
    00065 }
    00066
    00067 inline StkFrames& JetTable :: tick( StkFrames& frames, unsigned int channel )
    00068 {
    00069 #if defined(_STK_DEBUG_)
    00070   if ( channel >= frames.channels() ) {
    00071     oStream_ << "JetTable::tick(): channel and StkFrames arguments are incompatible!";
    00072     handleError( StkError::FUNCTION_ARGUMENT );
    00073   }
    00074 #endif
    00075
    00076   StkFloat *samples = &frames[channel];
    00077   unsigned int hop = frames.channels();
    00078   for ( unsigned int i=0; i<frames.frames(); i++, samples += hop ) {
    00079     *samples = *samples * (*samples * *samples - 1.0);
    00080     if ( *samples > 1.0) *samples = 1.0;
    00081     if ( *samples < -1.0) *samples = -1.0;
    00082   }
    00083
    00084   lastFrame_[0] = *(samples-hop);
    00085   return frames;
    00086 }
    00087
    00088 inline StkFrames& JetTable :: tick( StkFrames& iFrames, StkFrames& oFrames, unsigned int iChannel, unsigned int oChannel )
    00089 {
    00090 #if defined(_STK_DEBUG_)
    00091   if ( iChannel >= iFrames.channels() || oChannel >= oFrames.channels() ) {
    00092     oStream_ << "JetTable::tick(): channel and StkFrames arguments are incompatible!";
    00093     handleError( StkError::FUNCTION_ARGUMENT );
    00094   }
    00095 #endif
    00096
    00097   StkFloat *iSamples = &iFrames[iChannel];
    00098   StkFloat *oSamples = &oFrames[oChannel];
    00099   unsigned int iHop = iFrames.channels(), oHop = oFrames.channels();
    00100   for ( unsigned int i=0; i<iFrames.frames(); i++, iSamples += iHop, oSamples += oHop ) {
    00101     *oSamples = *oSamples * (*oSamples * *oSamples - 1.0);
    00102     if ( *oSamples > 1.0) *oSamples = 1.0;
    00103     if ( *oSamples < -1.0) *oSamples = -1.0;
    00104   }
    00105
    00106   lastFrame_[0] = *(oSamples-oHop);
    00107   return iFrames;
    00108 }
    00109
    00110 } // stk namespace
    00111
    00112 #endif

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