shithub: leaf

Download patch

ref: 8ea545cd68e5cf321fe47c9ad73207f2fbd117dd
parent: 6447d0119e11ad6bfce19cd7bb0cb3eb284e4fcd
author: spiricom <jeff@snyderphonics.com>
date: Sun Mar 1 14:50:23 EST 2020

added leak to ADSR

binary files a/.DS_Store b/.DS_Store differ
binary files a/LEAF/.DS_Store b/LEAF/.DS_Store differ
--- a/LEAF/Inc/leaf-envelopes.h
+++ b/LEAF/Inc/leaf-envelopes.h
@@ -104,6 +104,7 @@
         
         float attackPhase, decayPhase, releasePhase, rampPhase;
 
+        float leakFactor;
 
 
     } _tADSR;
@@ -120,6 +121,7 @@
     void    tADSR_setDecay      (tADSR* const, float decay);
     void    tADSR_setSustain    (tADSR* const, float sustain);
     void    tADSR_setRelease    (tADSR* const, float release);
+    void 	tADSR_setLeakFactor	(tADSR* const, float leakFactor);
     void    tADSR_on            (tADSR* const, float velocity);
     void    tADSR_off           (tADSR* const);
     
--- a/LEAF/Src/leaf-envelopes.c
+++ b/LEAF/Src/leaf-envelopes.c
@@ -309,6 +309,8 @@
     adsr->releaseInc = adsr->inc_buff[releaseIndex];
     adsr->rampInc = adsr->inc_buff[rampIndex];
 
+    adsr->leakFactor = 1.0f;
+
 }
 
 void tADSR_free(tADSR* const adsrenv)
@@ -374,6 +376,7 @@
     adsr->releaseInc = adsr->inc_buff[releaseIndex];
     adsr->rampInc = adsr->inc_buff[rampIndex];
 
+    adsr->leakFactor = 1.0f;
 }
 
 void    tADSR_freeFromPool  (tADSR* const adsrenv, tMempool* const mp)
@@ -443,8 +446,15 @@
     adsr->releaseInc = adsr->inc_buff[releaseIndex];
 }
 
+// 0.999999 is slow leak, 0.9 is fast leak
+void     tADSR_setLeakFactor(tADSR* const adsrenv, float leakFactor)
+{
+    _tADSR* adsr = *adsrenv;
 
 
+    adsr->leakFactor = leakFactor;
+}
+
 void tADSR_on(tADSR* const adsrenv, float velocity)
 {
     _tADSR* adsr = *adsrenv;
@@ -543,6 +553,11 @@
         
         // Increment ADSR decay.
         adsr->decayPhase += adsr->decayInc;
+    }
+
+    if (adsr->inSustain)
+    {
+    	adsr->next = adsr->next * adsr->leakFactor;
     }
 
     if (adsr->inRelease)