shithub: leaf

Download patch

ref: 8190e1637f5dbe57388711c6c994ed3be13d3474
parent: 4c40a1ff45a4e04f64f7692c2d3a3523ee51a453
author: Jeffrey Snyder <jeffsnyder@jeffreys-mbp.mynetworksettings.com>
date: Wed Aug 24 13:13:53 EDT 2022

fixed phase of triangle LFO

--- a/leaf/Inc/leaf-math.h
+++ b/leaf/Inc/leaf-math.h
@@ -93,6 +93,9 @@
 #define INV_TWO_TO_31    0.000000000465661f
 #define TWO_TO_32        4294967296.0f
 #define INV_TWO_TO_32    0.000000000232831f
+
+#define TWO_TO_32_INT        4294967296u
+#define TWO_TO_31_INT        2147483648u
     
 #define ONE_OVER_SQRT2  0.707106781186548f
 
--- a/leaf/Src/leaf-oscillators.c
+++ b/leaf/Src/leaf-oscillators.c
@@ -3046,8 +3046,9 @@
     
     //bitmask fun
     //
-    uint32_t mask = c->phase >> 31;
-    int32_t val2 = c->phase + mask;
+    int32_t shiftedPhase = c->phase + 1073741824; // offset by 1/4" wave by adding 2^30 to get things in phase with the other LFO oscillators
+    uint32_t mask = shiftedPhase >> 31;
+    int32_t val2 = shiftedPhase + mask;
     int32_t test = val2 ^ mask;
     float output =( ((float)test * INV_TWO_TO_31)-0.5f) * 2.0f;
     return output;
@@ -3083,7 +3084,7 @@
     
     int i = phase;
     phase -= i;
-    c->phase = phase * TWO_TO_32;
+    c->phase = phase * TWO_TO_32_INT;
 }
 
 void     tTriLFO_setSampleRate (tTriLFO* const cy, float sr)
@@ -3124,7 +3125,7 @@
     _tSineTriLFO* c = *cy;
     float a = tCycle_tick(&c->sine);
     float b = tTriLFO_tick(&c->tri);
-    return  (1 - c->shape) * a + c->shape * -1.0f * b; 
+    return  (1.0f - c->shape) * a + c->shape * b;
 }
 void    tSineTriLFO_setFreq     (tSineTriLFO* const cy, float freq)
 {