shithub: leaf

Download patch

ref: ed50a40430b62e7cca4f1d4efd9decafd296df77
parent: 344bac374e6642c371111b47cdc36ca143adb3d0
parent: 53cc69afc79c8adb859f00cdb183612baa50a48e
author: Jeff Snyder <jeff@snyderphonics.com>
date: Sat Apr 13 16:22:57 EDT 2019

merge fix

--- a/LEAF/Inc/leaf-crusher.h
+++ b/LEAF/Inc/leaf-crusher.h
@@ -61,4 +61,4 @@
 
 #endif // LEAF_WAVEFOLDER_H_INCLUDED
 
-//==============================================================================
+//==============================================================================
--- a/LEAF/Inc/leaf-math.h
+++ b/LEAF/Inc/leaf-math.h
@@ -19,6 +19,8 @@
 
 //==============================================================================
 
+//==============================================================================
+
 typedef enum oBool
 {
     OTRUE  = 1,
@@ -82,6 +84,10 @@
 float LEAF_round (float input, float rnd);
 float LEAF_bitwise_xor(float input, uint32_t op);
 
+float LEAF_reduct (float input, float ratio);
+float LEAF_round (float input, float rnd);
+float LEAF_bitwise_xor(float input, uint32_t op);
+
 float       LEAF_clip               (float min, float val, float max);
 int         LEAF_clipInt            (int min, int val, int max);
 float   	LEAF_softClip		    (float val, float thresh);
@@ -98,7 +104,6 @@
 // dope af
 float       LEAF_chebyshevT(float in, int n);
 float       LEAF_CompoundChebyshevT(float in, int n, float* amps);
-
 
 // Hermite interpolation
 float LEAF_interpolate_hermite (float A, float B, float C, float D, float t);
--- a/LEAF/Inc/leaf-mempool.h
+++ b/LEAF/Inc/leaf-mempool.h
@@ -50,7 +50,9 @@
     
 //==============================================================================
 
-#define MPOOL_POOL_SIZE   300000
+
+#define MPOOL_POOL_SIZE   500000
+
 #define MPOOL_ALIGN_SIZE (8)
 
 //#define size_t unsigned long
--- a/LEAF/Src/leaf-crusher.c
+++ b/LEAF/Src/leaf-crusher.c
@@ -81,4 +81,4 @@
 void    tCrusher_setSamplingRatio (tCrusher* const c, float ratio)
 {
     c->srr = ratio;
-}
+}
--- a/LEAF/Src/leaf-delay.c
+++ b/LEAF/Src/leaf-delay.c
@@ -437,8 +437,6 @@
 void   tTapeDelay_init (tTapeDelay* const d, float delay, uint32_t maxDelay)
 {
     d->maxDelay = maxDelay;
-    
-    d->delay = LEAF_clip(1.f, delay, d->maxDelay);
 
     d->buff = (float*) leaf_alloc(sizeof(float) * maxDelay);
     
@@ -451,7 +449,7 @@
     d->inc = 1.0f;
     d->inPoint = 0;
     
-    tTapeDelay_setDelay(d, 1.f);
+    tTapeDelay_setDelay(d, delay);
 }
 
 void tTapeDelay_free(tTapeDelay* const d)
@@ -462,7 +460,7 @@
 
 int count = 0;
 
-#define SMOOTH_FACTOR 10.f
+//#define SMOOTH_FACTOR 10.f
 
 float   tTapeDelay_tick (tTapeDelay* const d, float input)
 {
@@ -483,11 +481,11 @@
     float diff = (d->inPoint - d->idx);
     while (diff < 0.f) diff += d->maxDelay;
     
-    d->inc = 1.0f + (diff - d->delay) / d->delay * SMOOTH_FACTOR;
+    d->inc = 1.0f + (diff - d->delay) / d->delay; //* SMOOTH_FACTOR;
 
     d->idx += d->inc;
     
-    if (d->idx >= d->maxDelay) d->idx = 0.f;
+    if (d->idx >= d->maxDelay) d->idx = 0.0f;
 
     return d->lastOut;
 }
--- a/LEAF/Src/leaf-math.c
+++ b/LEAF/Src/leaf-math.c
@@ -21,9 +21,8 @@
 // The C-embedded Audio Library.
 #define TWO_TO_16 65536.f
 
-#define EXPONENTIAL_TABLE_SIZE 65536
+#define EXPONENTIAL_TABLE_SIZE 65536
 
-
 float interpolate3max(float *buf, const int peakindex)
 {
     float a = buf[peakindex-1];
@@ -71,7 +70,7 @@
     
     alias.f = f;
     alias.ui &= 0x7fffffff;
-    return alias.f;
+    return alias.f;
 }
 
 // dope af
@@ -207,8 +206,7 @@
     } else {
         return val;
     }
-}
-
+}
 
 oBool     LEAF_isPrime(uint64_t number )
 {
@@ -232,92 +230,92 @@
     else
         return x * ( 27 + x * x ) / ( 27 + 9 * x * x );
 }
-
-
-void LEAF_generate_sine(float* buffer, int size)
-{
-    float phase;
-    for (int i = 0; i < size; i++)
-    {
-        phase = (float) i / (float) size;
-        buffer[i] = sinf(phase * TWO_PI);
-    }
-}
-
-void LEAF_generate_sawtooth(float* buffer, float basefreq, int size)
-{
-    int harmonic = 1;
-    float phase = 0.0f;
-    float freq = harmonic * basefreq;
-    float amp;
-    
-    while (freq < (leaf.sampleRate * 0.5))
-    {
-        amp = 1.0f / harmonic;
-        for (int i = 0; i < size; i++)
-        {
-            phase = (float) i / (float) size;
-            buffer[i] += (amp * sinf(harmonic * phase * TWO_PI));
-        }
-        
-        harmonic++;
-        freq = harmonic * basefreq;
-    }
-}
-
-
-void LEAF_generate_triangle(float* buffer, float basefreq, int size)
-{
-    int harmonic = 1;
-    float phase = 0.0f;
-    float freq = harmonic * basefreq;
-    float amp = 1.0f;
-    
-    int count = 0;
-    float mult = 1.0f;
-    
-    while (freq < (leaf.sampleRate * 0.5))
-    {
-        amp = 1.0f / (float)(harmonic * harmonic);
-        
-        if (count % 2)  mult = -1.0f;
-        else            mult =  1.0f;
-        
-        for (int i = 0; i < size; i++)
-        {
-            phase = (float) i / (float) size;
-            buffer[i] += (mult * amp * sinf(harmonic * phase * TWO_PI));
-        }
-        
-        count++;
-        harmonic += 2;
-        freq = harmonic * basefreq;
-    }
-}
-
-void LEAF_generate_square(float* buffer, float basefreq, int size)
-{
-    int harmonic = 1;
-    float phase = 0.0f;
-    float freq = harmonic * basefreq;
-    float amp = 1.0f;
-    
-    while (freq < (leaf.sampleRate * 0.5))
-    {
-        amp = 1.0f / (float)(harmonic);
-        
-        for (int i = 0; i < size; i++)
-        {
-            phase = (float) i / (float) size;
-            buffer[i] += (amp * sinf(harmonic * phase * TWO_PI));
-        }
-        
-        harmonic += 2;
-        freq = harmonic * basefreq;
-    }
-}
-
 
+
+void LEAF_generate_sine(float* buffer, int size)
+{
+    float phase;
+    for (int i = 0; i < size; i++)
+    {
+        phase = (float) i / (float) size;
+        buffer[i] = sinf(phase * TWO_PI);
+    }
+}
+
+void LEAF_generate_sawtooth(float* buffer, float basefreq, int size)
+{
+    int harmonic = 1;
+    float phase = 0.0f;
+    float freq = harmonic * basefreq;
+    float amp;
+    
+    while (freq < (leaf.sampleRate * 0.5))
+    {
+        amp = 1.0f / harmonic;
+        for (int i = 0; i < size; i++)
+        {
+            phase = (float) i / (float) size;
+            buffer[i] += (amp * sinf(harmonic * phase * TWO_PI));
+        }
+        
+        harmonic++;
+        freq = harmonic * basefreq;
+    }
+}
+
+
+void LEAF_generate_triangle(float* buffer, float basefreq, int size)
+{
+    int harmonic = 1;
+    float phase = 0.0f;
+    float freq = harmonic * basefreq;
+    float amp = 1.0f;
+    
+    int count = 0;
+    float mult = 1.0f;
+    
+    while (freq < (leaf.sampleRate * 0.5))
+    {
+        amp = 1.0f / (float)(harmonic * harmonic);
+        
+        if (count % 2)  mult = -1.0f;
+        else            mult =  1.0f;
+        
+        for (int i = 0; i < size; i++)
+        {
+            phase = (float) i / (float) size;
+            buffer[i] += (mult * amp * sinf(harmonic * phase * TWO_PI));
+        }
+        
+        count++;
+        harmonic += 2;
+        freq = harmonic * basefreq;
+    }
+}
+
+void LEAF_generate_square(float* buffer, float basefreq, int size)
+{
+    int harmonic = 1;
+    float phase = 0.0f;
+    float freq = harmonic * basefreq;
+    float amp = 1.0f;
+    
+    while (freq < (leaf.sampleRate * 0.5))
+    {
+        amp = 1.0f / (float)(harmonic);
+        
+        for (int i = 0; i < size; i++)
+        {
+            phase = (float) i / (float) size;
+            buffer[i] += (amp * sinf(harmonic * phase * TWO_PI));
+        }
+        
+        harmonic += 2;
+        freq = harmonic * basefreq;
+    }
+}
+
+
 //-----------------------------------------------------------------------------
 // name: mtof()
 // desc: midi to freq, from PD source
@@ -326,35 +324,34 @@
 {
     if( f <= -1500.0f ) return (0);
     else if( f > 1499.0f ) return (LEAF_midiToFrequency(1499.0f));
-    else return ( powf(2.0f, (f - 69.0f) / 12.0f) * 440.0f );
-}
-
-
-// alpha, [0.0, 1.0]
-float LEAF_interpolate_hermite (float A, float B, float C, float D, float alpha)
-{
-    alpha = LEAF_clip(0.0f, alpha, 1.0f);
-    
-    float a = -A/2.0f + (3.0f*B)/2.0f - (3.0f*C)/2.0f + D/2.0f;
-    float b = A - (5.0f*B)/2.0f + 2.0f*C - D / 2.0f;
-    float c = -A/2.0f + C/2.0f;
-    float d = B;
-    
-    return a*alpha*alpha*alpha + b*alpha*alpha + c*alpha + d;
-}
-
-// alpha, [0.0, 1.0]
-float LEAF_interpolation_linear (float A, float B, float alpha)
-{
-    alpha = LEAF_clip(0.0f, alpha, 1.0f);
-    
-    float omAlpha = 1.0f - alpha;
-    
-    // First 1/2 of interpolation
-    float out = A * omAlpha;
-    
-    out += B * alpha;
-    
-    return out;
-}
+    else return ( powf(2.0f, (f - 69.0f) * 0.083333333333333f) * 440.0f );
+}
 
+
+// alpha, [0.0, 1.0]
+float LEAF_interpolate_hermite (float A, float B, float C, float D, float alpha)
+{
+    alpha = LEAF_clip(0.0f, alpha, 1.0f);
+
+    float a = -A/2.0f + (3.0f*B)/2.0f - (3.0f*C)/2.0f + D/2.0f;
+    float b = A - (5.0f*B)/2.0f + 2.0f*C - D / 2.0f;
+    float c = -A/2.0f + C/2.0f;
+    float d = B;
+
+    return a*alpha*alpha*alpha + b*alpha*alpha + c*alpha + d;
+}
+
+// alpha, [0.0, 1.0]
+float LEAF_interpolation_linear (float A, float B, float alpha)
+{
+    alpha = LEAF_clip(0.0f, alpha, 1.0f);
+
+    float omAlpha = 1.0f - alpha;
+
+    // First 1/2 of interpolation
+    float out = A * omAlpha;
+
+    out += B * alpha;
+
+    return out;
+}
--- a/LEAF/leaf.h
+++ b/LEAF/leaf.h
@@ -37,6 +37,7 @@
 #include ".\Inc\leaf-crusher.h"
 #include ".\Inc\leaf-wavefolder.h"
 #include ".\Inc\leaf-wavetables.h"
+#include ".\Inc\leaf-crusher.h"
 
 #else
 
@@ -58,6 +59,7 @@
 #include "./Inc/leaf-crusher.h"
 #include "./Inc/leaf-wavefolder.h"
 #include "./Inc/leaf-wavetables.h"
+#include "./Inc/leaf-crusher.h"
 
 #endif