shithub: leaf

Download patch

ref: 84de0e3ed453a366ba9c90c8b53c0b4fabcf69bb
parent: ae6880a654ac3f83b542e17b6b83a0a0888a767f
parent: ad69b23d21b20df735bb9fb2bccad7ab0c907f07
author: Jeff Snyder <jeff@snyderphonics.com>
date: Mon Aug 5 12:47:50 EDT 2019

Merge branch 'master' of https://github.com/spiricom/leaf

--- 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-globals.h
+++ b/LEAF/Inc/leaf-globals.h
@@ -25,13 +25,13 @@
     float   invSampleRate;
     int     blockSize;
     
-    /*
+
     float*  sinewave;
     float*  sawtooth[11];
     float*  square[11];
     float*  triangle[11];
-     */
 
+
     float   (*random)(void);
 } LEAF;
     
@@ -57,7 +57,7 @@
                                             // Feel free to change to suit memory constraints or desired delay max length / functionality.
 
 
-
+#define TALKBOX_BUFFER_LENGTH   1600    // Every talkbox instance introduces 5 buffers of this size
     
 union unholy_t { /* a union between a float and an integer */
     float f;
--- a/LEAF/Inc/leaf-sample.h
+++ b/LEAF/Inc/leaf-sample.h
@@ -77,6 +77,7 @@
         
         float idx;
         float inc;
+        float last;
         float iinc;
         int8_t dir;
         int8_t flip;
--- 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-sample.c
+++ b/LEAF/Src/leaf-sample.c
@@ -141,8 +141,13 @@
 
 float tSampler_tick        (tSampler* const p)
 {
-    if (p->active == 0 || (p->len < 4))         return 0.f;
-    
+    if (p->active == 0)         return 0.f;
+
+    if ((p->inc == 0.0f) || (p->len < 4))
+    {
+    	return p->last;
+    }
+
     float sample = 0.f;
     float cfxsample = 0.f;
     int numsamps;
@@ -162,7 +167,7 @@
     }
     else
     {
-    	idx = (int) (p->idx + 1.f); // we think this is because flooring on int works different when reading backwards
+    	idx = (int) (p->idx+1.f); // we think this is because flooring on int works different when reading backwards
     	alpha = (p->idx+1.f) - idx;
     }
     
@@ -173,52 +178,53 @@
         end = p->start;
     }
     
-    // Check dir (direction) to interpolate properly
-    if (dir > 0)
+    // Check dir (direction) to interpolate properly
+    if (dir > 0)
+    {
+        // FORWARD NORMAL SAMPLE
+        int i1 = ((idx-1) + p->len) % p->len;
+        int i3 = (idx+1) % p->len;
+        int i4 = (idx+2) % p->len;
+
+        sample =     LEAF_interpolate_hermite (buff[i1],
+                                               buff[idx],
+                                               buff[i3],
+                                               buff[i4],
+                                               alpha);
+        
+        // num samples to end of loop
+        numsamps = (idx - start) / p->inc;
+        //numsamps = (dir > 0) ? (end - idx) : (idx - start);
+        //numsamps *= p->iinc;
+        
+        if (p->mode == PlayLoop)
+        {
+            if (numsamps <= p->cfxlen)
+            {
+                // CROSSFADE SAMPLE
+                float idxx =  p->idx - p->len;
+                int cdx = ((int)(idxx) + p->len) % p->len;
+                
+                i1 = ((cdx-1) + p->len) % p->len;
+                i3 = (cdx+1) % p->len;
+                i4 = (cdx+2) % p->len;
+                
+                cfxsample =     LEAF_interpolate_hermite (buff[i1],
+                                                          buff[cdx],
+                                                          buff[i3],
+                                                          buff[i4],
+                                                          alpha);
+                
+                g2 = (float) (p->cfxlen - numsamps) / (float) p->cfxlen;
+            }
+        }
+    }
+    else
     {
-        // FORWARD NORMAL SAMPLE
-        int i1 = idx-1;
-        int i3 = idx+1;
-        int i4 = idx+2;
-
-        sample =     LEAF_interpolate_hermite (buff[i1],
-                                               buff[idx],
-                                               buff[i3],
-                                               buff[i4],
-                                               alpha);
-        
-        // num samples to end of loop
-        numsamps = (dir > 0) ? (end - idx) : (idx - start);
-        numsamps *= p->iinc;
-        
-        if (p->mode == PlayLoop)
-        {
-            if (numsamps <= p->cfxlen)
-            {
-                // CROSSFADE SAMPLE
-                float idxx =  p->idx - p->len;
-                int cdx = (int)(idxx);
-                
-                i1 = cdx-1;
-                i3 = cdx+1;
-                i4 = cdx+2;
-                
-                cfxsample =     LEAF_interpolate_hermite (buff[i1],
-                                                          buff[cdx],
-                                                          buff[i3],
-                                                          buff[i4],
-                                                          alpha);
-                
-                g2 = (float) (p->cfxlen - numsamps) / (float) p->cfxlen;
-            }
-        }
-    }
-    else
-    {
-        // REVERSE
-        int i1 = idx+1;
-        int i3 = idx-1;
-        int i4 = idx-2;
+        // REVERSE
+        int i1 = (idx+1) % p->len;
+        int i3 = ((idx-1) + p->len) % p->len;
+        int i4 = ((idx-2) + p->len) % p->len;
     
         sample =     LEAF_interpolate_hermite (buff[i1],
                                                buff[idx],
@@ -234,12 +240,12 @@
             {
                 // CROSSFADE SAMPLE
                 float idxx =  p->idx + p->len + 1.f;
-                int cdx = (int)(idxx);
+                int cdx = ((int)(idxx)) % p->len;
                 alpha = idxx - cdx;
                 
-                i1 = cdx+1;
-                i3 = cdx-1;
-                i4 = cdx-2;
+                i1 = (cdx+1) % p->len;
+                i3 = ((cdx-1) + p->len) % p->len;
+                i4 = ((cdx-2) + p->len) % p->len;
                 
                 cfxsample =     LEAF_interpolate_hermite (buff[i1],
                                                           buff[cdx],
@@ -322,7 +328,9 @@
         }
     }
     
-    return sample;
+    p->last = sample;
+
+    return p->last;
 }
 
 void tSampler_setSample    (tSampler* const p, tBuffer* s)
binary files a/LEAF_JUCEPlugin/.DS_Store b/LEAF_JUCEPlugin/.DS_Store differ
--- a/LEAF_JUCEPlugin/JuceLibraryCode/AppConfig.h
+++ b/LEAF_JUCEPlugin/JuceLibraryCode/AppConfig.h
@@ -451,6 +451,12 @@
 #ifndef  JucePlugin_IAAName
  #define JucePlugin_IAAName                "pumusic: LEAF"
 #endif
+#ifndef  JucePlugin_VSTNumMidiInputs
+ #define JucePlugin_VSTNumMidiInputs       16
+#endif
+#ifndef  JucePlugin_VSTNumMidiOutputs
+ #define JucePlugin_VSTNumMidiOutputs      16
+#endif
 #ifndef  JucePlugin_MaxNumInputChannels
  #define JucePlugin_MaxNumInputChannels    2
 #endif
--- a/LEAF_JUCEPlugin/LEAF.jucer
+++ b/LEAF_JUCEPlugin/LEAF.jucer
@@ -8,7 +8,7 @@
               pluginIsSynth="0" pluginWantsMidiIn="1" pluginProducesMidiOut="0"
               pluginIsMidiEffectPlugin="0" pluginEditorRequiresKeys="0" pluginAUExportPrefix="LEAFAU"
               pluginRTASCategory="" aaxIdentifier="com.pumusic.LEAF" pluginAAXCategory="2"
-              jucerVersion="5.4.1" companyName="Princeton University" companyEmail="mrmulshine@gmail.com"
+              jucerVersion="5.4.3" companyName="Princeton University" companyEmail="mrmulshine@gmail.com"
               displaySplashScreen="1" reportAppUsage="1" splashScreenColour="Dark"
               buildStandalone="1" enableIAA="0" cppLanguageStandard="11" companyCopyright="Princeton University"
               pluginFormats="buildVST,buildAU,buildStandalone" pluginCharacteristicsValue="pluginWantsMidiIn">
--- a/LEAF_JUCEPlugin/Source/LEAFLink.cpp
+++ b/LEAF_JUCEPlugin/Source/LEAFLink.cpp
@@ -15,14 +15,13 @@
 
 std::vector<juce::String> cButtonNames =  std::vector<juce::String>
 {
-
+    "record"
 };
 
 std::vector<juce::String> cSliderNames =  std::vector<juce::String>
 {
-    "gain",
-    "frequency",
-    "distortion"
+    "mod freq",
+    "mod depth"
 };
 
 std::vector<juce::String> cComboBoxNames =  std::vector<juce::String>
--- a/LEAF_JUCEPlugin/Source/MyTest.cpp
+++ b/LEAF_JUCEPlugin/Source/MyTest.cpp
@@ -1,153 +1,194 @@
-/*
-  ==============================================================================
+/*
+  ==============================================================================
+
+    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 mix = 0.f;
+float fx = 1.f;
+
+#define NUM_GRAINS 20
+
+
+
+tTapeDelay delay;
+
+float feedback = 0.f;
+
+tBuffer buff;
+tSampler samp;
 
-    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);
+tCycle osc;
+
+void    LEAFTest_init            (float sampleRate, int blockSize)
+{
+    LEAF_init(sampleRate, blockSize, &getRandomFloat);
+    
+    // Init and set record
+    tBuffer_init (&buff, leaf.sampleRate * 1.f); // init, 1 second buffer
+    tBuffer_setRecordMode (&buff, RecordOneShot); // RecordOneShot records once through
+    tBuffer_record(&buff); // starts recording
+
+    // Init and set play
+    tSampler_init (&samp, &buff); // init, give address of record buffer
+    tSampler_setMode (&samp, PlayLoop); //set in Loop Mode
+    tSampler_setRate(&samp, 1.f); // Rate of 1.0
+    tSampler_play(&samp); // start spitting samples out
     
-    leaf_pool_report();
+    tCycle_init(&osc);
+    
+    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);
+float depth = 1.0f;
+
+float   LEAFTest_tick            (float input)
+{
+    float sample = 0.f;
+    
+    tBuffer_tick(&buff, input); // ticking the buffer records in to buffer
     
-    sample = tOversampler4x_tick(&os4, sample, &softClip);
+    tSampler_setRate(&samp, tCycle_tick(&osc) * depth);
+
+    // dont tick sampler if buffer not active (not recording)
+    if (buff.active == 0)
+    {
+        sample = tSampler_tick(&samp); // ticking sampler loops sample
+    }
+    
+    
+    return sample;
+}
+
+bool lastState = false, lastPlayState = false;
+void    LEAFTest_block           (void)
+{
+    bool state = getButtonState("record");
     
-    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++)
+    if (state)
     {
-        DBG(String(buff[i]));
+        setButtonState("record", false);
+        tBuffer_record(&buff);
     }
-}
-
-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);
+    float val = getSliderValue("mod freq");
     
-    for (int i = 0; i < size; i++)
-    {
-        buffer[i] = (float)i;
-        
-    }
+    float freq = 0.1 + 999.9 * val;
     
-    leaf_pool_report();
+    tCycle_setFreq(&osc, freq);
     
-    DBG("ALLOC BUFFER 2");
-    size = 25;
+    DBG("mod freq: " + String(freq));
     
-    buffer = (float*) leaf_alloc(sizeof(float) * size);
+    val = getSliderValue("mod depth");
     
-    leaf_pool_report();
+    depth = 0.1 + val * 15.9f;
     
-    for (int i = 0; i < size; i++)
-    {
-        buffer[i] = (float)(i*2);
-    }
-    leaf_free(buffer);
+    DBG("mod depth: " + String(depth));
     
-    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();
-}
+
+}
+
+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();
+}
+