74 void setAllTimes( StkFloat aTime, StkFloat dTime, StkFloat sLevel, StkFloat rTime );
86 StkFloat
lastOut(
void )
const {
return lastFrame_[0]; };
89 StkFloat
tick(
void );
103 void sampleRateChanged( StkFloat newRate, StkFloat oldRate );
108 StkFloat attackRate_;
110 StkFloat releaseRate_;
111 StkFloat releaseTime_;
112 StkFloat sustainLevel_;
115inline StkFloat ADSR :: tick(
void )
120 value_ += attackRate_;
121 if ( value_ >= target_ ) {
123 target_ = sustainLevel_;
126 lastFrame_[0] = value_;
130 if ( value_ > sustainLevel_ ) {
131 value_ -= decayRate_;
132 if ( value_ <= sustainLevel_ ) {
133 value_ = sustainLevel_;
138 value_ += decayRate_;
139 if ( value_ >= sustainLevel_ ) {
140 value_ = sustainLevel_;
144 lastFrame_[0] = value_;
148 value_ -= releaseRate_;
149 if ( value_ <= 0.0 ) {
153 lastFrame_[0] = value_;
162#if defined(_STK_DEBUG_)
163 if ( channel >= frames.
channels() ) {
164 oStream_ <<
"ADSR::tick(): channel and StkFrames arguments are incompatible!";
165 handleError( StkError::FUNCTION_ARGUMENT );
169 StkFloat *samples = &frames[channel];
170 unsigned int hop = frames.
channels();
171 for (
unsigned int i=0; i<frames.
frames(); i++, samples += hop )
STK ADSR envelope class.
Definition ADSR.h:25
void setDecayRate(StkFloat rate)
Set the decay rate (gain / sample).
void setReleaseRate(StkFloat rate)
Set the release rate (gain / sample).
void setAllTimes(StkFloat aTime, StkFloat dTime, StkFloat sLevel, StkFloat rTime)
Set sustain level and attack, decay, and release time durations (seconds).
void setTarget(StkFloat target)
Set a sustain target value and attack or decay from current value to target.
void setDecayTime(StkFloat time)
Set the decay rate based on a time duration (seconds).
void setAttackTime(StkFloat time)
Set the attack rate based on a time duration (seconds).
StkFloat lastOut(void) const
Return the last computed output value.
Definition ADSR.h:86
~ADSR(void)
Class destructor.
void setSustainLevel(StkFloat level)
Set the sustain level.
void setReleaseTime(StkFloat time)
Set the release rate based on a time duration (seconds).
void keyOff(void)
Set target = 0, state = ADSR::RELEASE.
void setValue(StkFloat value)
Set to state = ADSR::SUSTAIN with current and target values of value.
void keyOn(void)
Set target = 1, state = ADSR::ATTACK.
ADSR(void)
Default constructor.
void setAttackTarget(StkFloat target)
Set the target value for the attack (default = 1.0).
@ SUSTAIN
Definition ADSR.h:32
@ IDLE
Definition ADSR.h:34
@ DECAY
Definition ADSR.h:31
@ RELEASE
Definition ADSR.h:33
@ ATTACK
Definition ADSR.h:30
StkFloat tick(void)
Compute and return one output sample.
Definition ADSR.h:115
int getState(void) const
Return the current envelope state (ATTACK, DECAY, SUSTAIN, RELEASE, IDLE).
Definition ADSR.h:80
void setAttackRate(StkFloat rate)
Set the attack rate (gain / sample).
STK abstract unit generator parent class.
Definition Generator.h:21
An STK class to handle vectorized audio data.
Definition Stk.h:279
unsigned int channels(void) const
Return the number of channels represented by the data.
Definition Stk.h:416
unsigned int frames(void) const
Return the number of sample frames represented by the data.
Definition Stk.h:419
The STK namespace.
Definition ADSR.h:6