History

plan 9 port

Sigrid Solveig Haflínudóttir committed 3 years ago

Commit a3746881 parent a0b0b7926 files · +328 −80Browse files

Unified · Split

26 files
  1. leaf/Externals/d_fft_mayer.c +3 −3
  2. leaf/Externals/plan9/limits.h +0 −0
  3. leaf/Externals/plan9/math.h +0 −0
  4. leaf/Externals/plan9/plan9.c +73 −0
  5. leaf/Externals/plan9/stdbool.h +0 −0
  6. leaf/Externals/plan9/stdint.h +0 −0
  7. leaf/Externals/plan9/stdio.h +55 −0
  8. leaf/Externals/plan9/stdlib.h +0 −0
  9. leaf/Externals/plan9/string.h +0 −0
  10. leaf/Inc/leaf-math.h +2 −0
  11. leaf/Src/leaf-analysis.c +6 −6
  12. leaf/Src/leaf-distortion.c +1 −1
  13. leaf/Src/leaf-dynamics.c +1 −1
  14. leaf/Src/leaf-effects.c +11 −13
  15. leaf/Src/leaf-electrical.c +34 −27
  16. leaf/Src/leaf-instruments.c +1 −1
  17. leaf/Src/leaf-math.c +9 −9
  18. leaf/Src/leaf-mempool.c +4 −4
  19. leaf/Src/leaf-midi.c +2 −3
  20. leaf/Src/leaf-oscillators.c +10 −5
  21. leaf/Src/leaf-physical.c +6 −4
  22. leaf/Src/leaf-sampling.c +2 −2
  23. leaf/Src/leaf.c +2 −1
  24. leaf/leaf.h +6 −0
  25. leaf/mkfile +67 −0
  26. leaf/plan9_example.c +33 −0
leaf/Externals/d_fft_mayer.c+3−3
@@ -69,15 +69,15 @@ · 68 unmodified lines
6969 #if defined(GOOD_TRIG)
7070 #define FHT_SWAP(a,b,t) {(t)=(a);(a)=(b);(b)=(t);}
7171 #define TRIG_VARS \
72− int t_lam=0;
72+ int t_lam=0; USED(t_lam);
7373 #define TRIG_INIT(k,c,s) \
7474 { \
7575 int i; \
7676 for (i=2 ; i<=k ; i++) \
7777 {coswrk[i]=costab[i];sinwrk[i]=sintab[i];} \
7878 t_lam = 0; \
79− c = 1; \
80− s = 0; \
79+ c = 1; USED(c); \
80+ s = 0; USED(s); \
8181 }
8282 #define TRIG_NEXT(k,c,s) \
8383 { \
leaf/Externals/plan9/limits.h+0−0

Empty file added.

leaf/Externals/plan9/math.h+0−0

Empty file added.

leaf/Externals/plan9/plan9.c+73−0
@@ -0,0 +1,73 @@
1+#include <stdio.h>
2+
3+int
4+isinf(double d)
5+{
6+ if(isInf(d, 0) == 0)
7+ return 0;
8+
9+ return isInf(d, -1) ? -1 : 1;
10+}
11+
12+int
13+lrintf(float f)
14+{
15+ int i;
16+
17+ *((float*)&i) = f + 12582912.0f;
18+
19+ return (i & 0x7fffff) - 0x400000;
20+}
21+
22+#define ln2o1 1.4426950408889634073599
23+#define hugeF 3.4028234e+38
24+#define hugeD 1.79769313486231e+308
25+
26+double
27+log2(double x)
28+{
29+ if(x == 0)
30+ return -hugeD;
31+ if(x < 0 || isNaN(x))
32+ return NaN();
33+
34+ return log(x)*ln2o1;
35+}
36+
37+float
38+log2f(float x)
39+{
40+ if(x == 0)
41+ return -hugeF;
42+
43+ return log2(x);
44+}
45+
46+/* taken from musl */
47+#define dbleps 2.2204460492503131e-16
48+static double toint = 1.0/dbleps;
49+double
50+round(double x)
51+{
52+ union {double f; u64int i;} u = {x};
53+ int e = u.i >> 52 & 0x7ff;
54+ double y;
55+
56+ if(e >= 0x3ff+52)
57+ return x;
58+ if(u.i >> 63)
59+ x = -x;
60+ if(e < 0x3ff-1)
61+ return 0*u.f;
62+ y = x + toint - toint - x;
63+ if(y > 0.5)
64+ y = y + x - 1;
65+ else if(y <= -0.5)
66+ y = y + x + 1;
67+ else
68+ y = y + x;
69+ if(u.i >> 63)
70+ y = -y;
71+
72+ return y;
73+}
leaf/Externals/plan9/stdbool.h+0−0

Empty file added.

leaf/Externals/plan9/stdint.h+0−0

Empty file added.

leaf/Externals/plan9/stdio.h+55−0
@@ -0,0 +1,55 @@
1+#ifndef _plan9_stdio_h_
2+#define _plan9_stdio_h_
3+
4+#include <u.h>
5+#include <libc.h>
6+#include </sys/include/stdio.h>
7+
8+#define cosf cos
9+#define sinf sin
10+#define expf exp
11+#define logf log
12+#define powf pow
13+#define tanf tan
14+#define fmodf fmod
15+#define sqrtf sqrt
16+#define isnan isNaN
17+#define acosf acos
18+#define atanf atan
19+#define atan2f atan2
20+#define tanhf tanh
21+#define fabsf fabs
22+#define roundf round
23+#define frexpf frexp
24+#define log10f log10
25+
26+#define fmax(a,b) ((a)>(b)?(a):(b))
27+#define fmin(a,b) ((a)<(b)?(a):(b))
28+#define fmaxf fmax
29+#define fminf fmin
30+
31+#define isfinite(x) (!isinf(x))
32+
33+typedef usize size_t;
34+typedef u8int uint8_t;
35+typedef s8int int8_t;
36+typedef u16int uint16_t;
37+typedef s16int int16_t;
38+typedef u32int uint32_t;
39+typedef s32int int32_t;
40+typedef u64int uint64_t;
41+typedef uintptr uintptr_t;
42+
43+#define CHAR_BIT 8
44+#define INT_MAX 0x7fffffff
45+#define INT_MIN (-INT_MAX-1)
46+#define UINT_MAX 0xffffffffU
47+#define UINT16_MAX 0xffff
48+
49+int isinf(double d);
50+int lrintf(float f);
51+double log2(double x);
52+float log2f(float x);
53+double round(double x);
54+
55+#endif
leaf/Externals/plan9/stdlib.h+0−0

Empty file added.

leaf/Externals/plan9/string.h+0−0

Empty file added.

leaf/Inc/leaf-math.h+2−0
@@ -36,7 +36,9 @@ extern "C" { · 35 unmodified lines
3636 #define SQRT8 2.82842712475f
3737 #define LEAF_SQRT2 1.41421356237f
3838 #define WSCALE 1.30612244898f
39+#ifndef PI
3940 #define PI (3.14159265358979f)
41+#endif
4042 #define TWO_PI (6.28318530717958f)
4143 #define HALF_PI (1.570796326794897f)
4244
leaf/Src/leaf-analysis.c+6−6
@@ -124,7 +124,7 @@ float tZeroCrossingCounter_tick (tZeroCrossingCounter* const zc, float · 123 unmodified lines
124124
125125 z->inBuffer[z->position] = input;
126126 int futurePosition = ((z->position + 1) % z->currentWindowSize);
127− float output = 0.0f;
127+ float output;
128128
129129 //add new value to count
130130 if ((z->inBuffer[z->position] * z->inBuffer[z->prevPosition]) < 0.0f)
@@ -438,7 +438,7 @@ static void atkdtk_envelope(tAttackDetection* const ad, float *in) · 307 unmodified lines
438438 {
439439 _tAttackDetection* a = *ad;
440440
441− int i = 0;
441+ int i;
442442 float tmp;
443443 for(i = 0; i < a->blockSize; ++i){
444444 tmp = fastabsf(in[i]);
@@ -1124,7 +1124,7 @@ int tZeroCrossingCollector_getState(tZeroCrossingCollector* const zc) · 679 unmodified lines
11241124 return z->_state;
11251125 }
11261126
1127−tZeroCrossingInfo const tZeroCrossingCollector_getCrossing(tZeroCrossingCollector* const zc, int index)
1127+tZeroCrossingInfo tZeroCrossingCollector_getCrossing(tZeroCrossingCollector* const zc, int index)
11281128 {
11291129 _tZeroCrossingCollector* z = *zc;
11301130
@@ -1487,7 +1487,7 @@ int tBACF_getCorrelation (tBACF* const bacf, int pos) · 356 unmodified lines
14871487 #elif _MSC_VER
14881488 count += __popcnt(*p1++ ^ v++);
14891489 #else
1490− count += popcount(*p1++ ^ v++);
1490+ count += popcount(*p1++ ^ v++); USED(count); USED(v);
14911491 #endif
14921492 }
14931493 }
@@ -1675,7 +1675,7 @@ void tPeriodDetector_setHysteresis (tPeriodDetector* const detector, float · 181 unmodified lines
16751675 {
16761676 _tPeriodDetector* p = *detector;
16771677
1678− return tZeroCrossingCollector_setHysteresis(&p->_zc, hysteresis);
1678+ tZeroCrossingCollector_setHysteresis(&p->_zc, hysteresis);
16791679 }
16801680
16811681 void tPeriodDetector_setSampleRate (tPeriodDetector* const detector, float sr)
@@ -2196,7 +2196,7 @@ int tDualPitchDetector_tick (tDualPitchDetector* const detector, float sa · 514 unmodified lines
21962196 if (ready)
21972197 {
21982198 int pd2_indeterminate = tPitchDetector_indeterminate(&p->_pd2);
2199− int disagreement = 0;
2199+ int disagreement;
22002200 float period = tPeriodDetection_getPeriod(&p->_pd1);
22012201 if (!pd2_indeterminate && period != 0.0f)
22022202 {
leaf/Src/leaf-distortion.c+1−1
@@ -513,7 +513,7 @@ float tLockhartWavefolder_tick(tLockhartWavefolder* const wf, float in) · 512 unmodified lines
513513 {
514514 _tLockhartWavefolder* w = *wf;
515515
516− float out = 0.0f;
516+ float out;
517517
518518 // Compute Antiderivative
519519 w->l = (in > 0.0) - (in < 0.0);
leaf/Src/leaf-dynamics.c+1−1
@@ -86,7 +86,7 @@ float tCompressor_tick(tCompressor* const comp, float in) · 85 unmodified lines
8686 float slope, overshoot;
8787
8888 float in_db = LEAF_clip(-90.0f, fasteratodb(fastabsf(in)), 0.0f);
89− float out_db = 0.0f;
89+ float out_db;
9090
9191 c->y_T[1] = c->y_T[0];
9292
leaf/Src/leaf-effects.c+11−13
@@ -149,7 +149,6 @@ void tTalkbox_warpedAutocorrelate(float * x, double* dl, double* Rt, unsigned in · 148 unmodified lines
149149 Rt[0]=0;
150150 r1=0;
151151 r2=0;
152− r1t=0;
153152 for(uint32_t m=0; m<L;m++)
154153 {
155154 Rt[0] += (double)(x[m]) * (double)(x[m]);
@@ -243,7 +242,7 @@ float tTalkbox_tick(tTalkbox* const voc, float synth, float voice) · 87 unmodified lines
243242 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; }
244243
245244 w = 1.0f - w; fx += v->buf1[p1] * w; v->buf1[p1] = x * w;
246− 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; }
245+ 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); }
247246 }
248247
249248 p = v->u0 + h0 * fx; v->u0 = v->u1; v->u1 = fx - h0 * p;
@@ -487,7 +486,6 @@ void tTalkboxFloat_warpedAutocorrelate(float * x, float* dl, float* Rt, unsigned · 237 unmodified lines
487486 Rt[0]=0;
488487 r1=0;
489488 r2=0;
490− r1t=0;
491489 for(uint32_t m=0; m<L;m++)
492490 {
493491 Rt[0] += (x[m]) * (x[m]);
@@ -582,7 +580,7 @@ float tTalkboxFloat_tick(tTalkboxFloat* const voc, float synth, float voice) · 88 unmodified lines
582580 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; }
583581
584582 w = 1.0f - w; fx += v->buf1[p1] * w; v->buf1[p1] = x * w;
585− 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; }
583+ 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); }
586584 }
587585
588586 p = v->u0 + h0 * fx; v->u0 = v->u1; v->u1 = fx - h0 * p;
@@ -826,7 +824,7 @@ float tVocoder_tick (tVocoder* const voc, float synth, float voice) · 237 unmodified lines
826824 {
827825 _tVocoder* v = *voc;
828826
829− float a, b, o=0.0f, aa, bb, oo = v->kout, g = v->gain, ht = v->thru, hh = v->high, tmp;
827+ float a, b, o, aa, bb, oo = v->kout, g = v->gain, ht = v->thru, hh = v->high, tmp;
830828 uint32_t i, k = v->kval, nb = v->nbnd;
831829
832830 a = voice; //speech
@@ -940,7 +938,7 @@ float tRosenbergGlottalPulse_tick (tRosenbergGlottalPulse* const gp) · 107 unmodified lines
940938 {
941939 _tRosenbergGlottalPulse* g = *gp;
942940
943− float output = 0.0f;
941+ float output;
944942
945943 // Phasor increment
946944 g->phase += g->inc;
@@ -969,7 +967,7 @@ float tRosenbergGlottalPulse_tickHQ (tRosenbergGlottalPulse* const g · 22 unmodified lines
969967 {
970968 _tRosenbergGlottalPulse* g = *gp;
971969
972− float output = 0.0f;
970+ float output;
973971
974972 // Phasor increment
975973 g->phase += g->inc;
@@ -1518,7 +1516,7 @@ void tSimpleRetune_initToPool (tSimpleRetune* const rt, int numVoices, float min · 542 unmodified lines
15181516 tPitchShift_initToPool(&r->ps[i], &r->dp, r->bufSize, mp);
15191517 }
15201518
1521− r->shiftFunction = &tPitchShift_shiftBy;
1519+ r->shiftFunction = tPitchShift_shiftBy;
15221520 }
15231521
15241522 void tSimpleRetune_free (tSimpleRetune* const rt)
@@ -1564,8 +1562,8 @@ void tSimpleRetune_setMode (tSimpleRetune* const rt, int mode) · 39 unmodified lines
15641562 {
15651563 _tSimpleRetune* r = *rt;
15661564
1567− if (mode > 0) r->shiftFunction = &tPitchShift_shiftTo;
1568− else r->shiftFunction = &tPitchShift_shiftBy;
1565+ if (mode > 0) r->shiftFunction = tPitchShift_shiftTo;
1566+ else r->shiftFunction = tPitchShift_shiftBy;
15691567 }
15701568
15711569 void tSimpleRetune_setNumVoices(tSimpleRetune* const rt, int numVoices)
@@ -1663,7 +1661,7 @@ void tRetune_initToPool (tRetune* const rt, int numVoices, float minInputFreq, f · 91 unmodified lines
16631661 r->outBuffers[i] = (float*) mpool_calloc(sizeof(float) * r->bufSize, m);
16641662 }
16651663
1666− r->shiftFunction = &tPitchShift_shiftBy;
1664+ r->shiftFunction = tPitchShift_shiftBy;
16671665 }
16681666
16691667 void tRetune_free (tRetune* const rt)
@@ -1715,8 +1713,8 @@ void tRetune_setMode (tRetune* const rt, int mode) · 45 unmodified lines
17151713 {
17161714 _tRetune* r = *rt;
17171715
1718− if (mode > 0) r->shiftFunction = &tPitchShift_shiftTo;
1719− else r->shiftFunction = &tPitchShift_shiftBy;
1716+ if (mode > 0) r->shiftFunction = tPitchShift_shiftTo;
1717+ else r->shiftFunction = tPitchShift_shiftBy;
17201718 }
17211719
17221720 void tRetune_setPickiness (tRetune* const rt, float p)
leaf/Src/leaf-electrical.c+34−27
@@ -71,45 +71,45 @@ static void wdf_init(tWDF* const wdf, WDFComponentType type, float value, tWDF* · 70 unmodified lines
7171 r->port_resistance_up = r->value;
7272 r->port_conductance_up = 1.0f / r->value;
7373
74− r->get_port_resistance = &get_port_resistance_for_resistor;
75− r->get_reflected_wave_up = &get_reflected_wave_for_resistor;
76− r->set_incident_wave = &set_incident_wave_for_leaf;
74+ r->get_port_resistance = get_port_resistance_for_resistor;
75+ r->get_reflected_wave_up = get_reflected_wave_for_resistor;
76+ r->set_incident_wave = set_incident_wave_for_leaf;
7777 }
7878 else if (r->type == Capacitor)
7979 {
8080 r->port_conductance_up = r->sample_rate * 2.0f * r->value;
8181 r->port_resistance_up = 1.0f / r->port_conductance_up; //based on trapezoidal discretization
8282
83− r->get_port_resistance = &get_port_resistance_for_capacitor;
84− r->get_reflected_wave_up = &get_reflected_wave_for_capacitor;
85− r->set_incident_wave = &set_incident_wave_for_leaf;
83+ r->get_port_resistance = get_port_resistance_for_capacitor;
84+ r->get_reflected_wave_up = get_reflected_wave_for_capacitor;
85+ r->set_incident_wave = set_incident_wave_for_leaf;
8686 }
8787 else if (r->type == Inductor)
8888 {
8989 r->port_resistance_up = r->sample_rate * 2.0f * r->value; //based on trapezoidal discretization
9090 r->port_conductance_up = 1.0f / r->port_resistance_up;
9191
92− r->get_port_resistance = &get_port_resistance_for_inductor;
93− r->get_reflected_wave_up = &get_reflected_wave_for_capacitor; // same as capacitor
94− r->set_incident_wave = &set_incident_wave_for_leaf_inverted;
92+ r->get_port_resistance = get_port_resistance_for_inductor;
93+ r->get_reflected_wave_up = get_reflected_wave_for_capacitor; // same as capacitor
94+ r->set_incident_wave = set_incident_wave_for_leaf_inverted;
9595 }
9696 else if (r->type == ResistiveSource)
9797 {
9898 r->port_resistance_up = r->value;
9999 r->port_conductance_up = 1.0f / r->port_resistance_up;
100100
101− r->get_port_resistance = &get_port_resistance_for_resistive;
102− r->get_reflected_wave_up = &get_reflected_wave_for_resistive;
103− r->set_incident_wave = &set_incident_wave_for_leaf;
101+ r->get_port_resistance = get_port_resistance_for_resistive;
102+ r->get_reflected_wave_up = get_reflected_wave_for_resistive;
103+ r->set_incident_wave = set_incident_wave_for_leaf;
104104 }
105105 else if (r->type == Inverter)
106106 {
107107 r->port_resistance_up = tWDF_getPortResistance(r->child_left);
108108 r->port_conductance_up = 1.0f / r->port_resistance_up;
109109
110− r->get_port_resistance = &get_port_resistance_for_inverter;
111− r->get_reflected_wave_up = &get_reflected_wave_for_inverter;
112− r->set_incident_wave = &set_incident_wave_for_inverter;
110+ r->get_port_resistance = get_port_resistance_for_inverter;
111+ r->get_reflected_wave_up = get_reflected_wave_for_inverter;
112+ r->set_incident_wave = set_incident_wave_for_inverter;
113113 }
114114 else if (r->type == SeriesAdaptor)
115115 {
@@ -121,9 +121,9 @@ static void wdf_init(tWDF* const wdf, WDFComponentType type, float value, tWDF* · 5 unmodified lines
121121 r->port_conductance_right = 1.0f / r->port_resistance_right;
122122 r->gamma_zero = 1.0f / (r->port_resistance_right + r->port_resistance_left);
123123
124− r->get_port_resistance = &get_port_resistance_for_series;
125− r->get_reflected_wave_up = &get_reflected_wave_for_series;
126− r->set_incident_wave = &set_incident_wave_for_series;
124+ r->get_port_resistance = get_port_resistance_for_series;
125+ r->get_reflected_wave_up = get_reflected_wave_for_series;
126+ r->set_incident_wave = set_incident_wave_for_series;
127127 }
128128 else if (r->type == ParallelAdaptor)
129129 {
@@ -135,33 +135,33 @@ static void wdf_init(tWDF* const wdf, WDFComponentType type, float value, tWDF* · 5 unmodified lines
135135 r->port_conductance_right = 1.0f / r->port_resistance_right;
136136 r->gamma_zero = 1.0f / (r->port_resistance_right + r->port_resistance_left);
137137
138− r->get_port_resistance = &get_port_resistance_for_parallel;
139− r->get_reflected_wave_up = &get_reflected_wave_for_parallel;
140− r->set_incident_wave = &set_incident_wave_for_parallel;
138+ r->get_port_resistance = get_port_resistance_for_parallel;
139+ r->get_reflected_wave_up = get_reflected_wave_for_parallel;
140+ r->set_incident_wave = set_incident_wave_for_parallel;
141141 }
142142 else if (r->type == IdealSource)
143143 {
144144 r->port_resistance_up = tWDF_getPortResistance(child);
145145 r->port_conductance_up = 1.0f / r->port_resistance_up;
146146
147− r->get_reflected_wave_down = &get_reflected_wave_for_ideal;
148− r->get_port_resistance = &get_port_resistance_for_root;
147+ r->get_reflected_wave_down = get_reflected_wave_for_ideal;
148+ r->get_port_resistance = get_port_resistance_for_root;
149149 }
150150 else if (r->type == Diode)
151151 {
152152 r->port_resistance_up = tWDF_getPortResistance(child);
153153 r->port_conductance_up = 1.0f / r->port_resistance_up;
154154
155− r->get_reflected_wave_down = &get_reflected_wave_for_diode;
156− r->get_port_resistance = &get_port_resistance_for_root;
155+ r->get_reflected_wave_down = get_reflected_wave_for_diode;
156+ r->get_port_resistance = get_port_resistance_for_root;
157157 }
158158 else if (r->type == DiodePair)
159159 {
160160 r->port_resistance_up = tWDF_getPortResistance(child);
161161 r->port_conductance_up = 1.0f / r->port_resistance_up;
162162
163− r->get_reflected_wave_down = &get_reflected_wave_for_diode_pair;
164− r->get_port_resistance = &get_port_resistance_for_root;
163+ r->get_reflected_wave_down = get_reflected_wave_for_diode_pair;
164+ r->get_port_resistance = get_port_resistance_for_root;
165165 }
166166 }
167167 //WDF
@@ -381,12 +381,14 @@ static float get_port_resistance_for_root(tWDF* const wdf) · 213 unmodified lines
381381 static void set_incident_wave_for_leaf(tWDF* const wdf, float incident_wave, float input)
382382 {
383383 _tWDF* r = *wdf;
384+ USED(input);
384385 r->incident_wave_up = incident_wave;
385386 }
386387
387388 static void set_incident_wave_for_leaf_inverted(tWDF* const wdf, float incident_wave, float input)
388389 {
389390 _tWDF* r = *wdf;
391+ USED(input);
390392 r->incident_wave_up = -1.0f * incident_wave;
391393 }
392394
@@ -438,6 +440,7 @@ static float get_reflected_wave_for_resistor(tWDF* const wdf, float input) · 45 unmodified lines
438440 {
439441 _tWDF* r = *wdf;
440442 r->reflected_wave_up = 0.0f;
443+ USED(input);
441444 return r->reflected_wave_up;
442445 }
443446
@@ -445,6 +448,7 @@ static float get_reflected_wave_for_capacitor(tWDF* const wdf, float input) · 1 unmodified line
445448 {
446449 _tWDF* r = *wdf;
447450 r->reflected_wave_up = r->incident_wave_up;
451+ USED(input);
448452 return r->reflected_wave_up;
449453 }
450454
@@ -483,6 +487,7 @@ static float get_reflected_wave_for_parallel(tWDF* const wdf, float input) · 32 unmodified lines
483487
484488 static float get_reflected_wave_for_ideal(tWDF* const wdf, float input, float incident_wave)
485489 {
490+ USED(wdf); USED(input);
486491 return (2.0f * input) - incident_wave;
487492 }
488493
@@ -528,6 +533,7 @@ static float get_reflected_wave_for_diode(tWDF* const wdf, float input, float in · 39 unmodified lines
528533
529534 float a = incident_wave;
530535 float r = n->port_resistance_up;
536+ USED(input);
531537 return a + 2.0f*r*Is_DIODE - 2.0f*VT_DIODE*lambertW(a, r, Is_DIODE, 1.0f/VT_DIODE);
532538 }
533539
@@ -537,6 +543,7 @@ static float get_reflected_wave_for_diode_pair(tWDF* const wdf, float input, flo · 3 unmodified lines
537543
538544 float a = incident_wave;
539545 float sgn = 0.0f;
546+ USED(input);
540547 if (a > 0.0f) sgn = 1.0f;
541548 else if (a < 0.0f) sgn = -1.0f;
542549 float r = n->port_resistance_up;
leaf/Src/leaf-instruments.c+1−1
@@ -84,7 +84,7 @@ float t808Cowbell_tick(t808Cowbell* const cowbellInst) · 83 unmodified lines
8484 {
8585 _t808Cowbell* cowbell = *cowbellInst;
8686
87− float sample = 0.0f;
87+ float sample;
8888
8989 // Mix oscillators.
9090 sample = (cowbell->oscMix * tSquare_tick(&cowbell->p[0])) + ((1.0f-cowbell->oscMix) * tSquare_tick(&cowbell->p[1]));
leaf/Src/leaf-math.c+9−9
@@ -276,7 +276,7 @@ float LEAF_chebyshevT(float in, int n){ · 275 unmodified lines
276276 else return 2.0f * in * LEAF_chebyshevT(in, n-1) - LEAF_chebyshevT(in, n-2);
277277 }
278278
279−#if !(_WIN32 || _WIN64)
279+#if !(_WIN32 || _WIN64 || __plan9__)
280280 float LEAF_CompoundChebyshevT(float in, int n, float* amps){
281281 float T[n+1];
282282 T[0] = 1.0f;
@@ -486,7 +486,7 @@ void LEAF_generate_sine(float* buffer, int size) · 203 unmodified lines
486486 void LEAF_generate_sawtooth(float* buffer, float basefreq, int size, LEAF* const leaf)
487487 {
488488 int harmonic = 1;
489− float phase = 0.0f;
489+ float phase;
490490 float freq = harmonic * basefreq;
491491 float amp;
492492
@@ -508,12 +508,12 @@ void LEAF_generate_sawtooth(float* buffer, float basefreq, int size, LEAF* const · 15 unmodified lines
508508 void LEAF_generate_triangle(float* buffer, float basefreq, int size, LEAF* const leaf)
509509 {
510510 int harmonic = 1;
511− float phase = 0.0f;
511+ float phase;
512512 float freq = harmonic * basefreq;
513− float amp = 1.0f;
513+ float amp;
514514
515515 int count = 0;
516− float mult = 1.0f;
516+ float mult;
517517
518518 while (freq < (leaf->sampleRate * 0.5))
519519 {
@@ -537,9 +537,9 @@ void LEAF_generate_triangle(float* buffer, float basefreq, int size, LEAF* const · 17 unmodified lines
537537 void LEAF_generate_square(float* buffer, float basefreq, int size, LEAF* const leaf)
538538 {
539539 int harmonic = 1;
540− float phase = 0.0f;
540+ float phase;
541541 float freq = harmonic * basefreq;
542− float amp = 1.0f;
542+ float amp;
543543
544544 while (freq < (leaf->sampleRate * 0.5))
545545 {
@@ -577,7 +577,7 @@ void LEAF_generate_table_skew_non_sym_double(float* buffer, float start, float e · 31 unmodified lines
577577 double skew = log (0.5) / log ((center - start) / (end - start));
578578 double increment = 1.0 / (double)(size-1);
579579 double x = 0.0;
580− double proportion = 0.0;
580+ double proportion;
581581 for (int i = 0; i < size; i++)
582582 {
583583 proportion = exp (log(x) / skew);
@@ -592,7 +592,7 @@ void LEAF_generate_table_skew_non_sym(float* buffer, float start, float end, flo · 8 unmodified lines
592592 float skew = logf (0.5) / logf ((center - start) / (end - start));
593593 float increment = 1.0 / (float)(size-1);
594594 float x = 0.0;
595− float proportion = 0.0;
595+ float proportion;
596596 for (int i = 0; i < size; i++)
597597 {
598598 proportion = expf (logf(x) / skew);
leaf/Src/leaf-mempool.c+4−4
@@ -327,15 +327,15 @@ void mpool_free(char* ptr, _tMempool* pool) · 326 unmodified lines
327327 mpool_node_t* next_node;
328328 while (other_node != NULL)
329329 {
330− if ((long) other_node < (long) pool->mpool ||
331− (long) other_node >= (((long) pool->mpool) + pool->msize))
330+ if ((uintptr_t) other_node < (uintptr_t) pool->mpool ||
331+ (uintptr_t) other_node >= (((uintptr_t) pool->mpool) + pool->msize))
332332 {
333333 LEAF_internalErrorCallback(pool->leaf, LEAFInvalidFree);
334334 return;
335335 }
336336 next_node = other_node->next;
337337 // Check if a node is directly after the freed node
338− if (((long) freed_node) + (pool->leaf->header_size + freed_node->size) == (long) other_node)
338+ if (((uintptr_t) freed_node) + (pool->leaf->header_size + freed_node->size) == (uintptr_t) other_node)
339339 {
340340 // Increase freed node's size
341341 freed_node->size += pool->leaf->header_size + other_node->size;
@@ -346,7 +346,7 @@ void mpool_free(char* ptr, _tMempool* pool) · 4 unmodified lines
346346 }
347347
348348 // Check if a node is directly before the freed node
349− else if (((long) other_node) + (pool->leaf->header_size + other_node->size) == (long) freed_node)
349+ else if (((uintptr_t) other_node) + (pool->leaf->header_size + other_node->size) == (uintptr_t) freed_node)
350350 {
351351 // Increase the merging node's size
352352 other_node->size += pool->leaf->header_size + freed_node->size;
leaf/Src/leaf-midi.c+2−3
@@ -163,7 +163,6 @@ int tStack_remove(tStack* const stack, uint16_t noteVal) · 162 unmodified lines
163163
164164 }
165165 // in case it got put on the stack multiple times
166− foundIndex--;
167166 ns->size--;
168167 removed = 1;
169168 }
@@ -222,7 +221,7 @@ int tStack_next(tStack* const stack) · 52 unmodified lines
222221 {
223222 _tStack* ns = *stack;
224223
225− int step = 0;
224+ int step;
226225 if (ns->size != 0) // if there is at least one note in the stack
227226 {
228227 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_noteOn(tSimplePoly* const polyh, int note, uint8_t vel) · 519 unmodified lines
748747 int tSimplePoly_noteOff(tSimplePoly* const polyh, uint8_t note)
749748 {
750749 _tSimplePoly* poly = *polyh;
751− int16_t noteToTest = -1;
750+ int16_t noteToTest;
752751
753752 tStack_remove(&poly->stack, note);
754753 poly->notes[note][0] = -1;
leaf/Src/leaf-oscillators.c+10−5
@@ -833,7 +833,7 @@ float tNeuron_tick(tNeuron* const nr) · 832 unmodified lines
833833 {
834834 _tNeuron* n = *nr;
835835
836− float output = 0.0f;
836+ float output;
837837 float voltage = n->voltage;
838838
839839 n->alpha[0] = (0.01f * (10.0f - voltage)) / (expf((10.0f - voltage)/10.0f) - 1.0f);
@@ -978,6 +978,7 @@ void tMBPulse_place_step_dd_noBuffer(tMBPulse* const osc, int index, float phase · 138 unmodified lines
978978 float r;
979979 long i;
980980
981+ USED(index);
981982 r = MINBLEP_PHASES * phase * inv_w;
982983 i = lrintf(r - 0.5f);
983984 r -= (float)i;
@@ -1323,6 +1324,7 @@ void tMBTriangle_place_dd_noBuffer(tMBTriangle* const osc, int index, float phas · 339 unmodified lines
13231324 float r;
13241325 long i;
13251326
1327+ USED(index);
13261328 r = MINBLEP_PHASES * phase * inv_w;
13271329 i = lrintf(r - 0.5f);
13281330 r -= (float)i;
@@ -1343,7 +1345,7 @@ float tMBTriangle_tick(tMBTriangle* const osc) · 14 unmodified lines
13431345 int j, k;
13441346 float sync;
13451347 float b, b1, invB, invB1, p, w, sw, z;
1346− float x = 0.5f;
1348+ float x;
13471349
13481350 sync = c->sync;
13491351
@@ -1692,6 +1694,7 @@ void tMBSineTri_place_dd_noBuffer(tMBSineTri* const osc, int index, float phase, · 342 unmodified lines
16921694 float r;
16931695 long i;
16941696
1697+ USED(index);
16951698 r = MINBLEP_PHASES * phase * inv_w;
16961699 i = lrintf(r - 0.5f);
16971700 r -= (float)i;
@@ -1712,7 +1715,7 @@ float tMBSineTri_tick(tMBSineTri* const osc) · 14 unmodified lines
17121715 int j, k;
17131716 float sync;
17141717 float b, b1, invB, invB1, p, sinPhase, w, sw, z;
1715− float x = 0.5f;
1718+ float x;
17161719
17171720 sync = c->sync;
17181721
@@ -2099,6 +2102,7 @@ void tMBSaw_place_step_dd_noBuffer(tMBSaw* const osc, int index, float phase, fl · 380 unmodified lines
20992102 float r;
21002103 long i;
21012104
2105+ USED(index);
21022106 r = MINBLEP_PHASES * phase * inv_w;
21032107 i = lrintf(r - 0.5f);
21042108 r -= (float)i;
@@ -2322,6 +2326,7 @@ void tMBSawPulse_place_step_dd_noBuffer(tMBSawPulse* const osc, int index, float · 217 unmodified lines
23222326 float r;
23232327 long i;
23242328
2329+ USED(index);
23252330 r = MINBLEP_PHASES * phase * inv_w;
23262331 i = lrintf(r - 0.5f);
23272332 r -= (float)i;
@@ -2913,7 +2918,7 @@ float tWaveOsc_tick(tWaveOsc* const cy) · 585 unmodified lines
29132918 // Phasor increment (unsigned 32bit int wraps automatically with overflow so no need for if branch checks, as you need with float)
29142919 c->phase += c->inc;
29152920 float floatPhase = (double)c->phase * 2.32830643654e-10;
2916− float s1 = 0.f, s2 = 0.f;
2921+ float s1, s2;
29172922
29182923 float temp;
29192924 int idx;
@@ -3299,7 +3304,7 @@ float tWaveOscS_tick(tWaveOscS* const cy) · 379 unmodified lines
32993304 // Phasor increment (unsigned 32bit int wraps automatically with overflow so no need for if branch checks, as you need with float)
33003305 c->phase += c->inc;
33013306 float floatPhase = (double)c->phase * 2.32830643654e-10;
3302− float s1 = 0.f, s2 = 0.f;
3307+ float s1, s2;
33033308
33043309 float temp;
33053310 int idx;
leaf/Src/leaf-physical.c+6−4
@@ -31,7 +31,7 @@ void tPluck_initToPool (tPluck* const pl, float lowestFrequency, tMempool* · 30 unmodified lines
3131
3232 p->sampleRate = leaf->sampleRate;
3333
34− if ( lowestFrequency <= 0.0f ) lowestFrequency = 10.0f;
34+ if ( lowestFrequency <= 0.0f ) lowestFrequency = 10.0f; USED(lowestFrequency);
3535
3636 tNoise_initToPool(&p->noise, WhiteNoise, mp);
3737
@@ -124,6 +124,7 @@ void tPluck_setFrequency (tPluck* const pl, float frequency ) · 86 unmodified lines
124124 // Perform the control change specified by \e number and \e value (0.0 - 128.0).
125125 void tPluck_controlChange (tPluck* const pl, int number, float value)
126126 {
127+ USED(pl); USED(number); USED(value);
127128 return;
128129 }
129130
@@ -156,7 +157,7 @@ void tKarplusStrong_initToPool (tKarplusStrong* const pl, float lowestFrequ · 26 unmodified lines
156157
157158 p->sampleRate = leaf->sampleRate;
158159
159− if ( lowestFrequency <= 0.0f ) lowestFrequency = 8.0f;
160+ if ( lowestFrequency <= 0.0f ) lowestFrequency = 8.0f; USED(lowestFrequency);
160161
161162 tAllpassDelay_initToPool(&p->delayLine, 0.0f, p->sampleRate * 2, mp);
162163 tAllpassDelay_clear(&p->delayLine);
@@ -618,7 +619,7 @@ void tSimpleLivingString3_pluck(tSimpleLivingString3* const pl, float input, f · 455 unmodified lines
618619 int remainder = length-pluckPoint;
619620 for (int i = 0; i < length; i++)
620621 {
621− float val = 0.0f;
622+ float val;
622623 if (i <= pluckPoint)
623624 {
624625 val = input * ((float)i/(float)pluckPoint);
@@ -643,6 +644,7 @@ void tSimpleLivingString3_pluck(tSimpleLivingString3* const pl, float input, f · 18 unmodified lines
643644 float tSimpleLivingString3_tick(tSimpleLivingString3* const pl, float input)
644645 {
645646 _tSimpleLivingString3* p = *pl;
647+ USED(input);
646648 tLinearDelay_setDelay(&p->delayLineU, tExpSmooth_tick(&p->wlSmooth));
647649 tLinearDelay_setDelay(&p->delayLineL, tExpSmooth_tick(&p->wlSmooth));
648650
@@ -1293,7 +1295,7 @@ float tLivingString2_tick(tLivingString2* const pl, float input) · 644 unmodified lines
12931295 tHermiteDelay_setDelay(&p->delUB, upLen);
12941296
12951297 uint32_t PUPInt;
1296− float pickupOut = 0.0f;
1298+ float pickupOut;
12971299 float pupos = tExpSmooth_tick(&p->puSmooth);
12981300 if (pupos < 0.9999f)
12991301 {
leaf/Src/leaf-sampling.c+2−2
@@ -281,7 +281,7 @@ float tSampler_tick (tSampler* const sp) · 280 unmodified lines
281281 return p->last;
282282 }
283283
284− float sample = 0.0f;
284+ float sample;
285285 float cfxsample = 0.0f;
286286 float crossfadeMix = 0.0f;
287287 float flipsample = 0.0f;
@@ -1202,7 +1202,7 @@ void tAutoSampler_setCrossfadeLength (tAutoSampler* const as, uint32_t length · 914 unmodified lines
12021202
12031203 void tAutoSampler_setRate (tAutoSampler* const as, float rate)
12041204 {
1205− ;
1205+ USED(as); USED(rate);
12061206 }
12071207
12081208 void tAutoSampler_setSampleRate (tAutoSampler* const as, float sr)
leaf/Src/leaf.c+2−1
@@ -33,7 +33,7 @@ void LEAF_init(LEAF* const leaf, float sr, char* memory, size_t memorysize, floa · 32 unmodified lines
3333
3434 leaf->clearOnAllocation = 0;
3535
36− leaf->errorCallback = &LEAF_defaultErrorCallback;
36+ leaf->errorCallback = LEAF_defaultErrorCallback;
3737
3838 for (int i = 0; i < LEAFErrorNil; ++i)
3939 leaf->errorState[i] = 0;
@@ -59,6 +59,7 @@ void LEAF_defaultErrorCallback(LEAF* const leaf, LEAFErrorType whichone) · 19 unmodified lines
5959 {
6060 // Not sure what this should do if anything
6161 // Maybe fine as a placeholder
62+ USED(leaf); USED(whichone);
6263 }
6364
6465 void LEAF_internalErrorCallback(LEAF* const leaf, LEAFErrorType whichone)
leaf/leaf.h+6−0
@@ -24,6 +24,12 @@ · 23 unmodified lines
2424
2525 #ifndef LEAF_H_INCLUDED
2626 #define LEAF_H_INCLUDED
27+
28+#ifdef __plan9__
29+#pragma lib "./libleaf.$M.a"
30+#else
31+#define USED(x)
32+#endif
2733
2834 #define LEAF_DEBUG 0
2935
leaf/mkfile+67−0
@@ -0,0 +1,67 @@
1+</$objtype/mkfile
2+LIB=libleaf.$objtype.a
3+
4+CFLAGS=$CFLAGS -p -IInc -IExternals -IExternals/plan9 -D__plan9__=1
5+
6+OFILES=\
7+ Externals/d_fft_mayer.$O\
8+ Externals/plan9/plan9.$O\
9+ Src/leaf-analysis.$O\
10+ Src/leaf-delay.$O\
11+ Src/leaf-distortion.$O\
12+ Src/leaf-dynamics.$O\
13+ Src/leaf-effects.$O\
14+ Src/leaf-electrical.$O\
15+ Src/leaf-envelopes.$O\
16+ Src/leaf-filters.$O\
17+ Src/leaf-instruments.$O\
18+ Src/leaf-math.$O\
19+ Src/leaf-mempool.$O\
20+ Src/leaf-midi.$O\
21+ Src/leaf-oscillators.$O\
22+ Src/leaf-physical.$O\
23+ Src/leaf-reverb.$O\
24+ Src/leaf-sampling.$O\
25+ Src/leaf-tables.$O\
26+ Src/leaf.$O\
27+
28+HFILES=\
29+ Externals/d_fft_mayer.h\
30+ Externals/trigtbl.h\
31+ Inc/leaf-analysis.h\
32+ Inc/leaf-delay.h\
33+ Inc/leaf-distortion.h\
34+ Inc/leaf-dynamics.h\
35+ Inc/leaf-effects.h\
36+ Inc/leaf-electrical.h\
37+ Inc/leaf-envelopes.h\
38+ Inc/leaf-filters.h\
39+ Inc/leaf-global.h\
40+ Inc/leaf-instruments.h\
41+ Inc/leaf-math.h\
42+ Inc/leaf-mempool.h\
43+ Inc/leaf-midi.h\
44+ Inc/leaf-oscillators.h\
45+ Inc/leaf-physical.h\
46+ Inc/leaf-reverb.h\
47+ Inc/leaf-sampling.h\
48+ Inc/leaf-tables.h\
49+ leaf-config.h\
50+ leaf.h\
51+
52+(.*)\.$O:R: \1.c
53+ $CC $CFLAGS -o $target $stem1.c
54+
55+LIBOBJ=${OFILES:%=$LIB(%)}
56+
57+default:V: $LIB
58+
59+all:V: $LIB
60+
61+$LIB: $LIBOBJ
62+ ar vu $LIB $newmember
63+
64+$LIB(%.$O):N: %.$O
65+
66+clean:V:
67+ rm -f */*.[$OS] */*/*.[$OS] *.a
leaf/plan9_example.c+33−0
@@ -0,0 +1,33 @@
1+#include "leaf.h"
2+#include <bio.h>
3+
4+static float
5+fandom(void)
6+{
7+ return frand();
8+}
9+
10+void
11+main(int, char **)
12+{
13+ LEAF leaf;
14+ tCycle cycle;
15+ char mem[1000];
16+ Biobuf out;
17+ int i;
18+
19+ LEAF_init(&leaf, 44100, mem, 1000, fandom);
20+ tCycle_init(&cycle, &leaf);
21+ tCycle_setFreq(&cycle, 220);
22+ Binit(&out, 1, OWRITE);
23+
24+ for(i = 0; i < 44100; i++){
25+ float f = tCycle_tick(&cycle);
26+ s16int s[2];
27+ s[0] = 16384.0f*(f - 0.5f);
28+ s[1] = s[0];
29+ Bwrite(&out, s, sizeof(s));
30+ }
31+
32+ exits(nil);
33+}

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t