mirror of
https://github.com/thestk/stk
synced 2026-04-23 07:48:36 +00:00
Version 4.4.3
This commit is contained in:
committed by
Stephen Sinclair
parent
baca57040b
commit
0aec39260a
@@ -11,10 +11,12 @@ namespace stk {
|
||||
|
||||
This class implements a traditional ADSR (Attack, Decay, Sustain,
|
||||
Release) envelope. It responds to simple keyOn and keyOff
|
||||
messages, keeping track of its state. The \e state = ADSR::DONE
|
||||
after the envelope value reaches 0.0 in the ADSR::RELEASE state.
|
||||
messages, keeping track of its state. The \e state = ADSR::IDLE
|
||||
before being triggered and after the envelope value reaches 0.0 in
|
||||
the ADSR::RELEASE state. All rate, target and level settings must
|
||||
be non-negative. All time settings must be positive.
|
||||
|
||||
by Perry R. Cook and Gary P. Scavone, 1995 - 2010.
|
||||
by Perry R. Cook and Gary P. Scavone, 1995-2011.
|
||||
*/
|
||||
/***************************************************/
|
||||
|
||||
@@ -28,7 +30,7 @@ class ADSR : public Generator
|
||||
DECAY, /*!< Decay */
|
||||
SUSTAIN, /*!< Sustain */
|
||||
RELEASE, /*!< Release */
|
||||
DONE /*!< End of release */
|
||||
IDLE /*!< Before attack / after release */
|
||||
};
|
||||
|
||||
//! Default constructor.
|
||||
@@ -46,6 +48,9 @@ class ADSR : public Generator
|
||||
//! Set the attack rate.
|
||||
void setAttackRate( StkFloat rate );
|
||||
|
||||
//! Set the target value for the attack (default = 1.0).
|
||||
void setAttackTarget( StkFloat target );
|
||||
|
||||
//! Set the decay rate.
|
||||
void setDecayRate( StkFloat rate );
|
||||
|
||||
@@ -58,19 +63,19 @@ class ADSR : public Generator
|
||||
//! Set the attack rate based on a time duration.
|
||||
void setAttackTime( StkFloat time );
|
||||
|
||||
//! Set the decay rate based on a time duration.
|
||||
//! Set the decay rate based on a time duration (seconds).
|
||||
void setDecayTime( StkFloat time );
|
||||
|
||||
//! Set the release rate based on a time duration.
|
||||
//! Set the release rate based on a time duration (seconds).
|
||||
void setReleaseTime( StkFloat time );
|
||||
|
||||
//! Set sustain level and attack, decay, and release time durations.
|
||||
void setAllTimes( StkFloat aTime, StkFloat dTime, StkFloat sLevel, StkFloat rTime );
|
||||
|
||||
//! Set the target value.
|
||||
//! Set a sustain target value and attack or decay from current value to target.
|
||||
void setTarget( StkFloat target );
|
||||
|
||||
//! Return the current envelope \e state (ATTACK, DECAY, SUSTAIN, RELEASE, DONE).
|
||||
//! Return the current envelope \e state (ATTACK, DECAY, SUSTAIN, RELEASE, IDLE).
|
||||
int getState( void ) const { return state_; };
|
||||
|
||||
//! Set to state = ADSR::SUSTAIN with current and target values of \e value.
|
||||
@@ -102,6 +107,7 @@ class ADSR : public Generator
|
||||
StkFloat attackRate_;
|
||||
StkFloat decayRate_;
|
||||
StkFloat releaseRate_;
|
||||
StkFloat releaseTime_;
|
||||
StkFloat sustainLevel_;
|
||||
};
|
||||
|
||||
@@ -120,10 +126,19 @@ inline StkFloat ADSR :: tick( void )
|
||||
break;
|
||||
|
||||
case DECAY:
|
||||
value_ -= decayRate_;
|
||||
if ( value_ <= sustainLevel_ ) {
|
||||
value_ = sustainLevel_;
|
||||
state_ = SUSTAIN;
|
||||
if ( value_ > sustainLevel_ ) {
|
||||
value_ -= decayRate_;
|
||||
if ( value_ <= sustainLevel_ ) {
|
||||
value_ = sustainLevel_;
|
||||
state_ = SUSTAIN;
|
||||
}
|
||||
}
|
||||
else {
|
||||
value_ += decayRate_; // attack target < sustain level
|
||||
if ( value_ >= sustainLevel_ ) {
|
||||
value_ = sustainLevel_;
|
||||
state_ = SUSTAIN;
|
||||
}
|
||||
}
|
||||
lastFrame_[0] = value_;
|
||||
break;
|
||||
@@ -131,8 +146,8 @@ inline StkFloat ADSR :: tick( void )
|
||||
case RELEASE:
|
||||
value_ -= releaseRate_;
|
||||
if ( value_ <= 0.0 ) {
|
||||
value_ = (StkFloat) 0.0;
|
||||
state_ = DONE;
|
||||
value_ = 0.0;
|
||||
state_ = IDLE;
|
||||
}
|
||||
lastFrame_[0] = value_;
|
||||
|
||||
@@ -145,7 +160,7 @@ inline StkFrames& ADSR :: tick( StkFrames& frames, unsigned int channel )
|
||||
{
|
||||
#if defined(_STK_DEBUG_)
|
||||
if ( channel >= frames.channels() ) {
|
||||
errorString_ << "ADSR::tick(): channel and StkFrames arguments are incompatible!";
|
||||
oStream_ << "ADSR::tick(): channel and StkFrames arguments are incompatible!";
|
||||
handleError( StkError::FUNCTION_ARGUMENT );
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user