summaryrefslogtreecommitdiff
path: root/synth
diff options
context:
space:
mode:
Diffstat (limited to 'synth')
-rw-r--r--synth/envelope.cpp48
-rw-r--r--synth/envelope.h2
2 files changed, 21 insertions, 29 deletions
diff --git a/synth/envelope.cpp b/synth/envelope.cpp
index 3e9c6ac..5678fd3 100644
--- a/synth/envelope.cpp
+++ b/synth/envelope.cpp
@@ -1,22 +1,6 @@
#include "envelope.h"
-Envelope::Envelope(jack_nframes_t a, jack_nframes_t d, fixed_t s, jack_nframes_t r, bool h, int frames)
-{
- level=0;
- t=0;
- state=ATTACK;
- max=ONE;
-
- nth_frame=frames;
-
- set_ratefactor(1.0);
-
- set_attack(a);
- set_decay(d);
- set_sustain(s);
- set_release(r);
- set_hold(h);
-}
+#include <iostream>
Envelope::Envelope(env_settings_t s, int frames)
{
@@ -29,6 +13,8 @@ Envelope::Envelope(env_settings_t s, int frames)
set_ratefactor(1.0);
+ has_release_phase=(s.release>=0);
+
set_attack(s.attack);
set_decay(s.decay);
set_sustain(s.sustain);
@@ -100,12 +86,14 @@ void Envelope::reattack()
void Envelope::release_key()
{
- if ((state!=RELEASE) && (state!=DONE))
- {
- t=0;
- state=RELEASE;
- sustain=level;
- }
+ if (has_release_phase)
+ if ((state!=RELEASE) && (state!=DONE))
+ {
+ t=0;
+ state=RELEASE;
+ sustain=level;
+ }
+ //if (!has_release_phase) ignore();
}
bool Envelope::still_active()
@@ -134,10 +122,14 @@ fixed_t Envelope::get_level() //must be called each frame
if (t>=decay)
{
level=max*sustain >>SCALE;
- if (hold)
- state=HOLD;
+ if (has_release_phase)
+ if (hold)
+ state=HOLD;
+ else
+ state=RELEASE;
else
- state=RELEASE;
+ state=DONE;
+
t=0;
}
else //will only happen, if t < decay. so decay will
@@ -147,7 +139,7 @@ fixed_t Envelope::get_level() //must be called each frame
break;
case HOLD:
- level=sustain*max >>SCALE;
+ //does nothing. level must be set properly before entering HOLD state
break;
case RELEASE:
@@ -163,7 +155,7 @@ fixed_t Envelope::get_level() //must be called each frame
break;
case DONE:
- level=0;
+ //does nothing. level must be set properly before entering DONE state
break;
}
diff --git a/synth/envelope.h b/synth/envelope.h
index 65ea723..be50fa2 100644
--- a/synth/envelope.h
+++ b/synth/envelope.h
@@ -14,7 +14,6 @@
class Envelope
{
public:
- Envelope(jack_nframes_t a, jack_nframes_t d, fixed_t s, jack_nframes_t r, bool h, int frames=1);
Envelope(env_settings_t s, int frames=1);
void release_key();
void reattack();
@@ -53,6 +52,7 @@ class Envelope
fixed_t sustain_orig;
fixed_t level;
bool hold;
+ bool has_release_phase;
jack_nframes_t t;
fixed_t ratefactor;