shithub: leaf

Download patch

ref: c9f87b8761155abf2cab26cb809bcf89016697f3
parent: 82851635c27305a84ef549e65cf69567b1d15471
author: Matthew Wang <mjw7@princeton.edu>
date: Mon Jul 26 12:11:09 EDT 2021

use rintf/lrintf instead of int cast for MB oscs

--- a/leaf/Src/leaf-math.c
+++ b/leaf/Src/leaf-math.c
@@ -833,10 +833,10 @@
 void place_step_dd(float *buffer, int index, float phase, float w, float scale)
 {
     float r;
-    int i;
+    long i;
     
     r = MINBLEP_PHASES * phase / w;
-    i = r; //rintf(r - 0.5f); is there a reason to use rintf here?
+    i = lrintf(r - 0.5f);
     r -= (float)i;
     i &= MINBLEP_PHASE_MASK;  /* extreme modulation can cause i to be out-of-range */
     /* this would be better than the above, but more expensive:
@@ -857,10 +857,10 @@
 void place_slope_dd(float *buffer, int index, float phase, float w, float slope_delta)
 {
     float r;
-    int i;
+    long i;
     
     r = MINBLEP_PHASES * phase / w;
-    i = r;
+    i = lrintf(r - 0.5f);
     r -= (float)i;
     i &= MINBLEP_PHASE_MASK;  /* extreme modulation can cause i to be out-of-range */
     
--- a/leaf/Src/leaf-midi.c
+++ b/leaf/Src/leaf-midi.c
@@ -839,13 +839,9 @@
     int deactivatedVoice = -1;
 
     if (tStack_remove(&poly->stack, note))
-
     {
-
         poly->notes[note][0] = -2;
-
-
-
+        
         for (int i = 0; i < poly->maxNumVoices; i++)
         {
             if (poly->voices[i][0] == note)
@@ -856,8 +852,6 @@
                 break;
             }
         }
-
-
     }
     return deactivatedVoice;
 }
--- a/leaf/Src/leaf-oscillators.c
+++ b/leaf/Src/leaf-oscillators.c
@@ -1024,7 +1024,7 @@
     if (sync > 0.0f && c->softsync > 0) c->syncdir = -c->syncdir;
     
     sw = w * c->syncdir;
-    p += sw - (int)sw;
+    p += sw - rintf(sw - 0.5f);
     
     if (sync > 0.0f && c->softsync == 0) {  /* sync to master */
         float eof_offset = sync * sw;
@@ -1322,7 +1322,7 @@
     if (sync > 0.0f && c->softsync > 0) c->syncdir = -c->syncdir;
     
     sw = w * c->syncdir;
-    p += sw - (int)sw;
+    p += sw - rintf(sw - 0.5f);
     
     if (sync > 0.0f && c->softsync == 0) {  /* sync to master */
         float eof_offset = sync * sw;
@@ -1627,7 +1627,7 @@
     //            else if (sw < 0) place_slope_dd(c->_f, j, 1.0f - p, -sw, -2.0f);
     
     sw = w * c->syncdir;
-    p += sw - (int)sw;
+    p += sw - rintf(sw - 0.5f);
     
     if (sync > 0.0f && c->softsync == 0) {  /* sync to master */
         float eof_offset = sync * sw;