shithub: leaf

Download patch

ref: 65a3aed39e922745d4a920266a0316c97c36e386
parent: 9862cbb37265bedd87834d358376b47553d33162
author: Matthew Wang <mjw7@princeton.edu>
date: Thu Jul 16 13:55:04 EDT 2020

bacf testing

--- a/TestPlugin/Source/MyTest.cpp
+++ b/TestPlugin/Source/MyTest.cpp
@@ -37,8 +37,10 @@
 
 tPeriodDetection pd;
 
+tZeroCrossing zc;
+tEnvelopeFollower ef;
+
 float gain;
-float freq;
 float dtime;
 bool buttonState;
 int ratio = 2;
@@ -46,8 +48,8 @@
 float y = 0.0f;
 float a, b, c, d;
 
-float bufIn[4096];
-float bufOut[4096];
+float* bufIn;
+float* bufOut;
 
 #define MSIZE 500000
 char memory[MSIZE];
@@ -60,11 +62,15 @@
     tMBTriangle_init(&btri);
     tMBPulse_init(&bpulse);
     
-    
+    bufIn = (float*) leaf_alloc(sizeof(float) * 4096);
+    bufOut = (float*) leaf_alloc(sizeof(float) * 4096);
     // lowestFreq, highestFreq, hysteresis (width of hysteresis region around 0.0 for zero crossing detection)
     tPitchDetector_init(&detector, mtof(48), mtof(84), 0.01f);
     
     tPeriodDetection_init(&pd, bufIn, bufOut, 4096, 1024);
+    
+    tZeroCrossing_init(&zc, 128);
+    tEnvelopeFollower_init(&ef, 0.02f, 0.9999f);
 }
 
 inline double getSawFall(double angle) {
@@ -88,15 +94,28 @@
 ////    return tMBSaw_tick(&bsaw);
 ////    return tMBTriangle_tick(&btri);
 //    return tMBPulse_tick(&bpulse);
+
     
-    tPitchDetector_tick(&detector, input);
+    if (x > 0.5)
+    {
+        tPitchDetector_tick(&detector, input);
+        if (tPitchDetector_getPeriodicity(&detector) > 0.99 &&  (tZeroCrossing_tick(&zc, input) < 0.05))
+        {
+            float freq = tPitchDetector_getFrequency(&detector);
+            if (freq != 0.0f)
+                tMBTriangle_setFreq(&btri, freq);
+        }
     
-    tMBTriangle_setFreq(&btri, tPitchDetector_getFrequency(&detector));
-    
-//    float freq = 1.0f/tPeriodDetection_tick(&pd, input) * leaf.sampleRate;
-//    tMBTriangle_setFreq(&btri, freq);
+    }
+    else
+    {
+        float freq = 1.0f/tPeriodDetection_tick(&pd, input) * leaf.sampleRate;
+        if (tZeroCrossing_tick(&zc, input) < 0.05)
+            tMBTriangle_setFreq(&btri, freq);
+    }
 
-    return tMBTriangle_tick(&btri);// * 0.25;
+    float g = tEnvelopeFollower_tick(&ef, input);
+    return input + tMBTriangle_tick(&btri) * g * 10.0f;
 }
 
 int firstFrame = 1;
@@ -114,7 +133,9 @@
     
     float val = getSliderValue("mod freq");
     
-    x = val * 20000.0f + 220.0f;
+    x = val;
+    
+        
     
     //    a = val * tBuffer_getBufferLength(&buff);
     
--- a/TestPlugin/Source/PluginProcessor.cpp
+++ b/TestPlugin/Source/PluginProcessor.cpp
@@ -86,7 +86,6 @@
         }
     }
     
-
    const float* inPointerL = buffer.getReadPointer (0);
    const float* inPointerR = buffer.getReadPointer (1);
     
@@ -95,7 +94,7 @@
     
     for (int samp = 0; samp < buffer.getNumSamples(); ++samp)
     {
-        outPointerL[samp] = LEAFTest_tick( (inPointerL[samp] +inPointerR[samp]) * 0.5f);
+        outPointerL[samp] = LEAFTest_tick( (inPointerL[samp] ));
         outPointerR[samp] = outPointerL[samp];
     }
 }