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 setTarget( StkFloat target ); 00065 00067 void setValue( StkFloat value ); 00068 00070 int getState( void ) const { return state_; }; 00071 00073 StkFloat lastOut( void ) const { return lastFrame_[0]; }; 00074 00076 StkFloat tick( void ); 00077 00079 00086 StkFrames& tick( StkFrames& frames, unsigned int channel = 0 ); 00087 00088 protected: 00089 00090 void sampleRateChanged( StkFloat newRate, StkFloat oldRate ); 00091 00092 StkFloat value_; 00093 StkFloat target_; 00094 StkFloat factor_; 00095 StkFloat constant_; 00096 int state_; 00097 }; 00098 00099 inline StkFloat Asymp :: tick( void ) 00100 { 00101 if ( state_ ) { 00102 00103 value_ = factor_ * value_ + constant_; 00104 00105 // Check threshold. 00106 if ( target_ > value_ ) { 00107 if ( target_ - value_ <= TARGET_THRESHOLD ) { 00108 value_ = target_; 00109 state_ = 0; 00110 } 00111 } 00112 else { 00113 if ( value_ - target_ <= TARGET_THRESHOLD ) { 00114 value_ = target_; 00115 state_ = 0; 00116 } 00117 } 00118 lastFrame_[0] = value_; 00119 } 00120 00121 return value_; 00122 } 00123 00124 inline StkFrames& Asymp :: tick( StkFrames& frames, unsigned int channel ) 00125 { 00126 #if defined(_STK_DEBUG_) 00127 if ( channel >= frames.channels() ) { 00128 errorString_ << "Asymp::tick(): channel and StkFrames arguments are incompatible!"; 00129 handleError( StkError::FUNCTION_ARGUMENT ); 00130 } 00131 #endif 00132 00133 StkFloat *samples = &frames[channel]; 00134 unsigned int hop = frames.channels(); 00135 for ( unsigned int i=0; i<frames.frames(); i++, samples += hop ) 00136 *samples = Asymp::tick(); 00137 00138 return frames; 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. |