Home Information Classes Download Usage Mail List Requirements Links FAQ Tutorial
00001 #ifndef STK_ASYMP_H 00002 #define STK_ASYMP_H 00003 00004 #include "Generator.h" 00005 00006 namespace stk { 00007 00008 /***************************************************/ 00031 /***************************************************/ 00032 00033 const StkFloat TARGET_THRESHOLD = 0.000001; 00034 00035 class Asymp : public Generator 00036 { 00037 public: 00038 00040 Asymp( void ); 00041 00043 ~Asymp( void ); 00044 00046 void keyOn( void ); 00047 00049 void keyOff( void ); 00050 00052 00058 void setTau( StkFloat tau ); 00059 00061 void setTime( StkFloat time ); 00062 00064 void setT60( StkFloat t60 ); 00065 00067 void setTarget( StkFloat target ); 00068 00070 void setValue( StkFloat value ); 00071 00073 int getState( void ) const { return state_; }; 00074 00076 StkFloat lastOut( void ) const { return lastFrame_[0]; }; 00077 00079 StkFloat tick( void ); 00080 00082 00089 StkFrames& tick( StkFrames& frames, unsigned int channel = 0 ); 00090 00091 protected: 00092 00093 void sampleRateChanged( StkFloat newRate, StkFloat oldRate ); 00094 00095 StkFloat value_; 00096 StkFloat target_; 00097 StkFloat factor_; 00098 StkFloat constant_; 00099 int state_; 00100 }; 00101 00102 inline StkFloat Asymp :: tick( void ) 00103 { 00104 if ( state_ ) { 00105 00106 value_ = factor_ * value_ + constant_; 00107 00108 // Check threshold. 00109 if ( target_ > value_ ) { 00110 if ( target_ - value_ <= TARGET_THRESHOLD ) { 00111 value_ = target_; 00112 state_ = 0; 00113 } 00114 } 00115 else { 00116 if ( value_ - target_ <= TARGET_THRESHOLD ) { 00117 value_ = target_; 00118 state_ = 0; 00119 } 00120 } 00121 lastFrame_[0] = value_; 00122 } 00123 00124 return value_; 00125 } 00126 00127 inline StkFrames& Asymp :: tick( StkFrames& frames, unsigned int channel ) 00128 { 00129 #if defined(_STK_DEBUG_) 00130 if ( channel >= frames.channels() ) { 00131 oStream_ << "Asymp::tick(): channel and StkFrames arguments are incompatible!"; 00132 handleError( StkError::FUNCTION_ARGUMENT ); 00133 } 00134 #endif 00135 00136 StkFloat *samples = &frames[channel]; 00137 unsigned int hop = frames.channels(); 00138 for ( unsigned int i=0; i<frames.frames(); i++, samples += hop ) 00139 *samples = Asymp::tick(); 00140 00141 return frames; 00142 } 00143 00144 } // stk namespace 00145 00146 #endif
The Synthesis ToolKit in C++ (STK) |
©1995-2012 Perry R. Cook and Gary P. Scavone. All Rights Reserved. |