54 ADSR(
float attack=0.001,
float decay=0.001,
float sustainLevel=0.5,
float release= 0.005){
55 this->attack = attack;
57 this->sustain = sustainLevel;
58 this->release = release;
63 void setAttackRate(
float a){
71 void setDecayRate(
float d){
79 void setSustainLevel(
float s){
87 void setReleaseRate(
float r){
95 void keyOn(
float tgt=0){
96 LOGI(
"%s: %f", LOG_METHOD, tgt);
98 this->target = tgt>0.0f && tgt<=1.0f ? tgt : sustain;
115 float attack, decay, sustain, release;
116 enum AdsrPhase {Idle, Attack, Decay, Sustain, Release};
117 const char* adsrNames[5] = {
"Idle",
"Attack",
"Decay",
"Sustain",
"Release"};
118 AdsrPhase state = Idle;
122 inline float update( ) {
127 if ( act_value >= target ) {
135 if ( act_value > sustain ) {
137 if ( act_value <= sustain ) {
144 if ( act_value >= sustain ) {
152 act_value -= release;
153 if ( act_value <= 0.0f ) {