Skip to content

Commit bcb76b0

Browse files
committed
Envelope Fixes #6
Runs a bit faster. Automatically runs on next step after state change.
1 parent fe17ad0 commit bcb76b0

2 files changed

Lines changed: 16 additions & 6 deletions

File tree

src/Envelope.hpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#define MAX_VALUE 0.999f
66
#define MIN_VALUE 0.001f
77

8+
#define MAX_PROCESS_COUNT 32
89

910
struct Envelope {
1011
enum Stage {
@@ -69,14 +70,23 @@ struct Envelope {
6970
void trigger() {
7071
stage = ATTACK;
7172
_env = MIN_VALUE;
73+
processCount = MAX_PROCESS_COUNT;
74+
sampleTime = 0;
7275
}
7376
void retrigger() {
7477
stage = ATTACK;
78+
processCount = MAX_PROCESS_COUNT;
79+
}
80+
void release(){
81+
stage = RELEASE;
82+
processCount = MAX_PROCESS_COUNT;
7583
}
7684
void reset() {
7785
stage = IDLE;
7886
idle = true;
7987
_env = MIN_VALUE;
88+
processCount = MAX_PROCESS_COUNT;
89+
sampleTime = 0;
8090
}
8191
};
8292

@@ -87,7 +97,7 @@ struct ADEnvelope : Envelope {
8797
void process(float st) {
8898
processCount++;
8999
sampleTime += st;
90-
if (processCount < 64) {
100+
if (processCount < MAX_PROCESS_COUNT) {
91101
return;
92102
}
93103
else {
@@ -167,7 +177,7 @@ struct ADSREnvelope : Envelope {
167177
void process(float st) {
168178
processCount++;
169179
sampleTime += st;
170-
if (processCount < 64) {
180+
if (processCount < MAX_PROCESS_COUNT) {
171181
return;
172182
}
173183
else {

src/supersaw.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,10 @@ struct Supersaw : Module {
7676
configInput(NOISE_MIX_CV_INPUT, "Noise mix CV");
7777
configParam(PULSE_WIDTH_PARAM, 0.0, 1.0, 0.0, "B width");
7878
configInput(PULSE_WIDTH_CV_INPUT, "B width CV");
79-
configParam(ATTACK_PARAM, 0.01, 5.0, 0.01, "Attack time", " s");
80-
configParam(DECAY_PARAM, 0.1, 5.0, 0.1, "Decay time", " s");
79+
configParam(ATTACK_PARAM, 0.001, 5.0, 0.01, "Attack time", " s");
80+
configParam(DECAY_PARAM, 0.001, 5.0, 0.1, "Decay time", " s");
8181
configParam(SUSTAIN_PARAM, 0.0, 1.0, 1.0, "Sustain level");
82-
configParam(RELEASE_PARAM, 0.01, 5.0, 0.01, "Release time", " s");
82+
configParam(RELEASE_PARAM, 0.001, 5.0, 0.01, "Release time", " s");
8383
configSwitch(ENV_TO_DUR_PARAM, 0.0, 1.0, 0.0, "Env -> Noise duration", {"Off", "On"});
8484
configSwitch(ENV_TO_MIX_PARAM, 0.0, 1.0, 0.0, "Env -> Noise mix", {"Off", "On"});
8585
configSwitch(ENV_TO_PW_PARAM, 0.0, 1.0, 0.0, "Env -> B width", {"Off", "On"});
@@ -241,7 +241,7 @@ struct Supersaw : Module {
241241
}
242242

243243
if (last_gate && !(inputs[GATE_INPUT].getVoltage() > 0.5)) {
244-
envelope.stage = envelope.RELEASE;
244+
envelope.release();
245245
}
246246

247247
envelope.process(args.sampleTime);

0 commit comments

Comments
 (0)