Version 4.4.0

This commit is contained in:
Gary Scavone
2013-09-29 23:11:39 +02:00
committed by Stephen Sinclair
parent d199342e86
commit eccd8c9981
287 changed files with 11712 additions and 7676 deletions

View File

@@ -2,33 +2,32 @@
/*! \class ADSR
\brief STK ADSR envelope class.
This Envelope subclass 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.
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.
by Perry R. Cook and Gary P. Scavone, 1995 - 2007.
by Perry R. Cook and Gary P. Scavone, 1995 - 2009.
*/
/***************************************************/
#include "ADSR.h"
ADSR :: ADSR() : Envelope()
namespace stk {
ADSR :: ADSR( void )
{
target_ = 0.0;
value_ = 0.0;
attackRate_ = 0.001;
decayRate_ = 0.001;
releaseRate_ = 0.005;
sustainLevel_ = 0.5;
releaseRate_ = 0.01;
state_ = ATTACK;
Stk::addSampleRateAlert( this );
}
ADSR :: ~ADSR()
ADSR :: ~ADSR( void )
{
}
@@ -44,20 +43,18 @@ void ADSR :: sampleRateChanged( StkFloat newRate, StkFloat oldRate )
void ADSR :: keyOn()
{
target_ = 1.0;
rate_ = attackRate_;
state_ = ATTACK;
}
void ADSR :: keyOff()
{
target_ = 0.0;
rate_ = releaseRate_;
state_ = RELEASE;
}
void ADSR :: setAttackRate(StkFloat rate)
void ADSR :: setAttackRate( StkFloat rate )
{
if (rate < 0.0) {
if ( rate < 0.0 ) {
errorString_ << "ADSR::setAttackRate: negative rates not allowed ... correcting!";
handleError( StkError::WARNING );
attackRate_ = -rate;
@@ -65,9 +62,9 @@ void ADSR :: setAttackRate(StkFloat rate)
else attackRate_ = rate;
}
void ADSR :: setDecayRate(StkFloat rate)
void ADSR :: setDecayRate( StkFloat rate )
{
if (rate < 0.0) {
if ( rate < 0.0 ) {
errorString_ << "ADSR::setDecayRate: negative rates not allowed ... correcting!";
handleError( StkError::WARNING );
decayRate_ = -rate;
@@ -75,9 +72,9 @@ void ADSR :: setDecayRate(StkFloat rate)
else decayRate_ = rate;
}
void ADSR :: setSustainLevel(StkFloat level)
void ADSR :: setSustainLevel( StkFloat level )
{
if (level < 0.0 ) {
if ( level < 0.0 ) {
errorString_ << "ADSR::setSustainLevel: level out of range ... correcting!";
handleError( StkError::WARNING );
sustainLevel_ = 0.0;
@@ -85,9 +82,9 @@ void ADSR :: setSustainLevel(StkFloat level)
else sustainLevel_ = level;
}
void ADSR :: setReleaseRate(StkFloat rate)
void ADSR :: setReleaseRate( StkFloat rate )
{
if (rate < 0.0) {
if ( rate < 0.0 ) {
errorString_ << "ADSR::setReleaseRate: negative rates not allowed ... correcting!";
handleError( StkError::WARNING );
releaseRate_ = -rate;
@@ -95,9 +92,9 @@ void ADSR :: setReleaseRate(StkFloat rate)
else releaseRate_ = rate;
}
void ADSR :: setAttackTime(StkFloat time)
void ADSR :: setAttackTime( StkFloat time )
{
if (time < 0.0) {
if ( time < 0.0 ) {
errorString_ << "ADSR::setAttackTime: negative times not allowed ... correcting!";
handleError( StkError::WARNING );
attackRate_ = 1.0 / ( -time * Stk::sampleRate() );
@@ -105,9 +102,9 @@ void ADSR :: setAttackTime(StkFloat time)
else attackRate_ = 1.0 / ( time * Stk::sampleRate() );
}
void ADSR :: setDecayTime(StkFloat time)
void ADSR :: setDecayTime( StkFloat time )
{
if (time < 0.0) {
if ( time < 0.0 ) {
errorString_ << "ADSR::setDecayTime: negative times not allowed ... correcting!";
handleError( StkError::WARNING );
decayRate_ = 1.0 / ( -time * Stk::sampleRate() );
@@ -115,9 +112,9 @@ void ADSR :: setDecayTime(StkFloat time)
else decayRate_ = 1.0 / ( time * Stk::sampleRate() );
}
void ADSR :: setReleaseTime(StkFloat time)
void ADSR :: setReleaseTime( StkFloat time )
{
if (time < 0.0) {
if ( time < 0.0 ) {
errorString_ << "ADSR::setReleaseTime: negative times not allowed ... correcting!";
handleError( StkError::WARNING );
releaseRate_ = sustainLevel_ / ( -time * Stk::sampleRate() );
@@ -125,74 +122,34 @@ void ADSR :: setReleaseTime(StkFloat time)
else releaseRate_ = sustainLevel_ / ( time * Stk::sampleRate() );
}
void ADSR :: setAllTimes(StkFloat aTime, StkFloat dTime, StkFloat sLevel, StkFloat rTime)
void ADSR :: setAllTimes( StkFloat aTime, StkFloat dTime, StkFloat sLevel, StkFloat rTime )
{
this->setAttackTime(aTime);
this->setDecayTime(dTime);
this->setSustainLevel(sLevel);
this->setReleaseTime(rTime);
this->setAttackTime( aTime );
this->setDecayTime( dTime );
this->setSustainLevel( sLevel );
this->setReleaseTime( rTime );
}
void ADSR :: setTarget(StkFloat target)
void ADSR :: setTarget( StkFloat target )
{
target_ = target;
if (value_ < target_) {
if ( value_ < target_ ) {
state_ = ATTACK;
this->setSustainLevel(target_);
rate_ = attackRate_;
this->setSustainLevel( target_ );
}
if (value_ > target_) {
this->setSustainLevel(target_);
if ( value_ > target_ ) {
this->setSustainLevel( target_ );
state_ = DECAY;
rate_ = decayRate_;
}
}
void ADSR :: setValue(StkFloat value)
void ADSR :: setValue( StkFloat value )
{
state_ = SUSTAIN;
target_ = value;
value_ = value;
this->setSustainLevel(value);
rate_ = (StkFloat) 0.0;
this->setSustainLevel( value );
lastFrame_[0] = value;
}
int ADSR :: getState(void) const
{
return state_;
}
StkFloat ADSR :: computeSample()
{
switch (state_) {
case ATTACK:
value_ += rate_;
if (value_ >= target_) {
value_ = target_;
rate_ = decayRate_;
target_ = sustainLevel_;
state_ = DECAY;
}
break;
case DECAY:
value_ -= decayRate_;
if (value_ <= sustainLevel_) {
value_ = sustainLevel_;
rate_ = (StkFloat) 0.0;
state_ = SUSTAIN;
}
break;
case RELEASE:
value_ -= releaseRate_;
if (value_ <= 0.0) {
value_ = (StkFloat) 0.0;
state_ = DONE;
}
}
lastOutput_ = value_;
return value_;
}
} // stk namespace