The Synthesis ToolKit in C++ (STK)

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
6namespace stk {
7
8/***************************************************/
31/***************************************************/
32
33const 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
stk::Asymp
STK asymptotic curve envelope class.
Definition Asymp.h:36
stk::Asymp::keyOff
void keyOff(void)
Set target = 0.
stk::Asymp::keyOn
void keyOn(void)
Set target = 1.
stk::Asymp::tick
StkFloat tick(void)
Compute and return one output sample.
Definition Asymp.h:102
stk::Asymp::setTarget
void setTarget(StkFloat target)
Set the target value.
stk::Asymp::setValue
void setValue(StkFloat value)
Set current and target values to value.
stk::Asymp::lastOut
StkFloat lastOut(void) const
Return the last computed output value.
Definition Asymp.h:76
stk::Asymp::getState
int getState(void) const
Return the current envelope state (0 = at target, 1 otherwise).
Definition Asymp.h:73
stk::Asymp::setTime
void setTime(StkFloat time)
Set the asymptotic rate based on a time duration (must be > 0).
stk::Asymp::~Asymp
~Asymp(void)
Class destructor.
stk::Asymp::Asymp
Asymp(void)
Default constructor.
stk::Asymp::setTau
void setTau(StkFloat tau)
Set the asymptotic rate via the time factor tau (must be > 0).
stk::Asymp::setT60
void setT60(StkFloat t60)
Set the asymptotic rate such that the target value is perceptually reached (to within -60dB of the ta...
stk::Generator
STK abstract unit generator parent class.
Definition Generator.h:21
stk::StkFrames
An STK class to handle vectorized audio data.
Definition Stk.h:279
stk::StkFrames::channels
unsigned int channels(void) const
Return the number of channels represented by the data.
Definition Stk.h:416
stk::StkFrames::frames
unsigned int frames(void) const
Return the number of sample frames represented by the data.
Definition Stk.h:419
stk
The STK namespace.
Definition ADSR.h:6

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