shithub: leaf

Download patch

ref: 2799e97c9f413e8e5880dfde9b8f6500ffee4685
parent: 67b440210f238511a2f30b1da044a6f5457d5b32
author: Davis Polito <davispolito1@gmail.com>
date: Mon Aug 22 12:25:21 EDT 2022

Fix SquareLFO

--- a/leaf/Inc/leaf-oscillators.h
+++ b/leaf/Inc/leaf-oscillators.h
@@ -1277,10 +1277,11 @@
         
         tMempool mempool;
         uint32_t phase;
-        uint32_t inc, freq;
-        uint32_t mask;
+        uint32_t inc;
+        float freq;
+        int32_t mask;
         uint8_t phaseDidReset;
-        uint32_t invSampleRateTimesTwoTo32;
+        int32_t invSampleRateTimesTwoTo32;
     } _tIntPhasor;
     
     typedef _tIntPhasor* tIntPhasor;
--- a/leaf/Src/leaf-filters.c
+++ b/leaf/Src/leaf-filters.c
@@ -1307,7 +1307,7 @@
     f->s2   = 0.0f;
     f->R2   = f->invG;
     f->R2Plusg = f->R2 + f->g;
-    tVZFilter_setBandwidth(vf,f->B);
+    //tVZFilter_setBandwidth(vf,f->B);
     tVZFilter_calcCoeffs(vf);
 }
 
--- a/leaf/Src/leaf-oscillators.c
+++ b/leaf/Src/leaf-oscillators.c
@@ -2545,7 +2545,7 @@
     
     c->phase    =  0;
     c->invSampleRateTimesTwoTo32 = (leaf->invSampleRate * TWO_TO_32);
-    c->mask = 0xFFFFFFFF;
+    c->mask = 0x7FFFFFFF;
 }
 
 void    tIntPhasor_free (tIntPhasor* const cy)
@@ -2560,7 +2560,7 @@
 {
     _tIntPhasor* c = *cy;
     // Phasor increment
-    c->phase = (c->phase + c->inc) & c->mask;
+    c->phase = (c->phase + c->inc);//& c->mask;
     
     return c->phase * INV_TWO_TO_32; 
 }
@@ -2624,8 +2624,10 @@
 {
     _tSquareLFO* c = *cy;
     // Phasor increment
-    
-    return tIntPhasor_tick(&c->phasor) + tIntPhasor_tick(&c->invPhasor);
+    float a = tIntPhasor_tick(&c->phasor);
+    float b = tIntPhasor_tick(&c->invPhasor);
+    float tmp = ((a - b)) + c->pulsewidth - 1.0f;
+    return 2 * tmp;
 }
 
 void     tSquareLFO_setFreq(tSquareLFO* const cy, float freq)
@@ -2632,7 +2634,7 @@
 {
     _tSquareLFO* c = *cy;
     tIntPhasor_setFreq(&c->phasor,freq);
-    tIntPhasor_setFreq(&c->invPhasor,-freq);
+    tIntPhasor_setFreq(&c->invPhasor,freq);
 }
 
 
@@ -2650,5 +2652,5 @@
 
     c->pulsewidth = pw;
     //c->delay = c->pulsewidth * INV_TWO_TO_32;
-    tIntPhasor_setPhase(&c->invPhasor, c->pulsewidth);
+    tIntPhasor_setPhase(&c->invPhasor, c->pulsewidth + (c->phasor->phase * INV_TWO_TO_32));
 }