shithub: leaf

Download patch

ref: 327ba3d40f2a118c79820438ee1ccc430895f6b9
parent: 7acbedad6373746a444acdb7f959c4602cc561b6
author: Matthew Wang <mjw7@princeton.edu>
date: Mon Aug 3 13:26:32 EDT 2020

pitch detector testing

--- a/TestPlugin/LEAF.jucer
+++ b/TestPlugin/LEAF.jucer
@@ -106,7 +106,7 @@
     </GROUP>
   </MAINGROUP>
   <EXPORTFORMATS>
-    <XCODE_MAC targetFolder="Builds/MacOSX">
+    <XCODE_MAC targetFolder="Builds/MacOSX" microphonePermissionNeeded="1">
       <CONFIGURATIONS>
         <CONFIGURATION name="Debug" isDebug="1" optimisation="1" targetName="OOPS" enablePluginBinaryCopyStep="1"/>
         <CONFIGURATION name="Release" isDebug="0" optimisation="3" targetName="OOPS"
--- a/TestPlugin/Source/MyTest.cpp
+++ b/TestPlugin/Source/MyTest.cpp
@@ -82,6 +82,7 @@
     
 }
 
+float lastFreq;
 float   LEAFTest_tick            (float input)
 {
 //    tMBSaw_setFreq(&bsaw, x);
@@ -96,25 +97,25 @@
 //    return tMBPulse_tick(&bpulse);
 
     
-    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);
-        }
+    float freq = 1.0f/tPeriodDetection_tick(&pd, input) * leaf.sampleRate;
+    tPitchDetector_tick(&detector, input);
     
+    if (tPitchDetector_getPeriodicity(&detector) > 0.0)
+    {
+        float altFreq = tPitchDetector_getFrequency(&detector);
+        if (fabsf(lastFreq - freq) > fabsf(lastFreq - altFreq))
+            freq = altFreq;
     }
-    else
+    
+    if (tZeroCrossing_tick(&zc, input) < 0.05 && freq > 0.0f)
     {
-        float freq = 1.0f/tPeriodDetection_tick(&pd, input) * leaf.sampleRate;
-        if (tZeroCrossing_tick(&zc, input) < 0.05)
-            tMBTriangle_setFreq(&btri, freq);
+        tMBTriangle_setFreq(&btri, freq);
     }
 
     float g = tEnvelopeFollower_tick(&ef, input);
+    
+    lastFreq = freq;
+    
     return input + tMBTriangle_tick(&btri) * g * 10.0f;
 }
 
--- a/leaf/Src/leaf-analysis.c
+++ b/leaf/Src/leaf-analysis.c
@@ -1456,8 +1456,9 @@
             count += __builtin_popcount(*p1++ ^ *p2++);
 #elif _MSC_VER
             count += __popcnt(*p1++ ^ *p2++);
-#endif
+#else
             count += popcount(*p1++ ^ *p2++);
+#endif
         }
     }
     else
@@ -1468,11 +1469,12 @@
             unsigned int v = *p2++ >> shift;
             v |= *p2 << shift2;
 #ifdef __GNUC__
-            count += __builtin_popcount(*p1++ ^ *p2++);
+            count += __builtin_popcount(*p1++ ^ v++);
 #elif _MSC_VER
-            count += __popcnt(*p1++ ^ *p2++);
+            count += __popcnt(*p1++ ^ v++);
+#else
+            count += popcount(*p1++ ^ v++);
 #endif
-            count += popcount(*p1++ ^ *p2++);
         }
     }
     return count;
@@ -1906,6 +1908,13 @@
     _tPitchDetector* p = *detector;
     
     return p->_pd->_period_info[1];
+}
+
+float   tPitchDetector_harmonic (tPitchDetector* const detector, int harmonicIndex)
+{
+    _tPitchDetector* p = *detector;
+    
+    return tPeriodDetector_harmonic(&p->_pd, harmonicIndex);
 }
 
 float   tPitchDetector_predictFrequency (tPitchDetector* const detector, int init)