shithub: leaf

Download patch

ref: 27cbc0375a57dfd54e7dd8155b39bf7e271aa0aa
parent: 23faeb0a9edc0b46299231e9f78a40705aab2e4d
parent: a3ef3e09c289fa943c6bc2e2cef58feff420784c
author: spiricom <jeff@snyderphonics.com>
date: Thu Sep 10 13:11:00 EDT 2020

merged with latest leaf. may have messed up some initToPools by adding unecessary additional arguments of leaf consts

--- a/leaf/Src/leaf-effects.c
+++ b/leaf/Src/leaf-effects.c
@@ -89,8 +89,8 @@
     LEAF* leaf = v->mempool->leaf;
     
     float fs = leaf->sampleRate;
-    if(fs <  8000.0f) fs =  8000.0f;
-    if(fs > 96000.0f) fs = 96000.0f;
+//    if(fs <  8000.0f) fs =  8000.0f;
+//    if(fs > 96000.0f) fs = 96000.0f;
     
     int32_t n = (int32_t)(0.01633f * fs); //this sets the window time to 16ms if the buffer is large enough. Buffer needs to be at least 784 samples at 48000
     if(n > v->bufsize) n = v->bufsize;
@@ -97,6 +97,10 @@
     
     //O = (VstInt32)(0.0005f * fs);
     v->O = (int32_t)((0.0001f + 0.0004f * v->param[3]) * fs);
+    if (v->O >= ORD_MAX)
+    {
+        v->O = ORD_MAX-1;
+    }
     
     if(n != v->N) //recalc hanning window
     {
@@ -261,7 +265,6 @@
     float z[ORD_MAX], r[ORD_MAX], x;
     int32_t i, j, nn=n;
 
-
     if (warpOn == 0)
     {
         for(j=0; j<=o; j++, nn--)  //buf[] is already emphasized and windowed
@@ -286,11 +289,11 @@
     {
         if(r[0] < min)
         {
-//            for(i=0; i<n; i++)
-//            {
-                buf[0] = 0.0f;
-                return;
-//            }
+            for(i=0; i<n; i++)
+            {
+                buf[i] = 0.0f;
+            }
+            return;
         }
 
         tTalkbox_lpcDurbin(r, o, k, G);  //calc reflection coeffs
@@ -418,8 +421,8 @@
     LEAF* leaf = v->mempool->leaf;
     
     float fs = leaf->sampleRate;
-    if(fs <  8000.0f) fs =  8000.0f;
-    if(fs > 96000.0f) fs = 96000.0f;
+//    if(fs <  8000.0f) fs =  8000.0f;
+//    if(fs > 96000.0f) fs = 96000.0f;
 
     int32_t n = (int32_t)(0.01633f * fs); //this sets the window time to 16ms if the buffer is large enough. Buffer needs to be at least 784 samples at 48000
     if(n > v->bufsize) n = v->bufsize;
@@ -426,6 +429,10 @@
 
     //O = (VstInt32)(0.0005f * fs);
     v->O = (int32_t)((0.0001f + 0.0004f * v->param[3]) * fs);
+    if (v->O >= ORD_MAX)
+    {
+        v->O = ORD_MAX-1;
+    }
 
     if(n != v->N) //recalc hanning window
     {
@@ -589,20 +596,20 @@
 void tTalkboxFloat_lpc(float *buf, float *car, float* dl, float* Rt, int32_t n, int32_t o, float warp, int warpOn, float *k, int freeze, float *G)
 {
     float z[ORD_MAX], r[ORD_MAX], x;
-    int32_t i, j, nn=n;
-
-
+    
     if (warpOn == 0)
     {
-        for(j=0; j<=o; j++, nn--)  //buf[] is already emphasized and windowed
+        int nn = n;
+        for(int j = 0; j <= o; j++, nn--)  //buf[] is already emphasized and windowed
         {
             z[j] = r[j] = 0.0f;
-            for(i=0; i<nn; i++) r[j] += buf[i] * buf[i+j]; //autocorrelation
+            for(int i = 0; i < nn; i++) r[j] += buf[i] * buf[i+j]; //autocorrelation
         }
     }
     else
     {
-        for(j=0; j<=o; j++, nn--)  //buf[] is already emphasized and windowed
+        int nn = n;
+        for(int j = 0; j <= o; j++, nn--)  //buf[] is already emphasized and windowed
         {
             z[j] = r[j] = 0.0f;
         }
@@ -616,11 +623,13 @@
     {
         if(r[0] < min)
         {
-//            for(i=0; i<n; i++)
-//            {
-                buf[0] = 0.0f;
-                return;
-//            }
+
+            for(int i = 0; i < n; i++)
+            {
+                buf[i] = 0.0f;
+            }
+            return;
+
         }
 
         tTalkbox_lpcDurbin(r, o, k, G);  //calc reflection coeffs
@@ -627,15 +636,15 @@
 
         //this is for stability to keep reflection coefficients inside the unit circle
         //but in Harma's papers I've seen 0.998.  just needs to be less than 1 it seems but maybe some wiggle room to avoid instability from floating point precision -JS
-        for(i=0; i<=o; i++)
+        for(int i = 0; i <= o; i++)
         {
             if(k[i] > 0.998f) k[i] = 0.998f; else if(k[i] < -0.998f) k[i] = -.998f;
         }
     }
-    for(i=0; i<n; i++)
+    for(int i = 0; i < n; i++)
     {
         x = G[0] * car[i];
-        for(j=o; j>0; j--)  //lattice filter
+        for(int j = o; j > 0; j--)  //lattice filter
         {
             x -= k[j] * z[j-1];
             z[j] = z[j-1] + k[j] * x;
--- a/leaf/Src/leaf-mempool.c
+++ b/leaf/Src/leaf-mempool.c
@@ -424,7 +424,8 @@
 {
     _tMempool* mm = *mem;
     _tMempool* m = *mp = (_tMempool*) mpool_alloc(sizeof(_tMempool), mm);
-    m->leaf = leaf;
+    m->leaf = mm->leaf;
+    
     mpool_create (memory, size, m);
 }