shithub: leaf

Download patch

ref: a3746888080f34c0618ec8da0a29eafbc92057ea
parent: a0b0b7915cce3792ea00f06d0a6861be1a73d609
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Tue Mar 7 06:47:09 EST 2023

plan 9 port

--- a/leaf/Externals/d_fft_mayer.c
+++ b/leaf/Externals/d_fft_mayer.c
@@ -69,7 +69,7 @@
 #if defined(GOOD_TRIG)
 #define FHT_SWAP(a,b,t) {(t)=(a);(a)=(b);(b)=(t);}
 #define TRIG_VARS                                                \
-      int t_lam=0;
+      int t_lam=0; USED(t_lam);
 #define TRIG_INIT(k,c,s)                                         \
      {                                                           \
       int i;                                                     \
@@ -76,8 +76,8 @@
       for (i=2 ; i<=k ; i++)                                     \
           {coswrk[i]=costab[i];sinwrk[i]=sintab[i];}             \
       t_lam = 0;                                                 \
-      c = 1;                                                     \
-      s = 0;                                                     \
+      c = 1; USED(c);                                            \
+      s = 0; USED(s);                                            \
      }
 #define TRIG_NEXT(k,c,s)                                         \
      {                                                           \
--- /dev/null
+++ b/leaf/Externals/plan9/plan9.c
@@ -1,0 +1,73 @@
+#include <stdio.h>
+
+int
+isinf(double d)
+{
+	if(isInf(d, 0) == 0)
+		return 0;
+
+	return isInf(d, -1) ? -1 : 1;
+}
+
+int
+lrintf(float f)
+{
+	int i;
+
+	*((float*)&i) = f + 12582912.0f;
+
+	return (i & 0x7fffff) - 0x400000;
+}
+
+#define ln2o1 1.4426950408889634073599
+#define hugeF 3.4028234e+38
+#define hugeD 1.79769313486231e+308
+
+double
+log2(double x)
+{
+	if(x == 0)
+		return -hugeD;
+	if(x < 0 || isNaN(x))
+		return NaN();
+
+	return log(x)*ln2o1;
+}
+
+float
+log2f(float x)
+{
+	if(x == 0)
+		return -hugeF;
+
+	return log2(x);
+}
+
+/* taken from musl */
+#define dbleps 2.2204460492503131e-16
+static double toint = 1.0/dbleps;
+double
+round(double x)
+{
+	union {double f; u64int i;} u = {x};
+	int e = u.i >> 52 & 0x7ff;
+	double y;
+
+	if(e >= 0x3ff+52)
+		return x;
+	if(u.i >> 63)
+		x = -x;
+	if(e < 0x3ff-1)
+		return 0*u.f;
+	y = x + toint - toint - x;
+	if(y > 0.5)
+		y = y + x - 1;
+	else if(y <= -0.5)
+		y = y + x + 1;
+	else
+		y = y + x;
+	if(u.i >> 63)
+		y = -y;
+
+	return y;
+}
--- /dev/null
+++ b/leaf/Externals/plan9/stdio.h
@@ -1,0 +1,55 @@
+#ifndef _plan9_stdio_h_
+#define _plan9_stdio_h_
+
+#include <u.h>
+#include <libc.h>
+#include </sys/include/stdio.h>
+
+#define cosf cos
+#define sinf sin
+#define expf exp
+#define logf log
+#define powf pow
+#define tanf tan
+#define fmodf fmod
+#define sqrtf sqrt
+#define isnan isNaN
+#define acosf acos
+#define atanf atan
+#define atan2f atan2
+#define tanhf tanh
+#define fabsf fabs
+#define roundf round
+#define frexpf frexp
+#define log10f log10
+
+#define fmax(a,b) ((a)>(b)?(a):(b))
+#define fmin(a,b) ((a)<(b)?(a):(b))
+#define fmaxf fmax
+#define fminf fmin
+
+#define isfinite(x) (!isinf(x))
+
+typedef usize size_t;
+typedef u8int uint8_t;
+typedef s8int int8_t;
+typedef u16int uint16_t;
+typedef s16int int16_t;
+typedef u32int uint32_t;
+typedef s32int int32_t;
+typedef u64int uint64_t;
+typedef uintptr uintptr_t;
+
+#define CHAR_BIT 8
+#define INT_MAX  0x7fffffff
+#define INT_MIN (-INT_MAX-1)
+#define UINT_MAX 0xffffffffU
+#define UINT16_MAX 0xffff
+
+int isinf(double d);
+int lrintf(float f);
+double log2(double x);
+float log2f(float x);
+double round(double x);
+
+#endif
--- a/leaf/Inc/leaf-math.h
+++ b/leaf/Inc/leaf-math.h
@@ -36,7 +36,9 @@
 #define SQRT8 2.82842712475f
 #define LEAF_SQRT2 1.41421356237f
 #define WSCALE 1.30612244898f
+#ifndef PI
 #define PI              (3.14159265358979f)
+#endif
 #define TWO_PI          (6.28318530717958f)
 #define HALF_PI         (1.570796326794897f)
 
--- a/leaf/Src/leaf-analysis.c
+++ b/leaf/Src/leaf-analysis.c
@@ -124,7 +124,7 @@
     
     z->inBuffer[z->position] = input;
     int futurePosition = ((z->position + 1) % z->currentWindowSize);
-    float output = 0.0f;
+    float output;
     
     //add new value to count
     if ((z->inBuffer[z->position] * z->inBuffer[z->prevPosition]) < 0.0f)
@@ -438,7 +438,7 @@
 {
     _tAttackDetection* a = *ad;
     
-    int i = 0;
+    int i;
     float tmp;
     for(i = 0; i < a->blockSize; ++i){
         tmp = fastabsf(in[i]);
@@ -1124,7 +1124,7 @@
     return z->_state;
 }
 
-tZeroCrossingInfo const tZeroCrossingCollector_getCrossing(tZeroCrossingCollector* const zc, int index)
+tZeroCrossingInfo tZeroCrossingCollector_getCrossing(tZeroCrossingCollector* const zc, int index)
 {
     _tZeroCrossingCollector* z = *zc;
     
@@ -1487,7 +1487,7 @@
 #elif _MSC_VER
             count += __popcnt(*p1++ ^ v++);
 #else
-            count += popcount(*p1++ ^ v++);
+            count += popcount(*p1++ ^ v++); USED(count); USED(v);
 #endif
         }
     }
@@ -1675,7 +1675,7 @@
 {
     _tPeriodDetector* p = *detector;
     
-    return tZeroCrossingCollector_setHysteresis(&p->_zc, hysteresis);
+    tZeroCrossingCollector_setHysteresis(&p->_zc, hysteresis);
 }
 
 void    tPeriodDetector_setSampleRate   (tPeriodDetector* const detector, float sr)
@@ -2196,7 +2196,7 @@
     if (ready)
     {
         int pd2_indeterminate = tPitchDetector_indeterminate(&p->_pd2);
-        int disagreement = 0;
+        int disagreement;
         float period = tPeriodDetection_getPeriod(&p->_pd1);
         if (!pd2_indeterminate && period != 0.0f)
         {
--- a/leaf/Src/leaf-distortion.c
+++ b/leaf/Src/leaf-distortion.c
@@ -513,7 +513,7 @@
 {
     _tLockhartWavefolder* w = *wf;
 
-    float out = 0.0f;
+    float out;
     
     // Compute Antiderivative
     w->l = (in > 0.0) - (in < 0.0);
--- a/leaf/Src/leaf-dynamics.c
+++ b/leaf/Src/leaf-dynamics.c
@@ -86,7 +86,7 @@
     float slope, overshoot;
     
     float in_db = LEAF_clip(-90.0f, fasteratodb(fastabsf(in)), 0.0f);
-    float out_db = 0.0f;
+    float out_db;
     
     c->y_T[1] = c->y_T[0];
     
--- a/leaf/Src/leaf-effects.c
+++ b/leaf/Src/leaf-effects.c
@@ -149,7 +149,6 @@
     Rt[0]=0;
     r1=0;
     r2=0;
-    r1t=0;
     for(uint32_t m=0; m<L;m++)
     {
                     Rt[0] += (double)(x[m]) * (double)(x[m]);
@@ -243,7 +242,7 @@
         if(++p0 >= v->N) { tTalkbox_lpc(v->buf0, v->car0, v->dl, v->Rt, v->N, v->O, v->warpFactor, v->warpOn, v->k, v->freeze, &v->G);  p0 = 0; }
         
         w = 1.0f - w;  fx += v->buf1[p1] * w;  v->buf1[p1] = x * w;
-        if(++p1 >= v->N) { tTalkbox_lpc(v->buf1, v->car1, v->dl, v->Rt, v->N, v->O, v->warpFactor, v->warpOn, v->k, v->freeze, &v->G);  p1 = 0; }
+        if(++p1 >= v->N) { tTalkbox_lpc(v->buf1, v->car1, v->dl, v->Rt, v->N, v->O, v->warpFactor, v->warpOn, v->k, v->freeze, &v->G); }
     }
     
     p = v->u0 + h0 * fx; v->u0 = v->u1;  v->u1 = fx - h0 * p;
@@ -487,7 +486,6 @@
     Rt[0]=0;
     r1=0;
     r2=0;
-    r1t=0;
     for(uint32_t m=0; m<L;m++)
     {
                     Rt[0] += (x[m]) * (x[m]);
@@ -582,7 +580,7 @@
         if(++p0 >= v->N) { tTalkboxFloat_lpc(v->buf0, v->car0, v->dl, v->Rt, v->N, v->O, v->warpFactor, v->warpOn, v->k, v->freeze, &v->G);  p0 = 0; }
 
         w = 1.0f - w;  fx += v->buf1[p1] * w;  v->buf1[p1] = x * w;
-        if(++p1 >= v->N) { tTalkboxFloat_lpc(v->buf1, v->car1, v->dl, v->Rt, v->N, v->O, v->warpFactor, v->warpOn, v->k, v->freeze, &v->G);  p1 = 0; }
+        if(++p1 >= v->N) { tTalkboxFloat_lpc(v->buf1, v->car1, v->dl, v->Rt, v->N, v->O, v->warpFactor, v->warpOn, v->k, v->freeze, &v->G); }
     }
 
     p = v->u0 + h0 * fx; v->u0 = v->u1;  v->u1 = fx - h0 * p;
@@ -826,7 +824,7 @@
 {
     _tVocoder* v = *voc;
     
-    float a, b, o=0.0f, aa, bb, oo = v->kout, g = v->gain, ht = v->thru, hh = v->high, tmp;
+    float a, b, o, aa, bb, oo = v->kout, g = v->gain, ht = v->thru, hh = v->high, tmp;
     uint32_t i, k = v->kval, nb = v->nbnd;
     
     a = voice; //speech
@@ -940,7 +938,7 @@
 {
     _tRosenbergGlottalPulse* g = *gp;
 
-    float output = 0.0f;
+    float output;
 
     // Phasor increment
     g->phase += g->inc;
@@ -969,7 +967,7 @@
 {
     _tRosenbergGlottalPulse* g = *gp;
 
-    float output = 0.0f;
+    float output;
 
     // Phasor increment
     g->phase += g->inc;
@@ -1518,7 +1516,7 @@
         tPitchShift_initToPool(&r->ps[i], &r->dp, r->bufSize, mp);
     }
     
-    r->shiftFunction = &tPitchShift_shiftBy;
+    r->shiftFunction = tPitchShift_shiftBy;
 }
 
 void tSimpleRetune_free (tSimpleRetune* const rt)
@@ -1564,8 +1562,8 @@
 {
     _tSimpleRetune* r = *rt;
     
-    if (mode > 0) r->shiftFunction = &tPitchShift_shiftTo;
-    else r->shiftFunction = &tPitchShift_shiftBy;
+    if (mode > 0) r->shiftFunction = tPitchShift_shiftTo;
+    else r->shiftFunction = tPitchShift_shiftBy;
 }
 
 void tSimpleRetune_setNumVoices(tSimpleRetune* const rt, int numVoices)
@@ -1663,7 +1661,7 @@
         r->outBuffers[i] = (float*) mpool_calloc(sizeof(float) * r->bufSize, m);
     }
     
-    r->shiftFunction = &tPitchShift_shiftBy;
+    r->shiftFunction = tPitchShift_shiftBy;
 }
 
 void tRetune_free (tRetune* const rt)
@@ -1715,8 +1713,8 @@
 {
     _tRetune* r = *rt;
     
-    if (mode > 0) r->shiftFunction = &tPitchShift_shiftTo;
-    else r->shiftFunction = &tPitchShift_shiftBy;
+    if (mode > 0) r->shiftFunction = tPitchShift_shiftTo;
+    else r->shiftFunction = tPitchShift_shiftBy;
 }
 
 void tRetune_setPickiness (tRetune* const rt, float p)
--- a/leaf/Src/leaf-electrical.c
+++ b/leaf/Src/leaf-electrical.c
@@ -71,9 +71,9 @@
         r->port_resistance_up = r->value;
         r->port_conductance_up = 1.0f / r->value;
         
-        r->get_port_resistance = &get_port_resistance_for_resistor;
-        r->get_reflected_wave_up = &get_reflected_wave_for_resistor;
-        r->set_incident_wave = &set_incident_wave_for_leaf;
+        r->get_port_resistance = get_port_resistance_for_resistor;
+        r->get_reflected_wave_up = get_reflected_wave_for_resistor;
+        r->set_incident_wave = set_incident_wave_for_leaf;
     }
     else if (r->type == Capacitor)
     {
@@ -80,9 +80,9 @@
         r->port_conductance_up = r->sample_rate * 2.0f * r->value;
         r->port_resistance_up = 1.0f / r->port_conductance_up; //based on trapezoidal discretization
         
-        r->get_port_resistance = &get_port_resistance_for_capacitor;
-        r->get_reflected_wave_up = &get_reflected_wave_for_capacitor;
-        r->set_incident_wave = &set_incident_wave_for_leaf;
+        r->get_port_resistance = get_port_resistance_for_capacitor;
+        r->get_reflected_wave_up = get_reflected_wave_for_capacitor;
+        r->set_incident_wave = set_incident_wave_for_leaf;
     }
     else if (r->type == Inductor)
     {
@@ -89,9 +89,9 @@
         r->port_resistance_up = r->sample_rate * 2.0f * r->value; //based on trapezoidal discretization
         r->port_conductance_up = 1.0f / r->port_resistance_up;
         
-        r->get_port_resistance = &get_port_resistance_for_inductor;
-        r->get_reflected_wave_up = &get_reflected_wave_for_capacitor; // same as capacitor
-        r->set_incident_wave = &set_incident_wave_for_leaf_inverted;
+        r->get_port_resistance = get_port_resistance_for_inductor;
+        r->get_reflected_wave_up = get_reflected_wave_for_capacitor; // same as capacitor
+        r->set_incident_wave = set_incident_wave_for_leaf_inverted;
     }
     else if (r->type == ResistiveSource)
     {
@@ -98,9 +98,9 @@
         r->port_resistance_up = r->value;
         r->port_conductance_up = 1.0f / r->port_resistance_up;
         
-        r->get_port_resistance = &get_port_resistance_for_resistive;
-        r->get_reflected_wave_up = &get_reflected_wave_for_resistive;
-        r->set_incident_wave = &set_incident_wave_for_leaf;
+        r->get_port_resistance = get_port_resistance_for_resistive;
+        r->get_reflected_wave_up = get_reflected_wave_for_resistive;
+        r->set_incident_wave = set_incident_wave_for_leaf;
     }
     else if (r->type == Inverter)
     {
@@ -107,9 +107,9 @@
         r->port_resistance_up = tWDF_getPortResistance(r->child_left);
         r->port_conductance_up = 1.0f / r->port_resistance_up;
         
-        r->get_port_resistance = &get_port_resistance_for_inverter;
-        r->get_reflected_wave_up = &get_reflected_wave_for_inverter;
-        r->set_incident_wave = &set_incident_wave_for_inverter;
+        r->get_port_resistance = get_port_resistance_for_inverter;
+        r->get_reflected_wave_up = get_reflected_wave_for_inverter;
+        r->set_incident_wave = set_incident_wave_for_inverter;
     }
     else if (r->type == SeriesAdaptor)
     {
@@ -121,9 +121,9 @@
         r->port_conductance_right = 1.0f / r->port_resistance_right;
         r->gamma_zero = 1.0f / (r->port_resistance_right + r->port_resistance_left);
         
-        r->get_port_resistance = &get_port_resistance_for_series;
-        r->get_reflected_wave_up = &get_reflected_wave_for_series;
-        r->set_incident_wave = &set_incident_wave_for_series;
+        r->get_port_resistance = get_port_resistance_for_series;
+        r->get_reflected_wave_up = get_reflected_wave_for_series;
+        r->set_incident_wave = set_incident_wave_for_series;
     }
     else if (r->type == ParallelAdaptor)
     {
@@ -135,9 +135,9 @@
         r->port_conductance_right = 1.0f / r->port_resistance_right;
         r->gamma_zero = 1.0f / (r->port_resistance_right + r->port_resistance_left);
         
-        r->get_port_resistance = &get_port_resistance_for_parallel;
-        r->get_reflected_wave_up = &get_reflected_wave_for_parallel;
-        r->set_incident_wave = &set_incident_wave_for_parallel;
+        r->get_port_resistance = get_port_resistance_for_parallel;
+        r->get_reflected_wave_up = get_reflected_wave_for_parallel;
+        r->set_incident_wave = set_incident_wave_for_parallel;
     }
     else if (r->type == IdealSource)
     {
@@ -144,8 +144,8 @@
         r->port_resistance_up = tWDF_getPortResistance(child);
         r->port_conductance_up = 1.0f / r->port_resistance_up;
         
-        r->get_reflected_wave_down = &get_reflected_wave_for_ideal;
-        r->get_port_resistance = &get_port_resistance_for_root;
+        r->get_reflected_wave_down = get_reflected_wave_for_ideal;
+        r->get_port_resistance = get_port_resistance_for_root;
     }
     else if (r->type == Diode)
     {
@@ -152,8 +152,8 @@
         r->port_resistance_up = tWDF_getPortResistance(child);
         r->port_conductance_up = 1.0f / r->port_resistance_up;
         
-        r->get_reflected_wave_down = &get_reflected_wave_for_diode;
-        r->get_port_resistance = &get_port_resistance_for_root;
+        r->get_reflected_wave_down = get_reflected_wave_for_diode;
+        r->get_port_resistance = get_port_resistance_for_root;
     }
     else if (r->type == DiodePair)
     {
@@ -160,8 +160,8 @@
         r->port_resistance_up = tWDF_getPortResistance(child);
         r->port_conductance_up = 1.0f / r->port_resistance_up;
         
-        r->get_reflected_wave_down = &get_reflected_wave_for_diode_pair;
-        r->get_port_resistance = &get_port_resistance_for_root;
+        r->get_reflected_wave_down = get_reflected_wave_for_diode_pair;
+        r->get_port_resistance = get_port_resistance_for_root;
     }
 }
 //WDF
@@ -381,6 +381,7 @@
 static void set_incident_wave_for_leaf(tWDF* const wdf, float incident_wave, float input)
 {
     _tWDF* r = *wdf;
+    USED(input);
     r->incident_wave_up = incident_wave;
 }
 
@@ -387,6 +388,7 @@
 static void set_incident_wave_for_leaf_inverted(tWDF* const wdf, float incident_wave, float input)
 {
     _tWDF* r = *wdf;
+    USED(input);
     r->incident_wave_up = -1.0f * incident_wave;
 }
 
@@ -438,6 +440,7 @@
 {
     _tWDF* r = *wdf;
     r->reflected_wave_up = 0.0f;
+    USED(input);
     return r->reflected_wave_up;
 }
 
@@ -445,6 +448,7 @@
 {
     _tWDF* r = *wdf;
     r->reflected_wave_up = r->incident_wave_up;
+    USED(input);
     return r->reflected_wave_up;
 }
 
@@ -483,6 +487,7 @@
 
 static float get_reflected_wave_for_ideal(tWDF* const wdf, float input, float incident_wave)
 {
+    USED(wdf); USED(input);
     return (2.0f * input) - incident_wave;
 }
 
@@ -528,6 +533,7 @@
     
     float a = incident_wave;
     float r = n->port_resistance_up;
+    USED(input);
     return a + 2.0f*r*Is_DIODE - 2.0f*VT_DIODE*lambertW(a, r, Is_DIODE, 1.0f/VT_DIODE);
 }
 
@@ -537,6 +543,7 @@
     
     float a = incident_wave;
     float sgn = 0.0f;
+    USED(input);
     if (a > 0.0f) sgn = 1.0f;
     else if (a < 0.0f) sgn = -1.0f;
     float r = n->port_resistance_up;
--- a/leaf/Src/leaf-instruments.c
+++ b/leaf/Src/leaf-instruments.c
@@ -84,7 +84,7 @@
 {
     _t808Cowbell* cowbell = *cowbellInst;
     
-    float sample = 0.0f;
+    float sample;
     
     // Mix oscillators.
     sample = (cowbell->oscMix * tSquare_tick(&cowbell->p[0])) + ((1.0f-cowbell->oscMix) * tSquare_tick(&cowbell->p[1]));
--- a/leaf/Src/leaf-math.c
+++ b/leaf/Src/leaf-math.c
@@ -276,7 +276,7 @@
     else return 2.0f * in * LEAF_chebyshevT(in, n-1) - LEAF_chebyshevT(in, n-2);
 }
 
-#if !(_WIN32 || _WIN64)
+#if !(_WIN32 || _WIN64 || __plan9__)
 float LEAF_CompoundChebyshevT(float in, int n, float* amps){
     float T[n+1];
     T[0] = 1.0f;
@@ -486,7 +486,7 @@
 void LEAF_generate_sawtooth(float* buffer, float basefreq, int size, LEAF* const leaf)
 {
     int harmonic = 1;
-    float phase = 0.0f;
+    float phase;
     float freq = harmonic * basefreq;
     float amp;
     
@@ -508,12 +508,12 @@
 void LEAF_generate_triangle(float* buffer, float basefreq, int size, LEAF* const leaf)
 {
     int harmonic = 1;
-    float phase = 0.0f;
+    float phase;
     float freq = harmonic * basefreq;
-    float amp = 1.0f;
+    float amp;
     
     int count = 0;
-    float mult = 1.0f;
+    float mult;
     
     while (freq < (leaf->sampleRate * 0.5))
     {
@@ -537,9 +537,9 @@
 void LEAF_generate_square(float* buffer, float basefreq, int size, LEAF* const leaf)
 {
     int harmonic = 1;
-    float phase = 0.0f;
+    float phase;
     float freq = harmonic * basefreq;
-    float amp = 1.0f;
+    float amp;
     
     while (freq < (leaf->sampleRate * 0.5))
     {
@@ -577,7 +577,7 @@
     double skew = log (0.5) / log ((center - start) / (end - start));
     double increment = 1.0 / (double)(size-1);
     double x = 0.0;
-    double proportion = 0.0;
+    double proportion;
     for (int i = 0; i < size; i++)
     {
         proportion = exp (log(x) / skew);
@@ -592,7 +592,7 @@
     float skew = logf (0.5) / logf ((center - start) / (end - start));
     float increment = 1.0 / (float)(size-1);
     float x = 0.0;
-    float proportion = 0.0;
+    float proportion;
     for (int i = 0; i < size; i++)
     {
         proportion = expf (logf(x) / skew);
--- a/leaf/Src/leaf-mempool.c
+++ b/leaf/Src/leaf-mempool.c
@@ -327,8 +327,8 @@
     mpool_node_t* next_node;
     while (other_node != NULL)
     {
-        if ((long) other_node < (long) pool->mpool ||
-            (long) other_node >= (((long) pool->mpool) + pool->msize))
+        if ((uintptr_t) other_node < (uintptr_t) pool->mpool ||
+            (uintptr_t) other_node >= (((uintptr_t) pool->mpool) + pool->msize))
         {
             LEAF_internalErrorCallback(pool->leaf, LEAFInvalidFree);
             return;
@@ -335,7 +335,7 @@
         }
         next_node = other_node->next;
         // Check if a node is directly after the freed node
-        if (((long) freed_node) + (pool->leaf->header_size + freed_node->size) == (long) other_node)
+        if (((uintptr_t) freed_node) + (pool->leaf->header_size + freed_node->size) == (uintptr_t) other_node)
         {
             // Increase freed node's size
             freed_node->size += pool->leaf->header_size + other_node->size;
@@ -346,7 +346,7 @@
         }
         
         // Check if a node is directly before the freed node
-        else if (((long) other_node) + (pool->leaf->header_size + other_node->size) == (long) freed_node)
+        else if (((uintptr_t) other_node) + (pool->leaf->header_size + other_node->size) == (uintptr_t) freed_node)
         {
             // Increase the merging node's size
             other_node->size += pool->leaf->header_size + freed_node->size;
--- a/leaf/Src/leaf-midi.c
+++ b/leaf/Src/leaf-midi.c
@@ -163,7 +163,6 @@
             
         }
         // in case it got put on the stack multiple times
-        foundIndex--;
         ns->size--;
         removed = 1;
     }
@@ -222,7 +221,7 @@
 {
     _tStack* ns = *stack;
     
-    int step = 0;
+    int step;
     if (ns->size != 0) // if there is at least one note in the stack
     {
         if (ns->pos > 0) // if you're not at the most recent note (first one), then go backward in the array (moving from earliest to latest)
@@ -748,7 +747,7 @@
 int tSimplePoly_noteOff(tSimplePoly* const polyh, uint8_t note)
 {
     _tSimplePoly* poly = *polyh;
-    int16_t noteToTest = -1;
+    int16_t noteToTest;
 
     tStack_remove(&poly->stack, note);
     poly->notes[note][0] = -1;
--- a/leaf/Src/leaf-oscillators.c
+++ b/leaf/Src/leaf-oscillators.c
@@ -833,7 +833,7 @@
 {
     _tNeuron* n = *nr;
     
-    float output = 0.0f;
+    float output;
     float voltage = n->voltage;
     
     n->alpha[0] = (0.01f * (10.0f - voltage)) / (expf((10.0f - voltage)/10.0f) - 1.0f);
@@ -978,6 +978,7 @@
 	float r;
 	long i;
 
+    USED(index);
 	r = MINBLEP_PHASES * phase * inv_w;
 	i = lrintf(r - 0.5f);
 	r -= (float)i;
@@ -1323,6 +1324,7 @@
 	float r;
 	long i;
 
+    USED(index);
 	r = MINBLEP_PHASES * phase * inv_w;
 	i = lrintf(r - 0.5f);
 	r -= (float)i;
@@ -1343,7 +1345,7 @@
     int    j, k;
     float  sync;
     float  b, b1, invB, invB1, p, w, sw, z;
-    float  x = 0.5f;
+    float  x;
     
     sync = c->sync;
 
@@ -1692,6 +1694,7 @@
 	float r;
 	long i;
 
+    USED(index);
 	r = MINBLEP_PHASES * phase * inv_w;
 	i = lrintf(r - 0.5f);
 	r -= (float)i;
@@ -1712,7 +1715,7 @@
     int    j, k;
     float  sync;
     float  b, b1, invB, invB1, p, sinPhase, w, sw, z;
-    float  x = 0.5f;
+    float  x;
 
     sync = c->sync;
 
@@ -2099,6 +2102,7 @@
 	float r;
 	long i;
 
+    USED(index);
 	r = MINBLEP_PHASES * phase * inv_w;
 	i = lrintf(r - 0.5f);
 	r -= (float)i;
@@ -2322,6 +2326,7 @@
 	float r;
 	long i;
 
+    USED(index);
 	r = MINBLEP_PHASES * phase * inv_w;
 	i = lrintf(r - 0.5f);
 	r -= (float)i;
@@ -2913,7 +2918,7 @@
     // Phasor increment (unsigned 32bit int wraps automatically with overflow so no need for if branch checks, as you need with float)
     c->phase += c->inc;
     float floatPhase = (double)c->phase * 2.32830643654e-10;
-    float s1 = 0.f, s2 = 0.f;
+    float s1, s2;
 
     float temp;
     int idx;
@@ -3299,7 +3304,7 @@
     // Phasor increment (unsigned 32bit int wraps automatically with overflow so no need for if branch checks, as you need with float)
     c->phase += c->inc;
     float floatPhase = (double)c->phase * 2.32830643654e-10;
-    float s1 = 0.f, s2 = 0.f;
+    float s1, s2;
 
     float temp;
     int idx;
--- a/leaf/Src/leaf-physical.c
+++ b/leaf/Src/leaf-physical.c
@@ -31,7 +31,7 @@
     
     p->sampleRate = leaf->sampleRate;
     
-    if ( lowestFrequency <= 0.0f )  lowestFrequency = 10.0f;
+    if ( lowestFrequency <= 0.0f )  lowestFrequency = 10.0f; USED(lowestFrequency);
     
     tNoise_initToPool(&p->noise, WhiteNoise, mp);
     
@@ -124,6 +124,7 @@
 // Perform the control change specified by \e number and \e value (0.0 - 128.0).
 void    tPluck_controlChange (tPluck* const pl, int number, float value)
 {
+    USED(pl); USED(number); USED(value);
     return;
 }
 
@@ -156,7 +157,7 @@
     
     p->sampleRate = leaf->sampleRate;
     
-    if ( lowestFrequency <= 0.0f )  lowestFrequency = 8.0f;
+    if ( lowestFrequency <= 0.0f )  lowestFrequency = 8.0f; USED(lowestFrequency);
     
     tAllpassDelay_initToPool(&p->delayLine, 0.0f, p->sampleRate * 2, mp);
     tAllpassDelay_clear(&p->delayLine);
@@ -618,7 +619,7 @@
     int remainder = length-pluckPoint;
     for (int i = 0; i < length; i++)
     {
-        float val = 0.0f;
+        float val;
         if (i <= pluckPoint)
         {
             val = input * ((float)i/(float)pluckPoint);
@@ -643,6 +644,7 @@
 float   tSimpleLivingString3_tick(tSimpleLivingString3* const pl, float input)
 {
     _tSimpleLivingString3* p = *pl;
+    USED(input);
     tLinearDelay_setDelay(&p->delayLineU, tExpSmooth_tick(&p->wlSmooth));
     tLinearDelay_setDelay(&p->delayLineL, tExpSmooth_tick(&p->wlSmooth));
     
@@ -1293,7 +1295,7 @@
     tHermiteDelay_setDelay(&p->delUB, upLen);
     
     uint32_t PUPInt;
-    float pickupOut = 0.0f;
+    float pickupOut;
     float pupos = tExpSmooth_tick(&p->puSmooth);
     if (pupos < 0.9999f)
     {
--- a/leaf/Src/leaf-sampling.c
+++ b/leaf/Src/leaf-sampling.c
@@ -281,7 +281,7 @@
         return p->last;
     }
     
-    float sample = 0.0f;
+    float sample;
     float cfxsample = 0.0f;
     float crossfadeMix = 0.0f;
     float flipsample = 0.0f;
@@ -1202,7 +1202,7 @@
 
 void    tAutoSampler_setRate    (tAutoSampler* const as, float rate)
 {
-    ;
+    USED(as); USED(rate);
 }
 
 void    tAutoSampler_setSampleRate (tAutoSampler* const as, float sr)
--- a/leaf/Src/leaf.c
+++ b/leaf/Src/leaf.c
@@ -33,7 +33,7 @@
     
     leaf->clearOnAllocation = 0;
     
-    leaf->errorCallback = &LEAF_defaultErrorCallback;
+    leaf->errorCallback = LEAF_defaultErrorCallback;
     
     for (int i = 0; i < LEAFErrorNil; ++i)
         leaf->errorState[i] = 0;
@@ -59,6 +59,7 @@
 {
     // Not sure what this should do if anything
     // Maybe fine as a placeholder
+    USED(leaf); USED(whichone);
 }
 
 void LEAF_internalErrorCallback(LEAF* const leaf, LEAFErrorType whichone)
--- a/leaf/leaf.h
+++ b/leaf/leaf.h
@@ -24,6 +24,12 @@
 
 #ifndef LEAF_H_INCLUDED
 #define LEAF_H_INCLUDED
+
+#ifdef __plan9__
+#pragma lib "./libleaf.$M.a"
+#else
+#define USED(x)
+#endif
 
 #define LEAF_DEBUG 0
 
--- /dev/null
+++ b/leaf/mkfile
@@ -1,0 +1,67 @@
+</$objtype/mkfile
+LIB=libleaf.$objtype.a
+
+CFLAGS=$CFLAGS -p -IInc -IExternals -IExternals/plan9 -D__plan9__=1
+
+OFILES=\
+	Externals/d_fft_mayer.$O\
+	Externals/plan9/plan9.$O\
+	Src/leaf-analysis.$O\
+	Src/leaf-delay.$O\
+	Src/leaf-distortion.$O\
+	Src/leaf-dynamics.$O\
+	Src/leaf-effects.$O\
+	Src/leaf-electrical.$O\
+	Src/leaf-envelopes.$O\
+	Src/leaf-filters.$O\
+	Src/leaf-instruments.$O\
+	Src/leaf-math.$O\
+	Src/leaf-mempool.$O\
+	Src/leaf-midi.$O\
+	Src/leaf-oscillators.$O\
+	Src/leaf-physical.$O\
+	Src/leaf-reverb.$O\
+	Src/leaf-sampling.$O\
+	Src/leaf-tables.$O\
+	Src/leaf.$O\
+
+HFILES=\
+	Externals/d_fft_mayer.h\
+	Externals/trigtbl.h\
+	Inc/leaf-analysis.h\
+	Inc/leaf-delay.h\
+	Inc/leaf-distortion.h\
+	Inc/leaf-dynamics.h\
+	Inc/leaf-effects.h\
+	Inc/leaf-electrical.h\
+	Inc/leaf-envelopes.h\
+	Inc/leaf-filters.h\
+	Inc/leaf-global.h\
+	Inc/leaf-instruments.h\
+	Inc/leaf-math.h\
+	Inc/leaf-mempool.h\
+	Inc/leaf-midi.h\
+	Inc/leaf-oscillators.h\
+	Inc/leaf-physical.h\
+	Inc/leaf-reverb.h\
+	Inc/leaf-sampling.h\
+	Inc/leaf-tables.h\
+	leaf-config.h\
+	leaf.h\
+
+(.*)\.$O:R: \1.c
+	$CC $CFLAGS -o $target $stem1.c
+
+LIBOBJ=${OFILES:%=$LIB(%)}
+
+default:V: $LIB
+
+all:V: $LIB
+
+$LIB: $LIBOBJ
+	ar vu $LIB $newmember
+
+$LIB(%.$O):N: %.$O
+
+clean:V:
+	rm -f */*.[$OS] */*/*.[$OS] *.a
--- /dev/null
+++ b/leaf/plan9_example.c
@@ -1,0 +1,33 @@
+#include "leaf.h"
+#include <bio.h>
+
+static float
+fandom(void)
+{
+	return frand();
+}
+
+void
+main(int, char **)
+{
+	LEAF leaf;
+	tCycle cycle;
+	char mem[1000];
+	Biobuf out;
+	int i;
+
+	LEAF_init(&leaf, 44100, mem, 1000, fandom);
+	tCycle_init(&cycle, &leaf);
+	tCycle_setFreq(&cycle, 220);
+	Binit(&out, 1, OWRITE);
+
+	for(i = 0; i < 44100; i++){
+		float f = tCycle_tick(&cycle);
+		s16int s[2];
+		s[0] = 16384.0f*(f - 0.5f);
+		s[1] = s[0];
+		Bwrite(&out, s, sizeof(s));
+	}
+
+	exits(nil);
+}