shithub: leaf

Download patch

ref: 98cb700b9e5af25336a1818612a8933d97587139
parent: 6d13ff665679ae51cbad437a46d17236441afaa9
parent: 579b819f8416248abe1bda1eb27d14cda3c91b7e
author: MatthewJWang <33766053+MatthewJWang@users.noreply.github.com>
date: Thu Feb 28 15:02:36 EST 2019

Merge branch 'mike_dev' into oversampler

--- a/LEAF/Inc/leaf-crusher.h
+++ b/LEAF/Inc/leaf-crusher.h
@@ -21,37 +21,37 @@
 #include "leaf-globals.h"
 #include "leaf-math.h"
 
-//==============================================================================
+//==============================================================================
     
-typedef struct _tCrusher
-{
-    float srr;
-    float mult, div;
-    float rnd;
-    
-    uint32_t  op; //which bitwise operation (0-7)
-    
-    float gain;
-    
-} tCrusher;
-    
-
-void    tCrusher_init    (tCrusher* const);
-void    tCrusher_free    (tCrusher* const);
-
-float   tCrusher_tick    (tCrusher* const, float input);
-    
-// 0-7
-void    tCrusher_setOperation (tCrusher* const, float op);
- 
-// 0.0 - 1.0
-void    tCrusher_setQuality (tCrusher* const, float val);
-    
-// what division to round to
-void    tCrusher_setRound (tCrusher* const, float rnd);
-    
-// sampling ratio
-void    tCrusher_setSamplingRatio (tCrusher* const, float ratio);
+typedef struct _tCrusher
+{
+    float srr;
+    float mult, div;
+    float rnd;
+    
+    uint32_t  op; //which bitwise operation (0-7)
+    
+    float gain;
+    
+} tCrusher;
+    
+
+void    tCrusher_init    (tCrusher* const);
+void    tCrusher_free    (tCrusher* const);
+
+float   tCrusher_tick    (tCrusher* const, float input);
+    
+// 0.0 - 1.0
+void    tCrusher_setOperation (tCrusher* const, float op);
+ 
+// 0.0 - 1.0
+void    tCrusher_setQuality (tCrusher* const, float val);
+    
+// what division to round to
+void    tCrusher_setRound (tCrusher* const, float rnd);
+    
+// sampling ratio
+void    tCrusher_setSamplingRatio (tCrusher* const, float ratio);
     
 //==============================================================================
 
--- a/LEAF/Inc/leaf-math.h
+++ b/LEAF/Inc/leaf-math.h
@@ -76,10 +76,10 @@
 
 // Jones shaper
 float LEAF_shaper     (float input, float m_drive);
-float LEAF_reedTable  (float input, float offset, float slope);
-    
-float LEAF_reduct (float input, float ratio);
-float LEAF_round (float input, float rnd);
+float LEAF_reedTable  (float input, float offset, float slope);
+    
+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);
--- a/LEAF/Inc/leaf-mempool.h
+++ b/LEAF/Inc/leaf-mempool.h
@@ -50,7 +50,7 @@
     
 //==============================================================================
 
-#define MPOOL_POOL_SIZE   500000
+#define MPOOL_POOL_SIZE   3000000
 #define MPOOL_ALIGN_SIZE (8)
 
 //#define size_t unsigned long
--- a/LEAF/Inc/leaf-sample.h
+++ b/LEAF/Inc/leaf-sample.h
@@ -61,13 +61,13 @@
     
 //==============================================================================
     
-    typedef enum Mode
+    typedef enum PlayMode
     {
-        Normal,
-        Loop,
-        BackAndForth,
-        SampleModeNil
-    } Mode;
+        PlayNormal,
+        PlayLoop,
+        PlayBackAndForth,
+        PlayModeNil
+    } PlayMode;
     
     typedef struct _tSampler
     {
@@ -87,7 +87,7 @@
         uint32_t len;
         uint32_t cfxlen;
     
-        Mode mode;
+        PlayMode mode;
         int retrigger;
         
         int active;
@@ -101,7 +101,7 @@
 
     void    tSampler_setSample (tSampler* const, tBuffer* s);
     
-    void    tSampler_setMode   (tSampler* const, Mode mode);
+    void    tSampler_setMode   (tSampler* const, PlayMode mode);
     
     void    tSampler_play      (tSampler* const);
     void    tSampler_stop      (tSampler* const);
--- a/LEAF/Src/leaf-crusher.c
+++ b/LEAF/Src/leaf-crusher.c
@@ -6,79 +6,79 @@
 
 ==============================================================================*/
 
-#if _WIN32 || _WIN64
-
-#include "..\Inc\leaf-crusher.h"
-
-#else
-
-#include "../Inc/leaf-crusher.h"
-
-#endif
+#if _WIN32 || _WIN64
 
+#include "..\Inc\leaf-crusher.h"
+
+#else
+
+#include "../Inc/leaf-crusher.h"
+
+#endif
+
 //==============================================================================
-
-#define SCALAR 5000.f
-
-void    tCrusher_init    (tCrusher* const c)
-{
-    c->op = 4;
-    c->div = SCALAR;
-    c->rnd = 0.25f;
-    c->srr = 0.25f;
-    
-    c->gain = (c->div / SCALAR) * 0.7f + 0.3f;
-}
-
-void    tCrusher_free    (tCrusher* const c)
-{
-    leaf_free(c);
-}
-
-float   tCrusher_tick    (tCrusher* const c, float input)
-{
-    float sample = input;
-    
-    sample *= SCALAR; // SCALAR is 5000 by default
-    
-    sample = (int32_t) sample;
-    
-    sample /= c->div;
-
-    sample = LEAF_bitwise_xor(sample, c->op << 23);
-    
-    sample = LEAF_clip(-1.f, sample, 1.f);
-    
-    sample = LEAF_round(sample, c->rnd);
-    
-    sample = LEAF_reduct(sample, c->srr);
-    
-    return sample * c->gain;
-    
-}
-
-void    tCrusher_setOperation (tCrusher* const c, float op)
+
+#define SCALAR 5000.f
+
+void    tCrusher_init    (tCrusher* const c)
 {
-	c->op = (uint32_t) (op * 8.0f);
-}
-
-// 0.0 - 1.0
-void    tCrusher_setQuality (tCrusher* const c, float val)
+    c->op = 4;
+    c->div = SCALAR;
+    c->rnd = 0.25f;
+    c->srr = 0.25f;
+    
+    c->gain = (c->div / SCALAR) * 0.7f + 0.3f;
+}
+
+void    tCrusher_free    (tCrusher* const c)
 {
-    val = LEAF_clip(0.0f, val, 1.0f);
-    
-    c->div = 0.01f + val * SCALAR;
-    
-    c->gain = (c->div / SCALAR) * 0.7f + 0.3f;
-}
-
-// what decimal to round to
-void    tCrusher_setRound (tCrusher* const c, float rnd)
-{
-    c->rnd = fabsf(rnd);
-}
-
-void    tCrusher_setSamplingRatio (tCrusher* const c, float ratio)
-{
-    c->srr = ratio;
+    leaf_free(c);
+}
+
+float   tCrusher_tick    (tCrusher* const c, float input)
+{
+    float sample = input;
+    
+    sample *= SCALAR; // SCALAR is 5000 by default
+    
+    sample = (int32_t) sample;
+    
+    sample /= c->div;
+
+    sample = LEAF_bitwise_xor(sample, c->op << 23);
+    
+    sample = LEAF_clip(-1.f, sample, 1.f);
+    
+    sample = LEAF_round(sample, c->rnd);
+    
+    sample = LEAF_reduct(sample, c->srr);
+    
+    return sample * c->gain;
+    
+}
+
+void    tCrusher_setOperation (tCrusher* const c, float op)
+{
+	c->op = (uint32_t) (op * 8.0f);
+}
+
+// 0.0 - 1.0
+void    tCrusher_setQuality (tCrusher* const c, float val)
+{
+    val = LEAF_clip(0.0f, val, 1.0f);
+    
+    c->div = 0.01f + val * SCALAR;
+    
+    c->gain = (c->div / SCALAR) * 0.7f + 0.3f;
+}
+
+// what decimal to round to
+void    tCrusher_setRound (tCrusher* const c, float rnd)
+{
+    c->rnd = fabsf(rnd);
+}
+
+void    tCrusher_setSamplingRatio (tCrusher* const c, float ratio)
+{
+    c->srr = ratio;
 }
--- a/LEAF/Src/leaf-sample.c
+++ b/LEAF/Src/leaf-sample.c
@@ -125,9 +125,9 @@
     p->flip = 1;
     p->bnf = 1;
     
-    p->mode = Normal;
+    p->mode = PlayNormal;
     
-    p->cfxlen = 300; // default 300 sample crossfade
+    p->cfxlen = 500; // default 300 sample crossfade
     
     tRamp_init(&p->gain, 7.0f, 1);
     tRamp_setVal(&p->gain, 0.f);
@@ -191,7 +191,7 @@
         numsamps = (dir > 0) ? (end - idx) : (idx - start);
         numsamps *= p->iinc;
         
-        if (p->mode == Loop)
+        if (p->mode == PlayLoop)
         {
             if (numsamps <= p->cfxlen)
             {
@@ -228,7 +228,7 @@
         
         numsamps = (idx - start) / p->inc;
         
-        if (p->mode == Loop)
+        if (p->mode == PlayLoop)
         {
             if (numsamps <= p->cfxlen)
             {
@@ -254,7 +254,7 @@
     
     p->idx += (dir * p->inc);
     
-    if (p->mode == Normal)
+    if (p->mode == PlayNormal)
     {
         if (numsamps < (0.007f * leaf.sampleRate))
         {
@@ -262,7 +262,7 @@
             p->active = -1;
         }
     }
-    else if (p->mode == Loop ) // == Normal or Loop
+    else if (p->mode == PlayLoop )
     {
         if (idx <= start)
         {
@@ -273,7 +273,7 @@
             p->idx -= (float)(p->len);
         }
     }
-    else // == BackAndForth
+    else // == PlayBackAndForth
     {
         if (p->idx < start)
         {
@@ -330,7 +330,7 @@
     p->samp = s;
 }
 
-void tSampler_setMode      (tSampler* const p, Mode mode)
+void tSampler_setMode      (tSampler* const p, PlayMode mode)
 {
     p->mode = mode;
 }
--- a/LEAF_JUCEPlugin/Source/LEAFLink.cpp
+++ b/LEAF_JUCEPlugin/Source/LEAFLink.cpp
@@ -137,7 +137,7 @@
     return value;
 }
 
-float randomNumberGenerator(void)
+float getRandomFloat(void)
 {
     return ((float)rand()/RAND_MAX);
 }
--- a/LEAF_JUCEPlugin/Source/LEAFLink.h
+++ b/LEAF_JUCEPlugin/Source/LEAFLink.h
@@ -47,6 +47,6 @@
 void setSliderModelValue(String name, float val);
 void setSliderValue(String name, float val);
 float getSliderValue(String name);
-float randomNumberGenerator(void);
+float getRandomFloat(void);
 
 #endif  // UTILITIES_H_INCLUDED
--- a/LEAF_JUCEPlugin/Source/MyTest.cpp
+++ b/LEAF_JUCEPlugin/Source/MyTest.cpp
@@ -1,151 +1,153 @@
-/*
-  ==============================================================================
-
-    FM.c
-    Created: 23 Jan 2017 9:39:38am
-    Author:  Michael R Mulshine
-
-  ==============================================================================
-*/
-
-#include "LEAFTest.h"
-#include "MyTest.h"
-
-
-static void leaf_pool_report(void);
-static void leaf_pool_dump(void);
-static void run_pool_test(void);
-
-float gain, freqVal;
-float clipThreshold = 1.f;
-
-tCycle test;
-tOversampler2x os2;
-tOversampler4x os4;
-
-void    LEAFTest_init            (float sampleRate, int blockSize)
-{
-    LEAF_init(sampleRate, blockSize, &randomNumberGenerator);
-
-    tCycle_init(&test);
-    tOversampler2x_init(&os2);
-    tOversampler4x_init(&os4);
-    
-    leaf_pool_report();
-}
-
-
-float softClip(float sample)
-{
-    return LEAF_softClip(sample, clipThreshold);
-}
-
-float   LEAFTest_tick            (float input)
-{
-    tCycle_setFreq(&test, freqVal);
-    float sample = tCycle_tick(&test);
-    
-    sample = tOversampler4x_tick(&os4, sample, &softClip);
-    
-    return sample * gain;
-}
-
-bool lastState = false, lastPlayState = false;
-void    LEAFTest_block           (void)
-{
-    clipThreshold = (1.f - getSliderValue("distortion")) * 0.3f;
-    gain = getSliderValue("gain") * 0.5f;
-    freqVal = getSliderValue("frequency") * 18000.f;
-}
-
-void    LEAFTest_controllerInput (int cnum, float cval)
-{
-
-}
-
-void    LEAFTest_pitchBendInput  (int pitchBend)
-{
-    
-}
-
-int lastNote;
-void    LEAFTest_noteOn          (int note, float velocity)
-{
-}
-
-
-void    LEAFTest_noteOff         (int note)
-{
-}
-
-
-
-void    LEAFTest_end             (void)
-{
-
-}
-
-// LEAF POOL UTILITIES
-
-void leaf_pool_report(void)
-{
-    DBG(String(leaf_pool_get_used()) + " of  " + String(leaf_pool_get_size()));
-}
-
-void leaf_pool_dump(void)
-{
-    float* buff = (float*)leaf_pool_get_pool();
-    int siz = leaf_pool_get_size();
-    siz /= sizeof(float);
-    for (int i = 0; i < siz; i++)
-    {
-        DBG(String(buff[i]));
-    }
-}
-
-static void run_pool_test(void)
-{
-    leaf_pool_report();
-    
-    DBG("ALLOC BUFFER 1");
-    int size = 50;
-    float* buffer;
-    buffer = (float*) leaf_alloc(sizeof(float) * size);
-    
-    for (int i = 0; i < size; i++)
-    {
-        buffer[i] = (float)i;
-        
-    }
-    
-    leaf_pool_report();
-    
-    DBG("ALLOC BUFFER 2");
-    size = 25;
-    
-    buffer = (float*) leaf_alloc(sizeof(float) * size);
-    
-    leaf_pool_report();
-    
-    for (int i = 0; i < size; i++)
-    {
-        buffer[i] = (float)(i*2);
-    }
-    leaf_free(buffer);
-    
-    leaf_pool_report();
-    
-    DBG("ALLOC BUFFER 3");
-    size = 15;
-    
-    buffer = (float*) leaf_alloc(sizeof(float) * size);
-    
-    for (int i = 0; i < size; i++)
-    {
-        buffer[i] = (float)(i*3);
-    }
-    
-    leaf_pool_report();
-    
-    leaf_pool_dump();
-}
+/*
+  ==============================================================================
+
+    FM.c
+    Created: 23 Jan 2017 9:39:38am
+    Author:  Michael R Mulshine
+
+  ==============================================================================
+*/
+
+#include "LEAFTest.h"
+#include "MyTest.h"
+
+
+static void leaf_pool_report(void);
+static void leaf_pool_dump(void);
+static void run_pool_test(void);
+
+float gain, freqVal;
+float clipThreshold = 1.f;
+
+tCycle test;
+tOversampler2x os2;
+tOversampler4x os4;
+
+void    LEAFTest_init            (float sampleRate, int blockSize)
+{
+    LEAF_init(sampleRate, blockSize, &randomNumberGenerator);
+
+    tCycle_init(&test);
+    tOversampler2x_init(&os2);
+    tOversampler4x_init(&os4);
+    
+    leaf_pool_report();
+}
+
+
+float softClip(float sample)
+{
+    return LEAF_softClip(sample, clipThreshold);
+}
+
+float lastOut;
+
+float   LEAFTest_tick            (float input)
+{
+    tCycle_setFreq(&test, freqVal);
+    float sample = tCycle_tick(&test);
+    
+    sample = tOversampler4x_tick(&os4, sample, &softClip);
+    
+    return sample * gain;
+}
+
+bool lastState = false, lastPlayState = false;
+void    LEAFTest_block           (void)
+{
+    clipThreshold = (1.f - getSliderValue("distortion")) * 0.3f;
+    gain = getSliderValue("gain") * 0.5f;
+    freqVal = getSliderValue("frequency") * 18000.f;
+}
+
+void    LEAFTest_controllerInput (int cnum, float cval)
+{
+
+}
+
+void    LEAFTest_pitchBendInput  (int pitchBend)
+{
+    
+}
+
+int lastNote;
+void    LEAFTest_noteOn          (int note, float velocity)
+{
+}
+
+
+void    LEAFTest_noteOff         (int note)
+{
+}
+
+
+
+void    LEAFTest_end             (void)
+{
+
+}
+
+// LEAF POOL UTILITIES
+
+void leaf_pool_report(void)
+{
+    DBG(String(leaf_pool_get_used()) + " of  " + String(leaf_pool_get_size()));
+}
+
+void leaf_pool_dump(void)
+{
+    float* buff = (float*)leaf_pool_get_pool();
+    int siz = leaf_pool_get_size();
+    siz /= sizeof(float);
+    for (int i = 0; i < siz; i++)
+    {
+        DBG(String(buff[i]));
+    }
+}
+
+static void run_pool_test(void)
+{
+    leaf_pool_report();
+    
+    DBG("ALLOC BUFFER 1");
+    int size = 50;
+    float* buffer;
+    buffer = (float*) leaf_alloc(sizeof(float) * size);
+    
+    for (int i = 0; i < size; i++)
+    {
+        buffer[i] = (float)i;
+        
+    }
+    
+    leaf_pool_report();
+    
+    DBG("ALLOC BUFFER 2");
+    size = 25;
+    
+    buffer = (float*) leaf_alloc(sizeof(float) * size);
+    
+    leaf_pool_report();
+    
+    for (int i = 0; i < size; i++)
+    {
+        buffer[i] = (float)(i*2);
+    }
+    leaf_free(buffer);
+    
+    leaf_pool_report();
+    
+    DBG("ALLOC BUFFER 3");
+    size = 15;
+    
+    buffer = (float*) leaf_alloc(sizeof(float) * size);
+    
+    for (int i = 0; i < size; i++)
+    {
+        buffer[i] = (float)(i*3);
+    }
+    
+    leaf_pool_report();
+    
+    leaf_pool_dump();
+}