Commit 3432aa16f3d348721c2f31f00fa2a090a36dd2b9

Judy Najnudel 2018-08-12T19:43:45

Fix ADSR attack and decay which made weird clicks

diff --git a/rtbuf_synth_adsr.c b/rtbuf_synth_adsr.c
index 3c83af2..5b50e70 100644
--- a/rtbuf_synth_adsr.c
+++ b/rtbuf_synth_adsr.c
@@ -24,11 +24,14 @@ static inline
 double adsr (double attack, double decay, double sustain,
              double release, double start, double stop)
 {
+  double t = start;
   double x;
-  if (start < attack)
-    x = start / attack;
-  else if (start < attack + decay)
-    x = 1.0 + (sustain - 1.0) * (start - attack);
+  if (stop >= 0.0)
+    t = start - stop;
+  if (t < attack)
+    x = t / attack;
+  else if (t - attack < decay)
+    x = 1.0 + (sustain - 1.0) * (t - attack) / decay;
   else
     x = sustain;
   if (stop < 0.0)