Home Information Classes Download Usage Mail List Requirements Links FAQ Tutorial

Asymp.h
1 #ifndef STK_ASYMP_H
2 #define STK_ASYMP_H
3
4 #include "Generator.h"
5
6 namespace stk {
7
8 /***************************************************/
31 /***************************************************/
32
33 const StkFloat TARGET_THRESHOLD = 0.000001;
34
35 class Asymp : public Generator
36 {
37 public:
38
40 Asymp( void );
41
43 ~Asymp( void );
44
46 void keyOn( void );
47
49 void keyOff( void );
50
52
58 void setTau( StkFloat tau );
59
61 void setTime( StkFloat time );
62
64 void setT60( StkFloat t60 );
65
67 void setTarget( StkFloat target );
68
70 void setValue( StkFloat value );
71
73 int getState( void ) const { return state_; };
74
76 StkFloat lastOut( void ) const { return lastFrame_[0]; };
77
79 StkFloat tick( void );
80
82
89 StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
90
91 protected:
92
93 void sampleRateChanged( StkFloat newRate, StkFloat oldRate );
94
95 StkFloat value_;
96 StkFloat target_;
97 StkFloat factor_;
98 StkFloat constant_;
99 int state_;
100 };
101
102 inline StkFloat Asymp :: tick( void )
103 {
104 if ( state_ ) {
105
106 value_ = factor_ * value_ + constant_;
107
108 // Check threshold.
109 if ( target_ > value_ ) {
110 if ( target_ - value_ <= TARGET_THRESHOLD ) {
111 value_ = target_;
112 state_ = 0;
113 }
114 }
115 else {
116 if ( value_ - target_ <= TARGET_THRESHOLD ) {
117 value_ = target_;
118 state_ = 0;
119 }
120 }
121 lastFrame_[0] = value_;
122 }
123
124 return value_;
125 }
126
127 inline StkFrames& Asymp :: tick( StkFrames& frames, unsigned int channel )
128 {
129 #if defined(_STK_DEBUG_)
130 if ( channel >= frames.channels() ) {
131 oStream_ << "Asymp::tick(): channel and StkFrames arguments are incompatible!";
132 handleError( StkError::FUNCTION_ARGUMENT );
133 }
134 #endif
135
136 StkFloat *samples = &frames[channel];
137 unsigned int hop = frames.channels();
138 for ( unsigned int i=0; i<frames.frames(); i++, samples += hop )
139 *samples = Asymp::tick();
140
141 return frames;
142 }
143
144 } // stk namespace
145
146 #endif

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