History

Revert changes since "shared static init functions for use in init and initToPool" This reverts commit to before 7156be01b28b4d4c7d688277a6db209526c5b43d.

Matthew Wang committed 6 years ago

Commit 7618da11 parent b05815618 files · +1295 −844Browse files

Unified · Split

18 files
  1. LEAF/Inc/leaf-reverb.h +0 −4
  2. LEAF/Inc/leaf-sampling.h +2 −0
  3. LEAF/Src/leaf-analysis.c +107 −53
  4. LEAF/Src/leaf-delay.c +145 −57
  5. LEAF/Src/leaf-distortion.c +64 −47
  6. LEAF/Src/leaf-dynamics.c +50 −22
  7. LEAF/Src/leaf-effects.c +149 −87
  8. LEAF/Src/leaf-electrical.c +4 −0
  9. LEAF/Src/leaf-envelopes.c +135 −48
  10. LEAF/Src/leaf-filters.c +158 −126
  11. LEAF/Src/leaf-instruments.c +75 −62
  12. LEAF/Src/leaf-mempool.c +8 −10
  13. LEAF/Src/leaf-midi.c +55 −39
  14. LEAF/Src/leaf-oscillators.c +94 −78
  15. LEAF/Src/leaf-physical.c +79 −79
  16. LEAF/Src/leaf-reverb.c +151 −96
  17. LEAF/Src/leaf-sampling.c +18 −35
  18. LEAF_JUCEPlugin/Source/MyTest.cpp +1 −1
LEAF/Inc/leaf-reverb.h+0−4
@@ -31,8 +31,6 @@ extern "C" { · 30 unmodified lines
3131
3232 float inv_441;
3333
34− int lengths[4];
35−
3634 tDelay allpassDelays[2];
3735 tDelay combDelay;
3836 float allpassCoeff;
@@ -66,8 +64,6 @@ extern "C" { · 27 unmodified lines
6664
6765 float inv_sr, inv_441;
6866
69− int lengths[15];
70−
7167 tLinearDelay allpassDelays[8];
7268 tLinearDelay combDelays[6];
7369 float allpassCoeff;
LEAF/Inc/leaf-sampling.h+2−0
@@ -124,6 +124,8 @@ extern "C" { · 123 unmodified lines
124124 void tSampler_setStart (tSampler* const, int32_t start);
125125 void tSampler_setEnd (tSampler* const, int32_t end);
126126
127+ static void handleStartEndChange (tSampler* const sp);
128+
127129 void tSampler_setCrossfadeLength (tSampler* const sp, uint32_t length);
128130
129131 void tSampler_setRate (tSampler* const, float rate);
LEAF/Src/leaf-analysis.c+107−53
@@ -21,38 +21,38 @@ · 20 unmodified lines
2121 //===========================================================================
2222 /* Envelope Follower */
2323 //===========================================================================
24−static void envelopefollower_init(tEnvelopeFollower* const ef, float attackThreshold, float decayCoeff)
24+
25+void tEnvelopeFollower_init(tEnvelopeFollower* const ef, float attackThreshold, float decayCoeff)
2526 {
26− _tEnvelopeFollower* e = *ef;
27+ _tEnvelopeFollower* e = *ef = (_tEnvelopeFollower*) leaf_alloc(sizeof(_tEnvelopeFollower));
2728
2829 e->y = 0.0f;
2930 e->a_thresh = attackThreshold;
3031 e->d_coeff = decayCoeff;
3132 }
3233
33−void tEnvelopeFollower_init(tEnvelopeFollower* const ef, float attackThreshold, float decayCoeff)
34−{
35− *ef = (_tEnvelopeFollower*) leaf_alloc(sizeof(_tEnvelopeFollower));
36− envelopefollower_init(ef, attackThreshold, decayCoeff);
37−}
38−
3934 void tEnvelopeFollower_free(tEnvelopeFollower* const ef)
4035 {
4136 _tEnvelopeFollower* e = *ef;
37+
4238 leaf_free(e);
4339 }
4440
4541 void tEnvelopeFollower_initToPool (tEnvelopeFollower* const ef, float attackThreshold, float decayCoeff, tMempool* const mp)
4642 {
4743 _tMempool* m = *mp;
48− *ef = (_tEnvelopeFollower*) mpool_alloc(sizeof(_tEnvelopeFollower), &m->pool);
49− envelopefollower_init(ef, attackThreshold, decayCoeff);
44+ _tEnvelopeFollower* e = *ef = (_tEnvelopeFollower*) mpool_alloc(sizeof(_tEnvelopeFollower), &m->pool);
45+
46+ e->y = 0.0f;
47+ e->a_thresh = attackThreshold;
48+ e->d_coeff = decayCoeff;
5049 }
5150
5251 void tEnvelopeFollower_freeFromPool (tEnvelopeFollower* const ef, tMempool* const mp)
5352 {
5453 _tMempool* m = *mp;
5554 _tEnvelopeFollower* e = *ef;
55+
5656 mpool_free(e, &m->pool);
5757 }
5858
@@ -89,38 +89,37 @@ int tEnvelopeFollower_attackThresh(tEnvelopeFollower* const ef, float attack · 30 unmodified lines
8989 //===========================================================================
9090 /* Power Follower */
9191 //===========================================================================
92−static void powerfollower_init(tPowerFollower* const pf, float factor)
92+void tPowerFollower_init(tPowerFollower* const pf, float factor)
9393 {
94− _tPowerFollower* p = *pf;
94+ _tPowerFollower* p = *pf = (_tPowerFollower*) leaf_alloc(sizeof(_tPowerFollower));
9595
9696 p->curr=0.0f;
9797 p->factor=factor;
9898 p->oneminusfactor=1.0f-factor;
9999 }
100100
101−void tPowerFollower_init(tPowerFollower* const pf, float factor)
102−{
103− *pf = (_tPowerFollower*) leaf_alloc(sizeof(_tPowerFollower));
104− powerfollower_init(pf, factor);
105−}
106−
107101 void tPowerFollower_free(tPowerFollower* const pf)
108102 {
109103 _tPowerFollower* p = *pf;
104+
110105 leaf_free(p);
111106 }
112107
113108 void tPowerFollower_initToPool (tPowerFollower* const pf, float factor, tMempool* const mp)
114109 {
115110 _tMempool* m = *mp;
116− *pf = (_tPowerFollower*) mpool_alloc(sizeof(_tPowerFollower), &m->pool);
117− powerfollower_init(pf, factor);
111+ _tPowerFollower* p = *pf = (_tPowerFollower*) mpool_alloc(sizeof(_tPowerFollower), &m->pool);
112+
113+ p->curr=0.0f;
114+ p->factor=factor;
115+ p->oneminusfactor=1.0f-factor;
118116 }
119117
120118 void tPowerFollower_freeFromPool (tPowerFollower* const pf, tMempool* const mp)
121119 {
122120 _tMempool* m = *mp;
123121 _tPowerFollower* p = *pf;
122+
124123 mpool_free(p, &m->pool);
125124 }
126125
@@ -154,9 +153,10 @@ float tPowerFollower_sample(tPowerFollower* const pf) · 27 unmodified lines
154153 //===========================================================================
155154 /* ---------------- env~ - simple envelope follower. ----------------- */
156155 //===========================================================================
157−static void envpd_init(tEnvPD* const xpd, int ws, int hs, int bs)
156+
157+void tEnvPD_init(tEnvPD* const xpd, int ws, int hs, int bs)
158158 {
159− _tEnvPD* x = *xpd;
159+ _tEnvPD* x = *xpd = (_tEnvPD*) leaf_allocAndClear(sizeof(_tEnvPD));
160160
161161 int period = hs, npoints = ws;
162162
@@ -196,29 +196,61 @@ static void envpd_init(tEnvPD* const xpd, int ws, int hs, int bs) · 33 unmodified lines
196196 // ~ ~ ~ ~ ~ ~ ~ ~
197197 }
198198
199−void tEnvPD_init(tEnvPD* const xpd, int ws, int hs, int bs)
200−{
201− *xpd = (_tEnvPD*) leaf_allocAndClear(sizeof(_tEnvPD));
202− envpd_init(xpd, ws, hs, bs);
203−}
204−
205199 void tEnvPD_free (tEnvPD* const xpd)
206200 {
207201 _tEnvPD* x = *xpd;
202+
208203 leaf_free(x);
209204 }
210205
211206 void tEnvPD_initToPool (tEnvPD* const xpd, int ws, int hs, int bs, tMempool* const mp)
212207 {
213208 _tMempool* m = *mp;
214− *xpd = (_tEnvPD*) mpool_allocAndClear(sizeof(_tEnvPD), &m->pool);
215− envpd_init(xpd, ws, hs, bs);
209+ _tEnvPD* x = *xpd = (_tEnvPD*) mpool_allocAndClear(sizeof(_tEnvPD), &m->pool);
210+
211+ int period = hs, npoints = ws;
212+
213+ int i;
214+
215+ if (npoints < 1) npoints = 1024;
216+ if (period < 1) period = npoints/2;
217+ if (period < npoints / MAXOVERLAP + 1)
218+ period = npoints / MAXOVERLAP + 1;
219+
220+ x->x_npoints = npoints;
221+ x->x_phase = 0;
222+ x->x_period = period;
223+
224+ x->windowSize = npoints;
225+ x->hopSize = period;
226+ x->blockSize = bs;
227+
228+ for (i = 0; i < MAXOVERLAP; i++) x->x_sumbuf[i] = 0;
229+ for (i = 0; i < npoints; i++)
230+ x->buf[i] = (1.0f - cosf((2 * PI * i) / npoints))/npoints;
231+ for (; i < npoints+INITVSTAKEN; i++) x->buf[i] = 0;
232+
233+ x->x_f = 0;
234+
235+ x->x_allocforvs = INITVSTAKEN;
236+
237+ // ~ ~ ~ dsp ~ ~ ~
238+ if (x->x_period % x->blockSize)
239+ {
240+ x->x_realperiod = x->x_period + x->blockSize - (x->x_period % x->blockSize);
241+ }
242+ else
243+ {
244+ x->x_realperiod = x->x_period;
245+ }
246+ // ~ ~ ~ ~ ~ ~ ~ ~
216247 }
217248
218249 void tEnvPD_freeFromPool (tEnvPD* const xpd, tMempool* const mp)
219250 {
220251 _tMempool* m = *mp;
221252 _tEnvPD* x = *xpd;
253+
222254 mpool_free(x, &m->pool);
223255 }
224256
@@ -426,9 +458,11 @@ static float snac_spectralpeak(tSNAC* const s, float periodlength); · 201 unmodified lines
426458 /******************************************************************************/
427459 /******************************** constructor, destructor *********************/
428460 /******************************************************************************/
429−static void snac_init(tSNAC* const snac, int overlaparg)
461+
462+
463+void tSNAC_init(tSNAC* const snac, int overlaparg)
430464 {
431− _tSNAC* s = *snac;
465+ _tSNAC* s = *snac = (_tSNAC*) leaf_allocAndClear(sizeof(_tSNAC));
432466
433467 s->biasfactor = DEFBIAS;
434468 s->timeindex = 0;
@@ -438,18 +472,13 @@ static void snac_init(tSNAC* const snac, int overlaparg) · 3 unmodified lines
438472 s->minrms = DEFMINRMS;
439473 s->framesize = SNAC_FRAME_SIZE;
440474
441− snac_biasbuf(snac);
442− tSNAC_setOverlap(snac, overlaparg);
443−}
444−
445−void tSNAC_init(tSNAC* const snac, int overlaparg)
446−{
447− _tSNAC* s = *snac = (_tSNAC*) leaf_allocAndClear(sizeof(_tSNAC));
448475 s->inputbuf = (float*) leaf_allocAndClear(sizeof(float) * SNAC_FRAME_SIZE);
449476 s->processbuf = (float*) leaf_allocAndClear(sizeof(float) * (SNAC_FRAME_SIZE * 2));
450477 s->spectrumbuf = (float*) leaf_allocAndClear(sizeof(float) * (SNAC_FRAME_SIZE / 2));
451478 s->biasbuf = (float*) leaf_allocAndClear(sizeof(float) * SNAC_FRAME_SIZE);
452− snac_init(snac, overlaparg);
479+
480+ snac_biasbuf(snac);
481+ tSNAC_setOverlap(snac, overlaparg);
453482 }
454483
455484 void tSNAC_free(tSNAC* const snac)
@@ -467,17 +496,29 @@ void tSNAC_initToPool (tSNAC* const snac, int overlaparg, tMempool* const · 11 unmodified lines
467496 {
468497 _tMempool* m = *mp;
469498 _tSNAC* s = *snac = (_tSNAC*) mpool_alloc(sizeof(_tSNAC), &m->pool);
499+
500+ s->biasfactor = DEFBIAS;
501+ s->timeindex = 0;
502+ s->periodindex = 0;
503+ s->periodlength = 0.;
504+ s->fidelity = 0.;
505+ s->minrms = DEFMINRMS;
506+ s->framesize = SNAC_FRAME_SIZE;
507+
470508 s->inputbuf = (float*) mpool_allocAndClear(sizeof(float) * SNAC_FRAME_SIZE, &m->pool);
471509 s->processbuf = (float*) mpool_allocAndClear(sizeof(float) * (SNAC_FRAME_SIZE * 2), &m->pool);
472510 s->spectrumbuf = (float*) mpool_allocAndClear(sizeof(float) * (SNAC_FRAME_SIZE / 2), &m->pool);
473511 s->biasbuf = (float*) mpool_allocAndClear(sizeof(float) * SNAC_FRAME_SIZE, &m->pool);
474− snac_init(snac, overlaparg);
512+
513+ snac_biasbuf(snac);
514+ tSNAC_setOverlap(snac, overlaparg);
475515 }
476516
477517 void tSNAC_freeFromPool (tSNAC* const snac, tMempool* const mp)
478518 {
479519 _tMempool* m = *mp;
480520 _tSNAC* s = *snac;
521+
481522 mpool_free(s->inputbuf, &m->pool);
482523 mpool_free(s->processbuf, &m->pool);
483524 mpool_free(s->spectrumbuf, &m->pool);
@@ -797,9 +838,9 @@ static void snac_biasbuf(tSNAC* const snac) · 313 unmodified lines
797838 //===========================================================================
798839 // PERIODDETECTION
799840 //===========================================================================
800−static void perioddetection_init (tPeriodDetection* const pd, float* in, float* out, int bufSize, int frameSize)
841+void tPeriodDetection_init (tPeriodDetection* const pd, float* in, float* out, int bufSize, int frameSize)
801842 {
802− _tPeriodDetection* p = *pd;
843+ _tPeriodDetection* p = *pd = (_tPeriodDetection*) leaf_allocAndClear(sizeof(_tPeriodDetection));
803844
804845 p->inBuffer = in;
805846 p->outBuffer = out;
@@ -814,22 +855,18 @@ static void perioddetection_init (tPeriodDetection* const pd, float* in, f · 8 unmodified lines
814855 p->windowSize = DEFWINDOWSIZE;
815856 p->fba = FBA;
816857
817− p->timeConstant = DEFTIMECONSTANT;
818− p->radius = expf(-1000.0f * p->hopSize * leaf.invSampleRate / p->timeConstant);
819−}
820−
821−void tPeriodDetection_init (tPeriodDetection* const pd, float* in, float* out, int bufSize, int frameSize)
822−{
823− _tPeriodDetection* p = *pd = (_tPeriodDetection*) leaf_allocAndClear(sizeof(_tPeriodDetection));
824− perioddetection_init(pd, in, out, bufSize, frameSize);
825−
826858 tEnvPD_init(&p->env, p->windowSize, p->hopSize, p->frameSize);
859+
827860 tSNAC_init(&p->snac, DEFOVERLAP);
861+
862+ p->timeConstant = DEFTIMECONSTANT;
863+ p->radius = expf(-1000.0f * p->hopSize * leaf.invSampleRate / p->timeConstant);
828864 }
829865
830866 void tPeriodDetection_free (tPeriodDetection* const pd)
831867 {
832868 _tPeriodDetection* p = *pd;
869+
833870 tEnvPD_free(&p->env);
834871 tSNAC_free(&p->snac);
835872 leaf_free(p);
@@ -839,16 +876,33 @@ void tPeriodDetection_initToPool (tPeriodDetection* const pd, float* in, flo · 3 unmodified lines
839876 {
840877 _tMempool* m = *mp;
841878 _tPeriodDetection* p = *pd = (_tPeriodDetection*) mpool_allocAndClear(sizeof(_tPeriodDetection), &m->pool);
842− perioddetection_init(pd, in, out, bufSize, frameSize);
879+
880+ p->inBuffer = in;
881+ p->outBuffer = out;
882+ p->bufSize = bufSize;
883+ p->frameSize = frameSize;
884+ p->framesPerBuffer = p->bufSize / p->frameSize;
885+ p->curBlock = 1;
886+ p->lastBlock = 0;
887+ p->index = 0;
888+
889+ p->hopSize = DEFHOPSIZE;
890+ p->windowSize = DEFWINDOWSIZE;
891+ p->fba = FBA;
843892
844893 tEnvPD_initToPool(&p->env, p->windowSize, p->hopSize, p->frameSize, mp);
894+
845895 tSNAC_initToPool(&p->snac, DEFOVERLAP, mp);
896+
897+ p->timeConstant = DEFTIMECONSTANT;
898+ p->radius = expf(-1000.0f * p->hopSize * leaf.invSampleRate / p->timeConstant);
846899 }
847900
848901 void tPeriodDetection_freeFromPool (tPeriodDetection* const pd, tMempool* const mp)
849902 {
850903 _tMempool* m = *mp;
851904 _tPeriodDetection* p = *pd;
905+
852906 tEnvPD_freeFromPool(&p->env, mp);
853907 tSNAC_freeFromPool(&p->snac, mp);
854908 mpool_free(p, &m->pool);
LEAF/Src/leaf-delay.c+145−57
@@ -19,31 +19,31 @@ · 18 unmodified lines
1919 #endif
2020
2121 // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Delay ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ //
22−static void delay_init (tDelay* const dl, uint32_t delay, uint32_t maxDelay)
22+void tDelay_init (tDelay* const dl, uint32_t delay, uint32_t maxDelay)
2323 {
24− _tDelay* d = *dl;
24+ _tDelay* d = *dl = (_tDelay*) leaf_alloc(sizeof(_tDelay));
2525
2626 d->maxDelay = maxDelay;
27+
2728 d->delay = delay;
29+
30+ d->buff = (float*) leaf_alloc(sizeof(float) * maxDelay);
31+
2832 d->inPoint = 0;
2933 d->outPoint = 0;
34+
3035 d->lastIn = 0.0f;
3136 d->lastOut = 0.0f;
37+
3238 d->gain = 1.0f;
3339
3440 tDelay_setDelay(dl, d->delay);
3541 }
3642
37−void tDelay_init (tDelay* const dl, uint32_t delay, uint32_t maxDelay)
38−{
39− _tDelay* d = *dl = (_tDelay*) leaf_alloc(sizeof(_tDelay));
40− d->buff = (float*) leaf_alloc(sizeof(float) * maxDelay);
41− delay_init(dl, delay, maxDelay);
42−}
43−
4443 void tDelay_free(tDelay* const dl)
4544 {
4645 _tDelay* d = *dl;
46+
4747 leaf_free(d->buff);
4848 leaf_free(d);
4949 }
@@ -52,14 +52,29 @@ void tDelay_initToPool (tDelay* const dl, uint32_t delay, uint32_t maxD · 2 unmodified lines
5252 {
5353 _tMempool* m = *mp;
5454 _tDelay* d = *dl = (_tDelay*) mpool_alloc(sizeof(_tDelay), &m->pool);
55+
56+ d->maxDelay = maxDelay;
57+
58+ d->delay = delay;
59+
5560 d->buff = (float*) mpool_alloc(sizeof(float) * maxDelay, &m->pool);
56− delay_init(dl, delay, maxDelay);
61+
62+ d->inPoint = 0;
63+ d->outPoint = 0;
64+
65+ d->lastIn = 0.0f;
66+ d->lastOut = 0.0f;
67+
68+ d->gain = 1.0f;
69+
70+ tDelay_setDelay(dl, d->delay);
5771 }
5872
5973 void tDelay_freeFromPool (tDelay* const dl, tMempool* const mp)
6074 {
6175 _tMempool* m = *mp;
6276 _tDelay* d = *dl;
77+
6378 mpool_free(d->buff, &m->pool);
6479 mpool_free(d, &m->pool);
6580 }
@@ -162,35 +177,33 @@ float tDelay_getGain (tDelay* const dl) · 96 unmodified lines
162177 }
163178
164179 // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ LinearDelay ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ //
165−static void lineardelay_init (tLinearDelay* const dl, float delay, uint32_t maxDelay)
180+void tLinearDelay_init (tLinearDelay* const dl, float delay, uint32_t maxDelay)
166181 {
167− _tLinearDelay* d = *dl;
182+ _tLinearDelay* d = *dl = (_tLinearDelay*) leaf_alloc(sizeof(_tLinearDelay));
168183
169184 d->maxDelay = maxDelay;
170−
185+
171186 if (delay > maxDelay) d->delay = maxDelay;
172187 else if (delay < 0.0f) d->delay = 0.0f;
173188 else d->delay = delay;
174189
190+ d->buff = (float*) leaf_allocAndClear(sizeof(float) * maxDelay);
191+
175192 d->gain = 1.0f;
193+
176194 d->lastIn = 0.0f;
177195 d->lastOut = 0.0f;
196+
178197 d->inPoint = 0;
179198 d->outPoint = 0;
180199
181200 tLinearDelay_setDelay(dl, d->delay);
182201 }
183202
184−void tLinearDelay_init (tLinearDelay* const dl, float delay, uint32_t maxDelay)
185−{
186− _tLinearDelay* d = *dl = (_tLinearDelay*) leaf_alloc(sizeof(_tLinearDelay));
187− d->buff = (float*) leaf_allocAndClear(sizeof(float) * maxDelay);
188− lineardelay_init(dl, delay, maxDelay);
189−}
190−
191203 void tLinearDelay_free(tLinearDelay* const dl)
192204 {
193205 _tLinearDelay* d = *dl;
206+
194207 leaf_free(d->buff);
195208 leaf_free(d);
196209 }
@@ -199,14 +212,31 @@ void tLinearDelay_initToPool (tLinearDelay* const dl, float delay, uint32_t · 2 unmodified lines
199212 {
200213 _tMempool* m = *mp;
201214 _tLinearDelay* d = *dl = (_tLinearDelay*) mpool_alloc(sizeof(_tLinearDelay), &m->pool);
202− d->buff = (float*) mpool_allocAndClear(sizeof(float) * maxDelay, &m->pool);
203− lineardelay_init(dl, delay, maxDelay);
215+
216+ d->maxDelay = maxDelay;
217+
218+ if (delay > maxDelay) d->delay = maxDelay;
219+ else if (delay < 0.0f) d->delay = 0.0f;
220+ else d->delay = delay;
221+
222+ d->buff = (float*) mpool_alloc(sizeof(float) * maxDelay, &m->pool);
223+
224+ d->gain = 1.0f;
225+
226+ d->lastIn = 0.0f;
227+ d->lastOut = 0.0f;
228+
229+ d->inPoint = 0;
230+ d->outPoint = 0;
231+
232+ tLinearDelay_setDelay(dl, d->delay);
204233 }
205234
206235 void tLinearDelay_freeFromPool(tLinearDelay* const dl, tMempool* const mp)
207236 {
208237 _tMempool* m = *mp;
209238 _tLinearDelay* d = *dl;
239+
210240 mpool_free(d->buff, &m->pool);
211241 mpool_free(d, &m->pool);
212242 }
@@ -218,6 +248,8 @@ void tLinearDelay_clear(tLinearDelay* const dl) · 5 unmodified lines
218248 {
219249 d->buff[i] = 0;
220250 }
251+
252+
221253 }
222254
223255 float tLinearDelay_tick (tLinearDelay* const dl, float input)
@@ -361,37 +393,38 @@ float tLinearDelay_getGain (tLinearDelay* const dl) · 137 unmodified lines
361393 }
362394
363395
396+
397+
398+
364399 /// Hermite Interpolated Delay
365400 // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ LinearDelay ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ //
366−static void hermitedelay_init (tHermiteDelay* const dl, float delay, uint32_t maxDelay)
401+void tHermiteDelay_init (tHermiteDelay* const dl, float delay, uint32_t maxDelay)
367402 {
368− _tHermiteDelay* d = *dl;
369−
403+ _tHermiteDelay* d = *dl = (_tHermiteDelay*) leaf_alloc(sizeof(_tHermiteDelay));
404+
370405 d->maxDelay = maxDelay;
371−
406+
372407 if (delay > maxDelay) d->delay = maxDelay;
373408 else if (delay < 0.0f) d->delay = 0.0f;
374409 else d->delay = delay;
375410
411+ d->buff = (float*) leaf_alloc(sizeof(float) * maxDelay);
412+
376413 d->gain = 1.0f;
414+
377415 d->lastIn = 0.0f;
378416 d->lastOut = 0.0f;
417+
379418 d->inPoint = 0;
380419 d->outPoint = 0;
381−
382− tHermiteDelay_setDelay(dl, d->delay);
383−}
384420
385−void tHermiteDelay_init (tHermiteDelay* const dl, float delay, uint32_t maxDelay)
386−{
387− _tHermiteDelay* d = *dl = (_tHermiteDelay*) leaf_alloc(sizeof(_tHermiteDelay));
388− d->buff = (float*) leaf_alloc(sizeof(float) * maxDelay);
389− hermitedelay_init(dl, delay, maxDelay);
421+ tHermiteDelay_setDelay(dl, d->delay);
390422 }
391423
392424 void tHermiteDelay_free(tHermiteDelay* const dl)
393425 {
394426 _tHermiteDelay* d = *dl;
427+
395428 leaf_free(d->buff);
396429 leaf_free(d);
397430 }
@@ -400,14 +433,31 @@ void tHermiteDelay_initToPool (tHermiteDelay* const dl, float delay, uint32_ · 2 unmodified lines
400433 {
401434 _tMempool* m = *mp;
402435 _tHermiteDelay* d = *dl = (_tHermiteDelay*) mpool_alloc(sizeof(_tHermiteDelay), &m->pool);
436+
437+ d->maxDelay = maxDelay;
438+
439+ if (delay > maxDelay) d->delay = maxDelay;
440+ else if (delay < 0.0f) d->delay = 0.0f;
441+ else d->delay = delay;
442+
403443 d->buff = (float*) mpool_alloc(sizeof(float) * maxDelay, &m->pool);
404− hermitedelay_init(dl, delay, maxDelay);
444+
445+ d->gain = 1.0f;
446+
447+ d->lastIn = 0.0f;
448+ d->lastOut = 0.0f;
449+
450+ d->inPoint = 0;
451+ d->outPoint = 0;
452+
453+ tHermiteDelay_setDelay(dl, d->delay);
405454 }
406455
407456 void tHermiteDelay_freeFromPool(tHermiteDelay* const dl, tMempool* const mp)
408457 {
409458 _tMempool* m = *mp;
410459 _tHermiteDelay* d = *dl;
460+
411461 mpool_free(d->buff, &m->pool);
412462 mpool_free(d, &m->pool);
413463 }
@@ -420,6 +470,8 @@ void tHermiteDelay_clear(tHermiteDelay* const dl) · 6 unmodified lines
420470 {
421471 d->buff[i] = 0;
422472 }
473+
474+
423475 }
424476
425477 float tHermiteDelay_tick (tHermiteDelay* const dl, float input)
@@ -564,10 +616,14 @@ float tHermiteDelay_getGain (tHermiteDelay* const dl) · 138 unmodified lines
564616 return d->gain;
565617 }
566618
619+
620+
621+
622+
567623 // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ AllpassDelay ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ //
568−static void allpass_init (tAllpassDelay* const dl, float delay, uint32_t maxDelay)
624+void tAllpassDelay_init (tAllpassDelay* const dl, float delay, uint32_t maxDelay)
569625 {
570− _tAllpassDelay* d = *dl;
626+ _tAllpassDelay* d = *dl = (_tAllpassDelay*) leaf_alloc(sizeof(_tAllpassDelay));
571627
572628 d->maxDelay = maxDelay;
573629
@@ -575,25 +631,25 @@ static void allpass_init (tAllpassDelay* const dl, float delay, uint32_t maxDel · 1 unmodified line
575631 else if (delay < 0.0f) d->delay = 0.0f;
576632 else d->delay = delay;
577633
634+ d->buff = (float*) leaf_alloc(sizeof(float) * maxDelay);
635+
578636 d->gain = 1.0f;
637+
579638 d->lastIn = 0.0f;
580639 d->lastOut = 0.0f;
640+
581641 d->inPoint = 0;
582642 d->outPoint = 0;
643+
583644 tAllpassDelay_setDelay(dl, d->delay);
645+
584646 d->apInput = 0.0f;
585647 }
586648
587−void tAllpassDelay_init (tAllpassDelay* const dl, float delay, uint32_t maxDelay)
588−{
589− _tAllpassDelay* d = *dl = (_tAllpassDelay*) leaf_alloc(sizeof(_tAllpassDelay));
590− d->buff = (float*) leaf_alloc(sizeof(float) * maxDelay);
591− allpass_init(dl, delay, maxDelay);
592−}
593−
594649 void tAllpassDelay_free(tAllpassDelay* const dl)
595650 {
596651 _tAllpassDelay* d = *dl;
652+
597653 leaf_free(d->buff);
598654 leaf_free(d);
599655 }
@@ -602,14 +658,33 @@ void tAllpassDelay_initToPool (tAllpassDelay* const dl, float delay, uint32_ · 2 unmodified lines
602658 {
603659 _tMempool* m = *mp;
604660 _tAllpassDelay* d = *dl = (_tAllpassDelay*) mpool_alloc(sizeof(_tAllpassDelay), &m->pool);
661+
662+ d->maxDelay = maxDelay;
663+
664+ if (delay > maxDelay) d->delay = maxDelay;
665+ else if (delay < 0.0f) d->delay = 0.0f;
666+ else d->delay = delay;
667+
605668 d->buff = (float*) mpool_alloc(sizeof(float) * maxDelay, &m->pool);
606− allpass_init(dl, delay, maxDelay);
669+
670+ d->gain = 1.0f;
671+
672+ d->lastIn = 0.0f;
673+ d->lastOut = 0.0f;
674+
675+ d->inPoint = 0;
676+ d->outPoint = 0;
677+
678+ tAllpassDelay_setDelay(dl, d->delay);
679+
680+ d->apInput = 0.0f;
607681 }
608682
609683 void tAllpassDelay_freeFromPool(tAllpassDelay* const dl, tMempool* const mp)
610684 {
611685 _tMempool* m = *mp;
612686 _tAllpassDelay* d = *dl;
687+
613688 mpool_free(d->buff, &m->pool);
614689 mpool_free(d, &m->pool);
615690 }
@@ -740,14 +815,19 @@ float tAllpassDelay_getGain (tAllpassDelay* const dl) · 124 unmodified lines
740815 }
741816
742817 // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ TapeDelay ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ //
743−static void tapedelay_init (tTapeDelay* const dl, float delay, uint32_t maxDelay)
818+void tTapeDelay_init (tTapeDelay* const dl, float delay, uint32_t maxDelay)
744819 {
745− _tTapeDelay* d = *dl;
820+ _tTapeDelay* d = *dl = (_tTapeDelay*) leaf_alloc(sizeof(_tTapeDelay));
746821
747822 d->maxDelay = maxDelay;
823+
824+ d->buff = (float*) leaf_alloc(sizeof(float) * maxDelay);
825+
748826 d->gain = 1.0f;
827+
749828 d->lastIn = 0.0f;
750829 d->lastOut = 0.0f;
830+
751831 d->idx = 0.0f;
752832 d->inc = 1.0f;
753833 d->inPoint = 0;
@@ -755,16 +835,10 @@ static void tapedelay_init (tTapeDelay* const dl, float delay, uint32_t maxDel · 1 unmodified line
755835 tTapeDelay_setDelay(dl, delay);
756836 }
757837
758−void tTapeDelay_init (tTapeDelay* const dl, float delay, uint32_t maxDelay)
759−{
760− _tTapeDelay* d = *dl = (_tTapeDelay*) leaf_alloc(sizeof(_tTapeDelay));
761− d->buff = (float*) leaf_alloc(sizeof(float) * maxDelay);
762− tapedelay_init(dl, delay, maxDelay);
763−}
764−
765838 void tTapeDelay_free(tTapeDelay* const dl)
766839 {
767840 _tTapeDelay* d = *dl;
841+
768842 leaf_free(d->buff);
769843 leaf_free(d);
770844 }
@@ -773,14 +847,28 @@ void tTapeDelay_initToPool (tTapeDelay* const dl, float delay, uint32_t maxD · 2 unmodified lines
773847 {
774848 _tMempool* m = *mp;
775849 _tTapeDelay* d = *dl = (_tTapeDelay*) mpool_alloc(sizeof(_tTapeDelay), &m->pool);
850+
851+ d->maxDelay = maxDelay;
852+
776853 d->buff = (float*) mpool_alloc(sizeof(float) * maxDelay, &m->pool);
777− tapedelay_init(dl, delay, maxDelay);
854+
855+ d->gain = 1.0f;
856+
857+ d->lastIn = 0.0f;
858+ d->lastOut = 0.0f;
859+
860+ d->idx = 0.0f;
861+ d->inc = 1.0f;
862+ d->inPoint = 0;
863+
864+ tTapeDelay_setDelay(dl, delay);
778865 }
779866
780867 void tTapeDelay_freeFromPool(tTapeDelay* const dl, tMempool* const mp)
781868 {
782869 _tMempool* m = *mp;
783870 _tTapeDelay* d = *dl;
871+
784872 mpool_free(d->buff, &m->pool);
785873 mpool_free(d, &m->pool);
786874 }
@@ -814,8 +902,8 @@ float tTapeDelay_tick (tTapeDelay* const dl, float input) · 27 unmodified lines
814902
815903 if (d->idx >= d->maxDelay) d->idx = 0.0f;
816904
817− if (d->lastOut) return d->lastOut;
818− else return 0.0f;
905+ if (d->lastOut)
906+ return d->lastOut;
819907 }
820908
821909 void tTapeDelay_incrementInPoint(tTapeDelay* const dl)
LEAF/Src/leaf-distortion.c+64−47
@@ -25,38 +25,38 @@ · 24 unmodified lines
2525 // Sample-Rate reducer
2626 //============================================================================================================
2727
28−static void samplereducer_init(tSampleReducer* const sr)
28+
29+void tSampleReducer_init(tSampleReducer* const sr)
2930 {
30− _tSampleReducer* s = *sr;
31+ _tSampleReducer* s = *sr = (_tSampleReducer*) leaf_alloc(sizeof(_tSampleReducer));
3132
3233 s->invRatio = 1.0f;
3334 s->hold = 0.0f;
3435 s->count = 0;
3536 }
3637
37−void tSampleReducer_init(tSampleReducer* const sr)
38−{
39− *sr = (_tSampleReducer*) leaf_alloc(sizeof(_tSampleReducer));
40− samplereducer_init(sr);
41−}
42−
4338 void tSampleReducer_free (tSampleReducer* const sr)
4439 {
4540 _tSampleReducer* s = *sr;
41+
4642 leaf_free(s);
4743 }
4844
4945 void tSampleReducer_initToPool (tSampleReducer* const sr, tMempool* const mp)
5046 {
5147 _tMempool* m = *mp;
52− *sr = (_tSampleReducer*) mpool_alloc(sizeof(_tSampleReducer), &m->pool);
53− samplereducer_init(sr);
48+ _tSampleReducer* s = *sr = (_tSampleReducer*) mpool_alloc(sizeof(_tSampleReducer), &m->pool);
49+
50+ s->invRatio = 1.0f;
51+ s->hold = 0.0f;
52+ s->count = 0;
5453 }
5554
5655 void tSampleReducer_freeFromPool (tSampleReducer* const sr, tMempool* const mp)
5756 {
5857 _tMempool* m = *mp;
5958 _tSampleReducer* s = *sr;
59+
6060 mpool_free(s, &m->pool);
6161 }
6262
@@ -85,9 +85,10 @@ void tSampleReducer_setRatio(tSampleReducer* const sr, float ratio) · 22 unmodified lines
8585 //============================================================================================================
8686 // Oversampler
8787 //============================================================================================================
88−static void oversampler_init(tOversampler* const osr, int ratio, oBool extraQuality)
88+// Latency is equal to the phase length (numTaps / ratio)
89+void tOversampler_init(tOversampler* const osr, int ratio, oBool extraQuality)
8990 {
90− _tOversampler* os = *osr;
91+ _tOversampler* os = *osr = (_tOversampler*) leaf_alloc(sizeof(_tOversampler));
9192
9293 uint8_t offset = 0;
9394 if (extraQuality) offset = 6;
@@ -99,17 +100,6 @@ static void oversampler_init(tOversampler* const osr, int ratio, oBool extraQual · 5 unmodified lines
99100 os->numTaps = firNumTaps[idx];
100101 os->phaseLength = os->numTaps / os->ratio;
101102 os->pCoeffs = (float*) firCoeffs[idx];
102− }
103−}
104−
105−// Latency is equal to the phase length (numTaps / ratio)
106−void tOversampler_init(tOversampler* const osr, int ratio, oBool extraQuality)
107−{
108− _tOversampler* os = *osr = (_tOversampler*) leaf_alloc(sizeof(_tOversampler));
109− oversampler_init(osr, ratio, extraQuality);
110− if (ratio == 2 || ratio == 4 ||
111− ratio == 8 || ratio == 16 ||
112− ratio == 32 || ratio == 64) {
113103 os->upState = leaf_alloc(sizeof(float) * os->numTaps * 2);
114104 os->downState = leaf_alloc(sizeof(float) * os->numTaps * 2);
115105 }
@@ -118,6 +108,7 @@ void tOversampler_init(tOversampler* const osr, int ratio, oBool extraQuality) · 2 unmodified lines
118108 void tOversampler_free(tOversampler* const osr)
119109 {
120110 _tOversampler* os = *osr;
111+
121112 leaf_free(os->upState);
122113 leaf_free(os->downState);
123114 leaf_free(os);
@@ -127,10 +118,17 @@ void tOversampler_initToPool (tOversampler* const osr, int ratio, oBool e · 3 unmodified lines
127118 {
128119 _tMempool* m = *mp;
129120 _tOversampler* os = *osr = (_tOversampler*) mpool_alloc(sizeof(_tOversampler), &m->pool);
130− oversampler_init(osr, ratio, extraQuality);
121+
122+ uint8_t offset = 0;
123+ if (extraQuality) offset = 6;
131124 if (ratio == 2 || ratio == 4 ||
132125 ratio == 8 || ratio == 16 ||
133126 ratio == 32 || ratio == 64) {
127+ os->ratio = ratio;
128+ int idx = (int)(log2f(os->ratio))-1+offset;
129+ os->numTaps = firNumTaps[idx];
130+ os->phaseLength = os->numTaps / os->ratio;
131+ os->pCoeffs = (float*) firCoeffs[idx];
134132 os->upState = mpool_alloc(sizeof(float) * os->numTaps * 2, &m->pool);
135133 os->downState = mpool_alloc(sizeof(float) * os->numTaps * 2, &m->pool);
136134 }
@@ -140,6 +138,7 @@ void tOversampler_freeFromPool (tOversampler* const osr, tMempool* const mp · 3 unmodified lines
140138 {
141139 _tMempool* m = *mp;
142140 _tOversampler* os = *osr;
141+
143142 mpool_free(os->upState, &m->pool);
144143 mpool_free(os->downState, &m->pool);
145144 mpool_free(os, &m->pool);
@@ -347,54 +346,72 @@ int tOversampler_getLatency(tOversampler* const osr) · 201 unmodified lines
347346 //============================================================================================================
348347 // WAVEFOLDER
349348 //============================================================================================================
349+
350+
350351 //from the paper: Virtual Analog Model of the Lockhart Wavefolder
351352 //by Fabián Esqueda, Henri Pöntynen, Julian D. Parker and Stefan Bilbao
352−static void lockhartwavefolder_init(tLockhartWavefolder* const wf)
353+
354+void tLockhartWavefolder_init(tLockhartWavefolder* const wf)
353355 {
354− _tLockhartWavefolder* w = *wf;
356+ _tLockhartWavefolder* w = *wf = (_tLockhartWavefolder*) leaf_alloc(sizeof(_tLockhartWavefolder));
355357
356358 w->Ln1 = 0.0;
357359 w->Fn1 = 0.0;
358360 w->xn1 = 0.0f;
359−
361+
360362 w->RL = 7.5e3;
361363 w->R = 15e3;
362364 w->VT = 26e-3;
363365 w->Is = 10e-16;
364−
366+
365367 w->a = 2.0*w->RL/w->R;
366368 w->b = (w->R+2.0*w->RL)/(w->VT*w->R);
367369 w->d = (w->RL*w->Is)/w->VT;
368370 w->half_a = 0.5 * w->a;
369371 w->longthing = (0.5*w->VT/w->b);
370−
372+
373+
371374 // Antialiasing error threshold
372375 w->thresh = 10e-10;
373376 }
374377
375−void tLockhartWavefolder_init(tLockhartWavefolder* const wf)
376−{
377− *wf = (_tLockhartWavefolder*) leaf_alloc(sizeof(_tLockhartWavefolder));
378− lockhartwavefolder_init(wf);
379−}
380−
381378 void tLockhartWavefolder_free(tLockhartWavefolder* const wf)
382379 {
383380 _tLockhartWavefolder* w = *wf;
381+
384382 leaf_free(w);
385383 }
386384
387385 void tLockhartWavefolder_initToPool (tLockhartWavefolder* const wf, tMempool* const mp)
388386 {
389387 _tMempool* m = *mp;
390− *wf = (_tLockhartWavefolder*) mpool_alloc(sizeof(_tLockhartWavefolder), &m->pool);
391− lockhartwavefolder_init(wf);
388+ _tLockhartWavefolder* w = *wf = (_tLockhartWavefolder*) mpool_alloc(sizeof(_tLockhartWavefolder), &m->pool);
389+
390+ w->Ln1 = 0.0;
391+ w->Fn1 = 0.0;
392+ w->xn1 = 0.0f;
393+
394+ w->RL = 7.5e3;
395+ w->R = 15e3;
396+ w->VT = 26e-3;
397+ w->Is = 10e-16;
398+
399+ w->a = 2.0*w->RL/w->R;
400+ w->b = (w->R+2.0*w->RL)/(w->VT*w->R);
401+ w->d = (w->RL*w->Is)/w->VT;
402+ w->half_a = 0.5 * w->a;
403+ w->longthing = (0.5*w->VT/w->b);
404+
405+
406+ // Antialiasing error threshold
407+ w->thresh = 10e-10;
392408 }
393409
394410 void tLockhartWavefolder_freeFromPool (tLockhartWavefolder* const wf, tMempool* const mp)
395411 {
396412 _tMempool* m = *mp;
397413 _tLockhartWavefolder* w = *wf;
414+
398415 mpool_free(w, &m->pool);
399416 }
400417
@@ -471,22 +488,17 @@ float tLockhartWavefolder_tick(tLockhartWavefolder* const wf, float samp) · 70 unmodified lines
471488 // CRUSHER
472489 //============================================================================================================
473490 #define SCALAR 5000.f
474−static void crusher_init (tCrusher* const cr)
491+
492+void tCrusher_init (tCrusher* const cr)
475493 {
476− _tCrusher* c = *cr;
494+ _tCrusher* c = *cr = (_tCrusher*) leaf_alloc(sizeof(_tCrusher));
477495
478496 c->op = 4;
479497 c->div = SCALAR;
480498 c->rnd = 0.25f;
481499 c->srr = 0.25f;
482− c->gain = (c->div / SCALAR) * 0.7f + 0.3f;
483−}
484−
485−void tCrusher_init (tCrusher* const cr)
486−{
487− _tCrusher* c = *cr = (_tCrusher*) leaf_alloc(sizeof(_tCrusher));
488− crusher_init(cr);
489500 tSampleReducer_init(&c->sReducer);
501+ c->gain = (c->div / SCALAR) * 0.7f + 0.3f;
490502 }
491503
492504 void tCrusher_free (tCrusher* const cr)
@@ -500,8 +512,13 @@ void tCrusher_initToPool (tCrusher* const cr, tMempool* const mp) · 7 unmodified lines
500512 {
501513 _tMempool* m = *mp;
502514 _tCrusher* c = *cr = (_tCrusher*) mpool_alloc(sizeof(_tCrusher), &m->pool);
503− crusher_init(cr);
515+
516+ c->op = 4;
517+ c->div = SCALAR;
518+ c->rnd = 0.25f;
519+ c->srr = 0.25f;
504520 tSampleReducer_initToPool(&c->sReducer, mp);
521+ c->gain = (c->div / SCALAR) * 0.7f + 0.3f;
505522 }
506523
507524 void tCrusher_freeFromPool (tCrusher* const cr, tMempool* const mp)
LEAF/Src/leaf-dynamics.c+50−22
@@ -19,9 +19,31 @@ · 18 unmodified lines
1919 //==============================================================================
2020
2121 // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Compressor ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ //
22−static void compressor_init(tCompressor* const comp)
22+
23+/*
24+ tCompressor* tCompressorInit(int tauAttack, int tauRelease)
25+ {
26+ tCompressor* c = &leaf.tCompressorRegistry[leaf.registryIndex[T_COMPRESSOR]++];
27+
28+ c->tauAttack = tauAttack;
29+ c->tauRelease = tauRelease;
30+
31+ c->x_G[0] = 0.0f, c->x_G[1] = 0.0f,
32+ c->y_G[0] = 0.0f, c->y_G[1] = 0.0f,
33+ c->x_T[0] = 0.0f, c->x_T[1] = 0.0f,
34+ c->y_T[0] = 0.0f, c->y_T[1] = 0.0f;
35+
36+ c->T = 0.0f; // Threshold
37+ c->R = 1.0f; // compression Ratio
38+ c->M = 0.0f; // decibel Make-up gain
39+ c->W = 0.0f; // decibel Width of knee transition
40+
41+ return c;
42+ }
43+ */
44+void tCompressor_init(tCompressor* const comp)
2345 {
24− _tCompressor* c = *comp;
46+ _tCompressor* c = *comp = (_tCompressor*) leaf_alloc(sizeof(_tCompressor));
2547
2648 c->tauAttack = 100;
2749 c->tauRelease = 100;
@@ -34,29 +56,34 @@ static void compressor_init(tCompressor* const comp) · 6 unmodified lines
3456 c->W = 1.0f; // decibel Make-up gain
3557 }
3658
37−void tCompressor_init(tCompressor* const comp)
38−{
39− *comp = (_tCompressor*) leaf_alloc(sizeof(_tCompressor));
40− compressor_init(comp);
41−}
42−
4359 void tCompressor_free(tCompressor* const comp)
4460 {
4561 _tCompressor* c = *comp;
62+
4663 leaf_free(c);
4764 }
4865
4966 void tCompressor_initToPool (tCompressor* const comp, tMempool* const mp)
5067 {
5168 _tMempool* m = *mp;
52− *comp = (_tCompressor*) mpool_alloc(sizeof(_tCompressor), &m->pool);
53− compressor_init(comp);
69+ _tCompressor* c = *comp = (_tCompressor*) mpool_alloc(sizeof(_tCompressor), &m->pool);
70+
71+ c->tauAttack = 100;
72+ c->tauRelease = 100;
73+
74+ c->isActive = OFALSE;
75+
76+ c->T = 0.0f; // Threshold
77+ c->R = 0.5f; // compression Ratio
78+ c->M = 3.0f; // decibel Width of knee transition
79+ c->W = 1.0f; // decibel Make-up gain
5480 }
5581
5682 void tCompressor_freeFromPool(tCompressor* const comp, tMempool* const mp)
5783 {
5884 _tMempool* m = *mp;
5985 _tCompressor* c = *comp;
86+
6087 mpool_free(c, &m->pool);
6188 }
6289
@@ -110,26 +137,22 @@ float tCompressor_tick(tCompressor* const comp, float in) · 47 unmodified lines
110137 }
111138
112139 /* Feedback Leveler */
113−static void feedbackleveler_init(tFeedbackLeveler* const fb, float targetLevel, float factor, float strength, int mode)
114−{
115− _tFeedbackLeveler* p = *fb;
116−
117− p->curr = 0.0f;
118− p->targetLevel = targetLevel;
119− p->mode = mode;
120− p->strength = strength;
121−}
122140
123141 void tFeedbackLeveler_init(tFeedbackLeveler* const fb, float targetLevel, float factor, float strength, int mode)
124142 {
125143 _tFeedbackLeveler* p = *fb = (_tFeedbackLeveler*) leaf_alloc(sizeof(_tFeedbackLeveler));
126− feedbackleveler_init(fb, targetLevel, factor, strength, mode);
144+
145+ p->curr=0.0f;
146+ p->targetLevel=targetLevel;
127147 tPowerFollower_init(&p->pwrFlw,factor);
148+ p->mode=mode;
149+ p->strength=strength;
128150 }
129151
130152 void tFeedbackLeveler_free(tFeedbackLeveler* const fb)
131153 {
132154 _tFeedbackLeveler* p = *fb;
155+
133156 tPowerFollower_free(&p->pwrFlw);
134157 leaf_free(p);
135158 }
@@ -138,14 +161,19 @@ void tFeedbackLeveler_initToPool (tFeedbackLeveler* const fb, float targe · 2 unmodified lines
138161 {
139162 _tMempool* m = *mp;
140163 _tFeedbackLeveler* p = *fb = (_tFeedbackLeveler*) mpool_alloc(sizeof(_tFeedbackLeveler), &m->pool);
141− feedbackleveler_init(fb, targetLevel, factor, strength, mode);
142− tPowerFollower_initToPool(&p->pwrFlw, factor, mp);
164+
165+ p->curr=0.0f;
166+ p->targetLevel=targetLevel;
167+ tPowerFollower_initToPool(&p->pwrFlw,factor, mp);
168+ p->mode=mode;
169+ p->strength=strength;
143170 }
144171
145172 void tFeedbackLeveler_freeFromPool (tFeedbackLeveler* const fb, tMempool* const mp)
146173 {
147174 _tMempool* m = *mp;
148175 _tFeedbackLeveler* p = *fb;
176+
149177 tPowerFollower_freeFromPool(&p->pwrFlw, mp);
150178 mpool_free(p, &m->pool);
151179 }
LEAF/Src/leaf-effects.c+149−87
@@ -18,12 +18,16 @@ · 17 unmodified lines
1818
1919 #endif
2020
21+
22+
2123 //============================================================================================================
2224 // TALKBOX
2325 //============================================================================================================
24−static void talkbox_init(tTalkbox* const voc, int bufsize)
26+
27+void tTalkbox_init(tTalkbox* const voc, int bufsize)
2528 {
26− _tTalkbox* v = *voc;
29+
30+ _tTalkbox* v = *voc = (_tTalkbox*) leaf_alloc(sizeof(_tTalkbox));
2731
2832 v->param[0] = 0.5f; //wet
2933 v->param[1] = 0.0f; //dry
@@ -32,29 +36,26 @@ static void talkbox_init(tTalkbox* const voc, int bufsize) · 2 unmodified lines
3236
3337 v->bufsize = bufsize;
3438
39+ v->car0 = (float*) leaf_alloc(sizeof(float) * v->bufsize);
40+ v->car1 = (float*) leaf_alloc(sizeof(float) * v->bufsize);
41+ v->window = (float*) leaf_alloc(sizeof(float) * v->bufsize);
42+ v->buf0 = (float*) leaf_alloc(sizeof(float) * v->bufsize);
43+ v->buf1 = (float*) leaf_alloc(sizeof(float) * v->bufsize);
44+
3545 tTalkbox_update(voc);
3646 tTalkbox_suspend(voc);
3747 }
3848
39−void tTalkbox_init(tTalkbox* const voc, int bufsize)
40−{
41− _tTalkbox* v = *voc = (_tTalkbox*) leaf_alloc(sizeof(_tTalkbox));
42− v->car0 = (float*) leaf_alloc(sizeof(float) * bufsize);
43− v->car1 = (float*) leaf_alloc(sizeof(float) * bufsize);
44− v->window = (float*) leaf_alloc(sizeof(float) * bufsize);
45− v->buf0 = (float*) leaf_alloc(sizeof(float) * bufsize);
46− v->buf1 = (float*) leaf_alloc(sizeof(float) * bufsize);
47− talkbox_init(voc, bufsize);
48−}
49−
5049 void tTalkbox_free(tTalkbox* const voc)
5150 {
5251 _tTalkbox* v = *voc;
52+
5353 leaf_free(v->buf1);
5454 leaf_free(v->buf0);
5555 leaf_free(v->window);
5656 leaf_free(v->car1);
5757 leaf_free(v->car0);
58+
5859 leaf_free(v);
5960 }
6061
@@ -62,23 +63,35 @@ void tTalkbox_initToPool (tTalkbox* const voc, int bufsize, tMempool* con · 1 unmodified line
6263 {
6364 _tMempool* m = *mp;
6465 _tTalkbox* v = *voc = (_tTalkbox*) mpool_alloc(sizeof(_tTalkbox), &m->pool);
65− v->car0 = (float*) mpool_alloc(sizeof(float) * bufsize, &m->pool);
66− v->car1 = (float*) mpool_alloc(sizeof(float) * bufsize, &m->pool);
67− v->window = (float*) mpool_alloc(sizeof(float) * bufsize, &m->pool);
68− v->buf0 = (float*) mpool_alloc(sizeof(float) * bufsize, &m->pool);
69− v->buf1 = (float*) mpool_alloc(sizeof(float) * bufsize, &m->pool);
70− talkbox_init(voc, bufsize);
66+
67+ v->param[0] = 0.5f; //wet
68+ v->param[1] = 0.0f; //dry
69+ v->param[2] = 0; // Swap
70+ v->param[3] = 1.0f; //quality
71+
72+ v->bufsize = bufsize;
73+
74+ v->car0 = (float*) mpool_alloc(sizeof(float) * v->bufsize, &m->pool);
75+ v->car1 = (float*) mpool_alloc(sizeof(float) * v->bufsize, &m->pool);
76+ v->window = (float*) mpool_alloc(sizeof(float) * v->bufsize, &m->pool);
77+ v->buf0 = (float*) mpool_alloc(sizeof(float) * v->bufsize, &m->pool);
78+ v->buf1 = (float*) mpool_alloc(sizeof(float) * v->bufsize, &m->pool);
79+
80+ tTalkbox_update(voc);
81+ tTalkbox_suspend(voc);
7182 }
7283
7384 void tTalkbox_freeFromPool (tTalkbox* const voc, tMempool* const mp)
7485 {
7586 _tMempool* m = *mp;
7687 _tTalkbox* v = *voc;
88+
7789 mpool_free(v->buf1, &m->pool);
7890 mpool_free(v->buf0, &m->pool);
7991 mpool_free(v->window, &m->pool);
8092 mpool_free(v->car1, &m->pool);
8193 mpool_free(v->car0, &m->pool);
94+
8295 mpool_free(v, &m->pool);
8396 }
8497
@@ -266,9 +279,9 @@ void tTalkbox_setQuality(tTalkbox* const voc, float quality) · 181 unmodified lines
266279 // VOCODER
267280 //============================================================================================================
268281
269−static void vocoder_init (tVocoder* const voc)
282+void tVocoder_init (tVocoder* const voc)
270283 {
271− _tVocoder* v = *voc;
284+ _tVocoder* v = *voc = (_tVocoder*) leaf_alloc(sizeof(_tVocoder));
272285
273286 v->param[0] = 0.33f; //input select
274287 v->param[1] = 0.50f; //output dB
@@ -282,29 +295,35 @@ static void vocoder_init (tVocoder* const voc) · 7 unmodified lines
282295 tVocoder_update(voc);
283296 }
284297
285−void tVocoder_init (tVocoder* const voc)
286−{
287− *voc = (_tVocoder*) leaf_alloc(sizeof(_tVocoder));
288− vocoder_init(voc);
289−}
290−
291298 void tVocoder_free (tVocoder* const voc)
292299 {
293300 _tVocoder* v = *voc;
301+
294302 leaf_free(v);
295303 }
296304
297305 void tVocoder_initToPool (tVocoder* const voc, tMempool* const mp)
298306 {
299307 _tMempool* m = *mp;
300− *voc = (_tVocoder*) mpool_alloc(sizeof(_tVocoder), &m->pool);
301− vocoder_init(voc);
308+ _tVocoder* v = *voc = (_tVocoder*) mpool_alloc(sizeof(_tVocoder), &m->pool);
309+
310+ v->param[0] = 0.33f; //input select
311+ v->param[1] = 0.50f; //output dB
312+ v->param[2] = 0.40f; //hi thru
313+ v->param[3] = 0.40f; //hi band
314+ v->param[4] = 0.16f; //envelope
315+ v->param[5] = 0.55f; //filter q
316+ v->param[6] = 0.6667f;//freq range
317+ v->param[7] = 0.33f; //num bands
318+
319+ tVocoder_update(voc);
302320 }
303321
304322 void tVocoder_freeFromPool (tVocoder* const voc, tMempool* const mp)
305323 {
306324 _tMempool* m = *mp;
307325 _tVocoder* v = *voc;
326+
308327 mpool_free(v, &m->pool);
309328 }
310329
@@ -854,9 +873,9 @@ static int pitchshift_attackdetect(_tPitchShift* ps) · 543 unmodified lines
854873 return (p->fba == 0 && (p->max > 60 && p->deltamax > 6)) ? 1 : 0;
855874 }
856875
857−static void pitchshift_init (tPitchShift* const psr, tPeriodDetection* pd, float* out, int bufSize)
876+void tPitchShift_init (tPitchShift* const psr, tPeriodDetection* pd, float* out, int bufSize)
858877 {
859− _tPitchShift* ps = *psr;
878+ _tPitchShift* ps = *psr = (_tPitchShift*) leaf_allocAndClear(sizeof(_tPitchShift));
860879 _tPeriodDetection* p = *pd;
861880
862881 ps->p = pd;
@@ -870,20 +889,17 @@ static void pitchshift_init (tPitchShift* const psr, tPeriodDetection* pd, float · 7 unmodified lines
870889 ps->index = 0;
871890 ps->pitchFactor = 1.0f;
872891
873− tSOLAD_setPitchFactor(&ps->sola, DEFPITCHRATIO);
874−}
875−
876−void tPitchShift_init (tPitchShift* const psr, tPeriodDetection* pd, float* out, int bufSize)
877−{
878− _tPitchShift* ps = *psr = (_tPitchShift*) leaf_allocAndClear(sizeof(_tPitchShift));
879892 tSOLAD_init(&ps->sola);
893+
880894 tHighpass_init(&ps->hp, HPFREQ);
881− pitchshift_init(psr, pd, out, bufSize);
895+
896+ tSOLAD_setPitchFactor(&ps->sola, DEFPITCHRATIO);
882897 }
883898
884899 void tPitchShift_free(tPitchShift* const psr)
885900 {
886901 _tPitchShift* ps = *psr;
902+
887903 tSOLAD_free(&ps->sola);
888904 tHighpass_free(&ps->hp);
889905 leaf_free(ps);
@@ -892,16 +908,34 @@ void tPitchShift_free(tPitchShift* const psr) · 2 unmodified lines
892908 void tPitchShift_initToPool (tPitchShift* const psr, tPeriodDetection* const pd, float* out, int bufSize, tMempool* const mp)
893909 {
894910 _tMempool* m = *mp;
911+
895912 _tPitchShift* ps = *psr = (_tPitchShift*) mpool_allocAndClear(sizeof(_tPitchShift), &m->pool);
913+
914+ _tPeriodDetection* p = *pd;
915+
916+ ps->p = pd;
917+
918+ ps->outBuffer = out;
919+ ps->bufSize = bufSize;
920+ ps->frameSize = p->frameSize;
921+ ps->framesPerBuffer = ps->bufSize / ps->frameSize;
922+ ps->curBlock = 1;
923+ ps->lastBlock = 0;
924+ ps->index = 0;
925+ ps->pitchFactor = 1.0f;
926+
896927 tSOLAD_initToPool(&ps->sola, mp);
928+
897929 tHighpass_initToPool(&ps->hp, HPFREQ, mp);
898− pitchshift_init(psr, pd, out, bufSize);
930+
931+ tSOLAD_setPitchFactor(&ps->sola, DEFPITCHRATIO);
899932 }
900933
901934 void tPitchShift_freeFromPool (tPitchShift* const psr, tMempool* const mp)
902935 {
903936 _tMempool* m = *mp;
904937 _tPitchShift* ps = *psr;
938+
905939 tSOLAD_freeFromPool(&ps->sola, mp);
906940 tHighpass_freeFromPool(&ps->hp, mp);
907941 mpool_free(ps, &m->pool);
@@ -1023,29 +1057,24 @@ float tPitchShift_shiftToFunc (tPitchShift* psr, float (*fun)(float)) · 115 unmodified lines
10231057 //============================================================================================================
10241058 // RETUNE
10251059 //============================================================================================================
1026−static void retune_init(tRetune* const rt, int numVoices, int bufSize, int frameSize)
1060+
1061+void tRetune_init(tRetune* const rt, int numVoices, int bufSize, int frameSize)
10271062 {
1028− _tRetune* r = *rt;
1063+ _tRetune* r = *rt = (_tRetune*) leaf_allocAndClear(sizeof(_tRetune));
10291064
10301065 r->bufSize = bufSize;
10311066 r->frameSize = frameSize;
10321067 r->numVoices = numVoices;
1033−
1068+
1069+ r->inBuffer = (float*) leaf_allocAndClear(sizeof(float) * r->bufSize);
1070+ r->outBuffers = (float**) leaf_allocAndClear(sizeof(float*) * r->numVoices);
1071+
10341072 r->hopSize = DEFHOPSIZE;
10351073 r->windowSize = DEFWINDOWSIZE;
10361074 r->fba = FBA;
10371075 tRetune_setTimeConstant(rt, DEFTIMECONSTANT);
10381076
10391077 r->inputPeriod = 0.0f;
1040−}
1041−
1042−void tRetune_init(tRetune* const rt, int numVoices, int bufSize, int frameSize)
1043−{
1044− _tRetune* r = *rt = (_tRetune*) leaf_allocAndClear(sizeof(_tRetune));
1045− retune_init(rt, numVoices, bufSize, frameSize);
1046−
1047− r->inBuffer = (float*) leaf_allocAndClear(sizeof(float) * r->bufSize);
1048− r->outBuffers = (float**) leaf_allocAndClear(sizeof(float*) * r->numVoices);
10491078
10501079 r->ps = (tPitchShift*) leaf_allocAndClear(sizeof(tPitchShift) * r->numVoices);
10511080 r->pitchFactor = (float*) leaf_allocAndClear(sizeof(float) * r->numVoices);
@@ -1066,6 +1095,7 @@ void tRetune_init(tRetune* const rt, int numVoices, int bufSize, int frameSize) · 14 unmodified lines
10661095 void tRetune_free(tRetune* const rt)
10671096 {
10681097 _tRetune* r = *rt;
1098+
10691099 tPeriodDetection_free(&r->pd);
10701100 for (int i = 0; i < r->numVoices; ++i)
10711101 {
@@ -1084,10 +1114,20 @@ void tRetune_initToPool (tRetune* const rt, int numVoices, int bufSize, · 12 unmodified lines
10841114 {
10851115 _tMempool* m = *mp;
10861116 _tRetune* r = *rt = (_tRetune*) mpool_alloc(sizeof(_tRetune), &m->pool);
1087− retune_init(rt, numVoices, bufSize, frameSize);
1117+
1118+ r->bufSize = bufSize;
1119+ r->frameSize = frameSize;
1120+ r->numVoices = numVoices;
10881121
10891122 r->inBuffer = (float*) mpool_allocAndClear(sizeof(float) * r->bufSize, &m->pool);
10901123 r->outBuffers = (float**) mpool_allocAndClear(sizeof(float*) * r->numVoices, &m->pool);
1124+
1125+ r->hopSize = DEFHOPSIZE;
1126+ r->windowSize = DEFWINDOWSIZE;
1127+ r->fba = FBA;
1128+ tRetune_setTimeConstant(rt, DEFTIMECONSTANT);
1129+
1130+ r->inputPeriod = 0.0f;
10911131
10921132 r->ps = (tPitchShift*) mpool_allocAndClear(sizeof(tPitchShift) * r->numVoices, &m->pool);
10931133 r->pitchFactor = (float*) mpool_allocAndClear(sizeof(float) * r->numVoices, &m->pool);
@@ -1109,6 +1149,7 @@ void tRetune_freeFromPool (tRetune* const rt, tMempool* const mp) · 15 unmodified lines
11091149 {
11101150 _tMempool* m = *mp;
11111151 _tRetune* r = *rt;
1152+
11121153 tPeriodDetection_freeFromPool(&r->pd, mp);
11131154 for (int i = 0; i < r->numVoices; ++i)
11141155 {
@@ -1162,6 +1203,8 @@ void tRetune_setNumVoices(tRetune* const rt, int numVoices) · 47 unmodified lines
11621203 r->outBuffers[i] = (float*) leaf_alloc(sizeof(float) * r->bufSize);
11631204 tPitchShift_init(&r->ps[i], &r->pd, r->outBuffers[i], r->bufSize);
11641205 }
1206+
1207+
11651208 }
11661209
11671210 void tRetune_setPitchFactors(tRetune* const rt, float pf)
@@ -1225,30 +1268,24 @@ float tRetune_getInputFreq(tRetune* const rt) · 57 unmodified lines
12251268 // AUTOTUNE
12261269 //============================================================================================================
12271270
1228−static void autotune_init(tAutotune* const rt, int numVoices, int bufSize, int frameSize)
1271+void tAutotune_init(tAutotune* const rt, int numVoices, int bufSize, int frameSize)
12291272 {
1230− _tAutotune* r = *rt;
1273+ _tAutotune* r = *rt = (_tAutotune*) leaf_alloc(sizeof(_tAutotune));
12311274
12321275 r->bufSize = bufSize;
12331276 r->frameSize = frameSize;
12341277 r->numVoices = numVoices;
12351278
1279+ r->inBuffer = (float*) leaf_alloc(sizeof(float) * r->bufSize);
1280+ r->outBuffers = (float**) leaf_alloc(sizeof(float*) * r->numVoices);
1281+
12361282 r->hopSize = DEFHOPSIZE;
12371283 r->windowSize = DEFWINDOWSIZE;
12381284 r->fba = FBA;
12391285 tAutotune_setTimeConstant(rt, DEFTIMECONSTANT);
1240−
1241− r->inputPeriod = 0.0f;
1242−}
1243−
1244−void tAutotune_init(tAutotune* const rt, int numVoices, int bufSize, int frameSize)
1245−{
1246− _tAutotune* r = *rt = (_tAutotune*) leaf_alloc(sizeof(_tAutotune));
1247− autotune_init(rt, numVoices, bufSize, frameSize);
12481286
1249− r->inBuffer = (float*) leaf_alloc(sizeof(float) * r->bufSize);
1250− r->outBuffers = (float**) leaf_alloc(sizeof(float*) * r->numVoices);
1251−
1287+
1288+
12521289 r->ps = (tPitchShift*) leaf_alloc(sizeof(tPitchShift) * r->numVoices);
12531290 r->freq = (float*) leaf_alloc(sizeof(float) * r->numVoices);
12541291 r->tickOutput = (float*) leaf_alloc(sizeof(float) * r->numVoices);
@@ -1263,11 +1300,15 @@ void tAutotune_init(tAutotune* const rt, int numVoices, int bufSize, int frameSi · 8 unmodified lines
12631300 {
12641301 tPitchShift_init(&r->ps[i], &r->pd, r->outBuffers[i], r->bufSize);
12651302 }
1303+
1304+ r->inputPeriod = 0.0f;
12661305 }
12671306
12681307 void tAutotune_free(tAutotune* const rt)
12691308 {
12701309 _tAutotune* r = *rt;
1310+
1311+ tPeriodDetection_free(&r->pd);
12711312 for (int i = 0; i < r->numVoices; ++i)
12721313 {
12731314 tPitchShift_free(&r->ps[i]);
@@ -1285,11 +1326,21 @@ void tAutotune_initToPool (tAutotune* const rt, int numVoices, int buf · 11 unmodified lines
12851326 {
12861327 _tMempool* m = *mp;
12871328 _tAutotune* r = *rt = (_tAutotune*) mpool_alloc(sizeof(_tAutotune), &m->pool);
1288− autotune_init(rt, numVoices, bufSize, frameSize);
1289−
1329+
1330+ r->bufSize = bufSize;
1331+ r->frameSize = frameSize;
1332+ r->numVoices = numVoices;
1333+
12901334 r->inBuffer = (float*) mpool_alloc(sizeof(float) * r->bufSize, &m->pool);
12911335 r->outBuffers = (float**) mpool_alloc(sizeof(float*) * r->numVoices, &m->pool);
1292−
1336+
1337+ r->hopSize = DEFHOPSIZE;
1338+ r->windowSize = DEFWINDOWSIZE;
1339+ r->fba = FBA;
1340+ tAutotune_setTimeConstant(rt, DEFTIMECONSTANT);
1341+
1342+
1343+
12931344 r->ps = (tPitchShift*) mpool_alloc(sizeof(tPitchShift) * r->numVoices, &m->pool);
12941345 r->freq = (float*) mpool_alloc(sizeof(float) * r->numVoices, &m->pool);
12951346 r->tickOutput = (float*) mpool_alloc(sizeof(float) * r->numVoices, &m->pool);
@@ -1304,18 +1355,21 @@ void tAutotune_initToPool (tAutotune* const rt, int numVoices, int buf · 8 unmodified lines
13041355 {
13051356 tPitchShift_initToPool(&r->ps[i], &r->pd, r->outBuffers[i], r->bufSize, mp);
13061357 }
1358+
1359+ r->inputPeriod = 0.0f;
13071360 }
13081361
13091362 void tAutotune_freeFromPool (tAutotune* const rt, tMempool* const mp)
13101363 {
13111364 _tMempool* m = *mp;
13121365 _tAutotune* r = *rt;
1366+
1367+ tPeriodDetection_freeFromPool(&r->pd, mp);
13131368 for (int i = 0; i < r->numVoices; ++i)
13141369 {
13151370 tPitchShift_freeFromPool(&r->ps[i], mp);
13161371 mpool_free(r->outBuffers[i], &m->pool);
13171372 }
1318− tPeriodDetection_freeFromPool(&r->pd, mp);
13191373 mpool_free(r->tickOutput, &m->pool);
13201374 mpool_free(r->freq, &m->pool);
13211375 mpool_free(r->ps, &m->pool);
@@ -1367,6 +1421,8 @@ void tAutotune_setNumVoices(tAutotune* const rt, int numVoices) · 45 unmodified lines
13671421 r->outBuffers[i] = (float*) leaf_alloc(sizeof(float) * r->bufSize);
13681422 tPitchShift_init(&r->ps[i], &r->pd, r->outBuffers[i], r->bufSize);
13691423 }
1424+
1425+
13701426 }
13711427
13721428 void tAutotune_setFreqs(tAutotune* const rt, float f)
@@ -1428,28 +1484,12 @@ float tAutotune_getInputFreq(tAutotune* const rt) · 55 unmodified lines
14281484 // FORMANTSHIFTER
14291485 //============================================================================================================
14301486 // algorithm from Tom Baran's autotalent code.
1431−static void formantshifter_init(tFormantShifter* const fsr, int order)
1432−{
1433− _tFormantShifter* fs = *fsr;
1434−
1435− fs->ford = order;
1436− fs->falph = powf(0.001f, 40.0f * leaf.invSampleRate);
1437− fs->flamb = -(0.8517f*sqrtf(atanf(0.06583f*leaf.sampleRate))-0.1916f);
1438− fs->fhp = 0.0f;
1439− fs->flp = 0.0f;
1440− fs->flpa = powf(0.001f, 10.0f * leaf.invSampleRate);
1441− fs->fmute = 1.0f;
1442− fs->fmutealph = powf(0.001f, 0.5f * leaf.invSampleRate);
1443− fs->cbi = 0;
1444− fs->intensity = 1.0f;
1445− fs->invIntensity = 1.0f;
1446−}
14471487
14481488 void tFormantShifter_init(tFormantShifter* const fsr, int order)
14491489 {
14501490 _tFormantShifter* fs = *fsr = (_tFormantShifter*) leaf_alloc(sizeof(_tFormantShifter));
1451− formantshifter_init(fsr, order);
14521491
1492+ fs->ford = order;
14531493 fs->fk = (float*) leaf_allocAndClear(sizeof(float) * fs->ford);
14541494 fs->fb = (float*) leaf_allocAndClear(sizeof(float) * fs->ford);
14551495 fs->fc = (float*) leaf_allocAndClear(sizeof(float) * fs->ford);
@@ -1460,6 +1500,16 @@ void tFormantShifter_init(tFormantShifter* const fsr, int order) · 4 unmodified lines
14601500 fs->ftvec = (float*) leaf_allocAndClear(sizeof(float) * fs->ford);
14611501 fs->fbuff = (float*) leaf_allocAndClear(sizeof(float*) * fs->ford);
14621502
1503+ fs->falph = powf(0.001f, 40.0f * leaf.invSampleRate);
1504+ fs->flamb = -(0.8517f*sqrtf(atanf(0.06583f*leaf.sampleRate))-0.1916f);
1505+ fs->fhp = 0.0f;
1506+ fs->flp = 0.0f;
1507+ fs->flpa = powf(0.001f, 10.0f * leaf.invSampleRate);
1508+ fs->fmute = 1.0f;
1509+ fs->fmutealph = powf(0.001f, 0.5f * leaf.invSampleRate);
1510+ fs->cbi = 0;
1511+ fs->intensity = 1.0f;
1512+ fs->invIntensity = 1.0f;
14631513 tHighpass_init(&fs->hp, 10.0f);
14641514 tHighpass_init(&fs->hp2, 10.0f);
14651515 tFeedbackLeveler_init(&fs->fbl1, 0.99f, 0.005f, 0.125f, 0);
@@ -1490,8 +1540,8 @@ void tFormantShifter_initToPool (tFormantShifter* const fsr, int order, · 24 unmodified lines
14901540 {
14911541 _tMempool* m = *mp;
14921542 _tFormantShifter* fs = *fsr = (_tFormantShifter*) mpool_alloc(sizeof(_tFormantShifter), &m->pool);
1493− formantshifter_init(fsr, order);
14941543
1544+ fs->ford = order;
14951545 fs->fk = (float*) mpool_allocAndClear(sizeof(float) * fs->ford, &m->pool);
14961546 fs->fb = (float*) mpool_allocAndClear(sizeof(float) * fs->ford, &m->pool);
14971547 fs->fc = (float*) mpool_allocAndClear(sizeof(float) * fs->ford, &m->pool);
@@ -1500,8 +1550,20 @@ void tFormantShifter_initToPool (tFormantShifter* const fsr, int order, · 2 unmodified lines
15001550 fs->fsig = (float*) mpool_allocAndClear(sizeof(float) * fs->ford, &m->pool);
15011551 fs->fsmooth = (float*) mpool_allocAndClear(sizeof(float) * fs->ford, &m->pool);
15021552 fs->ftvec = (float*) mpool_allocAndClear(sizeof(float) * fs->ford, &m->pool);
1553+
15031554 fs->fbuff = (float*) mpool_allocAndClear(sizeof(float*) * fs->ford, &m->pool);
1555+
15041556
1557+ fs->falph = powf(0.001f, 10.0f * leaf.invSampleRate);
1558+ fs->flamb = -(0.8517f*sqrtf(atanf(0.06583f*leaf.sampleRate))-0.1916f);
1559+ fs->fhp = 0.0f;
1560+ fs->flp = 0.0f;
1561+ fs->flpa = powf(0.001f, 10.0f * leaf.invSampleRate);
1562+ fs->fmute = 1.0f;
1563+ fs->fmutealph = powf(0.001f, 1.0f * leaf.invSampleRate);
1564+ fs->cbi = 0;
1565+ fs->intensity = 1.0f;
1566+ fs->invIntensity = 1.0f;
15051567 tHighpass_initToPool(&fs->hp, 20.0f, mp);
15061568 tHighpass_initToPool(&fs->hp2, 20.0f, mp);
15071569 tFeedbackLeveler_initToPool(&fs->fbl1, 0.8f, .005f, 0.125, 1, mp);
LEAF/Src/leaf-electrical.c+4−0
@@ -167,12 +167,14 @@ static void wdf_init(tWDF* const wdf, WDFComponentType type, float value, tWDF* · 166 unmodified lines
167167 void tWDF_init(tWDF* const wdf, WDFComponentType type, float value, tWDF* const rL, tWDF* const rR)
168168 {
169169 *wdf = (_tWDF*) leaf_alloc(sizeof(_tWDF));
170+
170171 wdf_init(wdf, type, value, rL, rR);
171172 }
172173
173174 void tWDF_free(tWDF* const wdf)
174175 {
175176 _tWDF* r = *wdf;
177+
176178 leaf_free(r);
177179 }
178180
@@ -180,6 +182,7 @@ void tWDF_initToPool (tWDF* const wdf, WDFComponentType type, flo · 1 unmodified line
180182 {
181183 _tMempool* m = *mp;
182184 *wdf = (_tWDF*) mpool_alloc(sizeof(_tWDF), &m->pool);
185+
183186 wdf_init(wdf, type, value, rL, rR);
184187 }
185188
@@ -187,6 +190,7 @@ void tWDF_freeFromPool (tWDF* const wdf, tMempool* const mp) · 1 unmodified line
187190 {
188191 _tMempool* m = *mp;
189192 _tWDF* r = *wdf;
193+
190194 mpool_free(r, &m->pool);
191195 }
192196
LEAF/Src/leaf-envelopes.c+135−48
@@ -24,9 +24,9 @@ · 23 unmodified lines
2424 #endif
2525
2626 // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Envelope ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ //
27−static void envelope_init(tEnvelope* const envlp, float attack, float decay, oBool loop)
27+void tEnvelope_init(tEnvelope* const envlp, float attack, float decay, oBool loop)
2828 {
29− _tEnvelope* env = *envlp;
29+ _tEnvelope* env = *envlp = (_tEnvelope*) leaf_alloc(sizeof(_tEnvelope));
3030
3131 env->exp_buff = exp_decay;
3232 env->inc_buff = attack_decay_inc;
@@ -64,12 +64,6 @@ static void envelope_init(tEnvelope* const envlp, float attack, float decay, · 31 unmodified lines
6464 env->rampInc = env->inc_buff[rampIndex];
6565 }
6666
67−void tEnvelope_init(tEnvelope* const envlp, float attack, float decay, oBool loop)
68−{
69− *envlp = (_tEnvelope*) leaf_alloc(sizeof(_tEnvelope));
70− envelope_init(envlp, attack, decay, loop);
71−}
72−
7367 void tEnvelope_free(tEnvelope* const envlp)
7468 {
7569 _tEnvelope* env = *envlp;
@@ -79,8 +73,42 @@ void tEnvelope_free(tEnvelope* const envlp) · 3 unmodified lines
7973 void tEnvelope_initToPool (tEnvelope* const envlp, float attack, float decay, oBool loop, tMempool* const mp)
8074 {
8175 _tMempool* m = *mp;
82− *envlp = (_tEnvelope*) mpool_alloc(sizeof(_tEnvelope), &m->pool);
83− envelope_init(envlp, attack, decay, loop);
76+ _tEnvelope* env = *envlp = (_tEnvelope*) mpool_alloc(sizeof(_tEnvelope), &m->pool);
77+
78+ env->exp_buff = exp_decay;
79+ env->inc_buff = attack_decay_inc;
80+ env->buff_size = sizeof(exp_decay);
81+
82+ env->loop = loop;
83+
84+ if (attack > 8192.0f)
85+ attack = 8192.0f;
86+ if (attack < 0.0f)
87+ attack = 0.0f;
88+
89+ if (decay > 8192.0f)
90+ decay = 8192.0f;
91+ if (decay < 0.0f)
92+ decay = 0.0f;
93+
94+ int16_t attackIndex = ((int16_t)(attack * 8.0f))-1;
95+ int16_t decayIndex = ((int16_t)(decay * 8.0f))-1;
96+ int16_t rampIndex = ((int16_t)(2.0f * 8.0f))-1;
97+
98+ if (attackIndex < 0)
99+ attackIndex = 0;
100+ if (decayIndex < 0)
101+ decayIndex = 0;
102+ if (rampIndex < 0)
103+ rampIndex = 0;
104+
105+ env->inRamp = OFALSE;
106+ env->inAttack = OFALSE;
107+ env->inDecay = OFALSE;
108+
109+ env->attackInc = env->inc_buff[attackIndex];
110+ env->decayInc = env->inc_buff[decayIndex];
111+ env->rampInc = env->inc_buff[rampIndex];
84112 }
85113
86114 void tEnvelope_freeFromPool (tEnvelope* const envlp, tMempool* const mp)
@@ -226,9 +254,9 @@ float tEnvelope_tick(tEnvelope* const envlp) · 139 unmodified lines
226254 }
227255
228256 /* ADSR */
229−static void adsr_init(tADSR* const adsrenv, float attack, float decay, float sustain, float release)
257+void tADSR_init(tADSR* const adsrenv, float attack, float decay, float sustain, float release)
230258 {
231− _tADSR* adsr = *adsrenv;
259+ _tADSR* adsr = *adsrenv = (_tADSR*) leaf_alloc(sizeof(_tADSR));
232260
233261 adsr->exp_buff = exp_decay;
234262 adsr->inc_buff = attack_decay_inc;
@@ -282,30 +310,75 @@ static void adsr_init(tADSR* const adsrenv, float attack, float decay, float · 47 unmodified lines
282310 adsr->rampInc = adsr->inc_buff[rampIndex];
283311 }
284312
285−
286−void tADSR_init(tADSR* const adsrenv, float attack, float decay, float sustain, float release)
287−{
288− _tADSR* adsr = *adsrenv = (_tADSR*) leaf_alloc(sizeof(_tADSR));
289− adsr_init(adsrenv, attack, decay, sustain, release);
290−}
291−
292313 void tADSR_free(tADSR* const adsrenv)
293314 {
294315 _tADSR* adsr = *adsrenv;
316+
295317 leaf_free(adsr);
296318 }
297319
298320 void tADSR_initToPool (tADSR* const adsrenv, float attack, float decay, float sustain, float release, tMempool* const mp)
299321 {
300322 _tMempool* m = *mp;
301− *adsrenv = (_tADSR*) mpool_alloc(sizeof(_tADSR), &m->pool);
302− adsr_init(adsrenv, attack, decay, sustain, release);
323+ _tADSR* adsr = *adsrenv = (_tADSR*) mpool_alloc(sizeof(_tADSR), &m->pool);
324+
325+ adsr->exp_buff = exp_decay;
326+ adsr->inc_buff = attack_decay_inc;
327+ adsr->buff_size = sizeof(exp_decay);
328+
329+ if (attack > 8192.0f)
330+ attack = 8192.0f;
331+ if (attack < 0.0f)
332+ attack = 0.0f;
333+
334+ if (decay > 8192.0f)
335+ decay = 8192.0f;
336+ if (decay < 0.0f)
337+ decay = 0.0f;
338+
339+ if (sustain > 1.0f)
340+ sustain = 1.0f;
341+ if (sustain < 0.0f)
342+ sustain = 0.0f;
343+
344+ if (release > 8192.0f)
345+ release = 8192.0f;
346+ if (release < 0.0f)
347+ release = 0.0f;
348+
349+ int16_t attackIndex = ((int16_t)(attack * 8.0f))-1;
350+ int16_t decayIndex = ((int16_t)(decay * 8.0f))-1;
351+ int16_t releaseIndex = ((int16_t)(release * 8.0f))-1;
352+ int16_t rampIndex = ((int16_t)(2.0f * 8.0f))-1;
353+
354+ if (attackIndex < 0)
355+ attackIndex = 0;
356+ if (decayIndex < 0)
357+ decayIndex = 0;
358+ if (releaseIndex < 0)
359+ releaseIndex = 0;
360+ if (rampIndex < 0)
361+ rampIndex = 0;
362+
363+ adsr->inRamp = OFALSE;
364+ adsr->inAttack = OFALSE;
365+ adsr->inDecay = OFALSE;
366+ adsr->inSustain = OFALSE;
367+ adsr->inRelease = OFALSE;
368+
369+ adsr->sustain = sustain;
370+
371+ adsr->attackInc = adsr->inc_buff[attackIndex];
372+ adsr->decayInc = adsr->inc_buff[decayIndex];
373+ adsr->releaseInc = adsr->inc_buff[releaseIndex];
374+ adsr->rampInc = adsr->inc_buff[rampIndex];
303375 }
304376
305377 void tADSR_freeFromPool (tADSR* const adsrenv, tMempool* const mp)
306378 {
307379 _tMempool* m = *mp;
308380 _tADSR* adsr = *adsrenv;
381+
309382 mpool_free(adsr, &m->pool);
310383 }
311384
@@ -489,12 +562,12 @@ float tADSR_tick(tADSR* const adsrenv) · 177 unmodified lines
489562 }
490563
491564 /* Ramp */
492−static void ramp_init(tRamp* const r, float time, int samples_per_tick)
565+void tRamp_init(tRamp* const r, float time, int samples_per_tick)
493566 {
494− _tRamp* ramp = *r;
567+ _tRamp* ramp = *r = (_tRamp*) leaf_alloc(sizeof(_tRamp));
495568
496569 ramp->inv_sr_ms = 1.0f/(leaf.sampleRate*0.001f);
497− ramp->minimum_time = ramp->inv_sr_ms * samples_per_tick;
570+ ramp->minimum_time = ramp->inv_sr_ms * samples_per_tick;
498571 ramp->curr = 0.0f;
499572 ramp->dest = 0.0f;
500573
@@ -511,29 +584,41 @@ static void ramp_init(tRamp* const r, float time, int samples_per_tick) · 10 unmodified lines
511584 ramp->inc = ((ramp->dest - ramp->curr) / ramp->time * ramp->inv_sr_ms) * (float)ramp->samples_per_tick;
512585 }
513586
514−void tRamp_init(tRamp* const r, float time, int samples_per_tick)
515−{
516− *r = (_tRamp*) leaf_alloc(sizeof(_tRamp));
517− ramp_init(r, time, samples_per_tick);
518−}
519−
520587 void tRamp_free(tRamp* const r)
521588 {
522589 _tRamp* ramp = *r;
590+
523591 leaf_free(ramp);
524592 }
525593
526594 void tRamp_initToPool (tRamp* const r, float time, int samples_per_tick, tMempool* const mp)
527595 {
528596 _tMempool* m = *mp;
529− *r = (_tRamp*) mpool_alloc(sizeof(_tRamp), &m->pool);
530− ramp_init(r, time, samples_per_tick);
597+ _tRamp* ramp = *r = (_tRamp*) mpool_alloc(sizeof(_tRamp), &m->pool);
598+
599+ ramp->inv_sr_ms = 1.0f/(leaf.sampleRate*0.001f);
600+ ramp->minimum_time = ramp->inv_sr_ms * samples_per_tick;
601+ ramp->curr = 0.0f;
602+ ramp->dest = 0.0f;
603+
604+ if (time < ramp->minimum_time)
605+ {
606+ ramp->time = ramp->minimum_time;
607+ }
608+ else
609+ {
610+ ramp->time = time;
611+ }
612+
613+ ramp->samples_per_tick = samples_per_tick;
614+ ramp->inc = ((ramp->dest - ramp->curr) / ramp->time * ramp->inv_sr_ms) * (float)ramp->samples_per_tick;
531615 }
532616
533617 void tRamp_freeFromPool (tRamp* const r, tMempool* const mp)
534618 {
535619 _tMempool* m = *mp;
536620 _tRamp* ramp = *r;
621+
537622 mpool_free(ramp, &m->pool);
538623 }
539624
@@ -599,41 +684,43 @@ void tRampSampleRateChanged(tRamp* const ramp) · 59 unmodified lines
599684
600685
601686 /* Exponential Smoother */
602−static void expsmooth_init(tExpSmooth* const expsmooth, float val, float factor)
603−{ // factor is usually a value between 0 and 0.1. Lower value is slower. 0.01 for example gives you a smoothing time of about 10ms
604− _tExpSmooth* smooth = *expsmooth;
605−
606− smooth->curr = val;
607− smooth->dest = val;
608− if (factor < 0) factor = 0;
609− if (factor > 1) factor = 1;
610− smooth->factor = factor;
611− smooth->oneminusfactor = 1.0f - factor;
612−}
613−
614687 void tExpSmooth_init(tExpSmooth* const expsmooth, float val, float factor)
615688 { // factor is usually a value between 0 and 0.1. Lower value is slower. 0.01 for example gives you a smoothing time of about 10ms
616− *expsmooth = (_tExpSmooth*) leaf_alloc(sizeof(_tExpSmooth));
617− expsmooth_init(expsmooth, val, factor);
689+ _tExpSmooth* smooth = *expsmooth = (_tExpSmooth*) leaf_alloc(sizeof(_tExpSmooth));
690+
691+ smooth->curr=val;
692+ smooth->dest=val;
693+ if (factor<0) factor=0;
694+ if (factor>1) factor=1;
695+ smooth->factor=factor;
696+ smooth->oneminusfactor=1.0f-factor;
618697 }
619698
620699 void tExpSmooth_free(tExpSmooth* const expsmooth)
621700 {
622701 _tExpSmooth* smooth = *expsmooth;
702+
623703 leaf_free(smooth);
624704 }
625705
626706 void tExpSmooth_initToPool (tExpSmooth* const expsmooth, float val, float factor, tMempool* const mp)
627707 {
628708 _tMempool* m = *mp;
629− *expsmooth = (_tExpSmooth*) mpool_alloc(sizeof(_tExpSmooth), &m->pool);
630− expsmooth_init(expsmooth, val, factor);
709+ _tExpSmooth* smooth = *expsmooth = (_tExpSmooth*) mpool_alloc(sizeof(_tExpSmooth), &m->pool);
710+
711+ smooth->curr=val;
712+ smooth->dest=val;
713+ if (factor<0) factor=0;
714+ if (factor>1) factor=1;
715+ smooth->factor=factor;
716+ smooth->oneminusfactor=1.0f-factor;
631717 }
632718
633719 void tExpSmooth_freeFromPool (tExpSmooth* const expsmooth, tMempool* const mp)
634720 {
635721 _tMempool* m = *mp;
636722 _tExpSmooth* smooth = *expsmooth;
723+
637724 mpool_free(smooth, &m->pool);
638725 }
639726
LEAF/Src/leaf-filters.c+158−126
@@ -21,23 +21,21 @@ · 20 unmodified lines
2121 #endif
2222
2323 // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ OnePole Filter ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ //
24−static void allpass_init(tAllpass* const ft, float initDelay, uint32_t maxDelay)
25−{
26− _tAllpass* f = *ft;
27− f->gain = 0.7f;
28− f->lastOut = 0.0f;
29−}
30−
3124 void tAllpass_init(tAllpass* const ft, float initDelay, uint32_t maxDelay)
3225 {
3326 _tAllpass* f = *ft = (_tAllpass*) leaf_alloc(sizeof(_tAllpass));
27+
28+ f->gain = 0.7f;
29+
30+ f->lastOut = 0.0f;
31+
3432 tLinearDelay_init(&f->delay, initDelay, maxDelay);
35− allpass_init(ft, initDelay, maxDelay);
3633 }
3734
3835 void tAllpass_free(tAllpass* const ft)
3936 {
4037 _tAllpass* f = *ft;
38+
4139 tLinearDelay_free(&f->delay);
4240 leaf_free(f);
4341 }
@@ -46,14 +44,19 @@ void tAllpass_initToPool (tAllpass* const ft, float initDelay, uint32_t m · 2 unmodified lines
4644 {
4745 _tMempool* m = *mp;
4846 _tAllpass* f = *ft = (_tAllpass*) mpool_alloc(sizeof(_tAllpass), &m->pool);
47+
48+ f->gain = 0.7f;
49+
50+ f->lastOut = 0.0f;
51+
4952 tLinearDelay_initToPool(&f->delay, initDelay, maxDelay, mp);
50− allpass_init(ft, initDelay, maxDelay);
5153 }
5254
5355 void tAllpass_freeFromPool (tAllpass* const ft, tMempool* const mp)
5456 {
5557 _tMempool* m = *mp;
5658 _tAllpass* f = *ft;
59+
5760 tLinearDelay_freeFromPool(&f->delay, mp);
5861 mpool_free(f, &m->pool);
5962 }
@@ -86,9 +89,9 @@ float tAllpass_tick(tAllpass* const ft, float input) · 26 unmodified lines
8689 }
8790
8891 // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ OnePole Filter ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ //
89−static void onepole_init(tOnePole* const ft, float freq)
92+void tOnePole_init(tOnePole* const ft, float freq)
9093 {
91− _tOnePole* f = *ft;
94+ _tOnePole* f = *ft = (_tOnePole*) leaf_alloc(sizeof(_tOnePole));
9295
9396 f->gain = 1.0f;
9497 f->a0 = 1.0;
@@ -99,29 +102,32 @@ static void onepole_init(tOnePole* const ft, float freq) · 4 unmodified lines
99102 f->lastOut = 0.0f;
100103 }
101104
102−void tOnePole_init(tOnePole* const ft, float freq)
103−{
104− *ft = (_tOnePole*) leaf_alloc(sizeof(_tOnePole));
105− onepole_init(ft, freq);
106−}
107−
108105 void tOnePole_free(tOnePole* const ft)
109106 {
110107 _tOnePole* f = *ft;
108+
111109 leaf_free(f);
112110 }
113111
114112 void tOnePole_initToPool (tOnePole* const ft, float freq, tMempool* const mp)
115113 {
116114 _tMempool* m = *mp;
117− *ft = (_tOnePole*) mpool_alloc(sizeof(_tOnePole), &m->pool);
118− onepole_init(ft, freq);
115+ _tOnePole* f = *ft = (_tOnePole*) mpool_alloc(sizeof(_tOnePole), &m->pool);
116+
117+ f->gain = 1.0f;
118+ f->a0 = 1.0;
119+
120+ tOnePole_setFreq(ft, freq);
121+
122+ f->lastIn = 0.0f;
123+ f->lastOut = 0.0f;
119124 }
120125
121126 void tOnePole_freeFromPool (tOnePole* const ft, tMempool* const mp)
122127 {
123128 _tMempool* m = *mp;
124129 _tOnePole* f = *ft;
130+
125131 mpool_free(f, &m->pool);
126132 }
127133
@@ -187,9 +193,9 @@ float tOnePole_tick(tOnePole* const ft, float input) · 59 unmodified lines
187193 }
188194
189195 // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ TwoPole Filter ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ //
190−static void twopole_init(tTwoPole* const ft)
196+void tTwoPole_init(tTwoPole* const ft)
191197 {
192− _tTwoPole* f = *ft;
198+ _tTwoPole* f = *ft = (_tTwoPole*) leaf_alloc(sizeof(_tTwoPole));
193199
194200 f->gain = 1.0f;
195201 f->a0 = 1.0;
@@ -199,29 +205,31 @@ static void twopole_init(tTwoPole* const ft) · 3 unmodified lines
199205 f->lastOut[1] = 0.0f;
200206 }
201207
202−void tTwoPole_init(tTwoPole* const ft)
203−{
204− *ft = (_tTwoPole*) leaf_alloc(sizeof(_tTwoPole));
205− twopole_init(ft);
206−}
207−
208208 void tTwoPole_free(tTwoPole* const ft)
209209 {
210210 _tTwoPole* f = *ft;
211+
211212 leaf_free(f);
212213 }
213214
214215 void tTwoPole_initToPool (tTwoPole* const ft, tMempool* const mp)
215216 {
216217 _tMempool* m = *mp;
217− *ft = (_tTwoPole*) mpool_alloc(sizeof(_tTwoPole), &m->pool);
218− twopole_init(ft);
218+ _tTwoPole* f = *ft = (_tTwoPole*) mpool_alloc(sizeof(_tTwoPole), &m->pool);
219+
220+ f->gain = 1.0f;
221+ f->a0 = 1.0;
222+ f->b0 = 1.0;
223+
224+ f->lastOut[0] = 0.0f;
225+ f->lastOut[1] = 0.0f;
219226 }
220227
221228 void tTwoPole_freeFromPool (tTwoPole* const ft, tMempool* const mp)
222229 {
223230 _tMempool* m = *mp;
224231 _tTwoPole* f = *ft;
232+
225233 mpool_free(f, &m->pool);
226234 }
227235
@@ -313,9 +321,9 @@ void tTwoPoleSampleRateChanged (tTwoPole* const ft) · 85 unmodified lines
313321 }
314322
315323 // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ OneZero Filter ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ //
316−static void onezero_init(tOneZero* const ft, float theZero)
324+void tOneZero_init(tOneZero* const ft, float theZero)
317325 {
318− _tOneZero* f = *ft;
326+ _tOneZero* f = *ft = (_tOneZero*) leaf_alloc(sizeof(_tOneZero));
319327
320328 f->gain = 1.0f;
321329 f->lastIn = 0.0f;
@@ -323,29 +331,29 @@ static void onezero_init(tOneZero* const ft, float theZero) · 1 unmodified line
323331 tOneZero_setZero(ft, theZero);
324332 }
325333
326−void tOneZero_init(tOneZero* const ft, float theZero)
327−{
328− *ft = (_tOneZero*) leaf_alloc(sizeof(_tOneZero));
329− onezero_init(ft, theZero);
330−}
331−
332334 void tOneZero_free(tOneZero* const ft)
333335 {
334336 _tOneZero* f = *ft;
337+
335338 leaf_free(f);
336339 }
337340
338341 void tOneZero_initToPool (tOneZero* const ft, float theZero, tMempool* const mp)
339342 {
340343 _tMempool* m = *mp;
341− *ft = (_tOneZero*) mpool_alloc(sizeof(_tOneZero), &m->pool);
342− onezero_init(ft, theZero);
344+ _tOneZero* f = *ft = (_tOneZero*) mpool_alloc(sizeof(_tOneZero), &m->pool);
345+
346+ f->gain = 1.0f;
347+ f->lastIn = 0.0f;
348+ f->lastOut = 0.0f;
349+ tOneZero_setZero(ft, theZero);
343350 }
344351
345352 void tOneZero_freeFromPool (tOneZero* const ft, tMempool* const mp)
346353 {
347354 _tMempool* m = *mp;
348355 _tOneZero* f = *ft;
356+
349357 mpool_free(f, &m->pool);
350358 }
351359
@@ -429,38 +437,37 @@ float tOneZero_getPhaseDelay(tOneZero* const ft, float frequency ) · 77 unmodified lines
429437 }
430438
431439 // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ TwoZero Filter ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ //
432−static void twozero_init(tTwoZero* const ft)
440+void tTwoZero_init(tTwoZero* const ft)
433441 {
434− _tTwoZero* f = *ft;
442+ _tTwoZero* f = *ft = (_tTwoZero*) leaf_alloc(sizeof(_tTwoZero));
435443
436444 f->gain = 1.0f;
437445 f->lastIn[0] = 0.0f;
438446 f->lastIn[1] = 0.0f;
439447 }
440448
441−void tTwoZero_init(tTwoZero* const ft)
442−{
443− *ft = (_tTwoZero*) leaf_alloc(sizeof(_tTwoZero));
444− twozero_init(ft);
445−}
446−
447449 void tTwoZero_free(tTwoZero* const ft)
448450 {
449451 _tTwoZero* f = *ft;
452+
450453 leaf_free(f);
451454 }
452455
453456 void tTwoZero_initToPool (tTwoZero* const ft, tMempool* const mp)
454457 {
455458 _tMempool* m = *mp;
456− *ft = (_tTwoZero*) mpool_alloc(sizeof(_tTwoZero), &m->pool);
457− twozero_init(ft);
459+ _tTwoZero* f = *ft = (_tTwoZero*) mpool_alloc(sizeof(_tTwoZero), &m->pool);
460+
461+ f->gain = 1.0f;
462+ f->lastIn[0] = 0.0f;
463+ f->lastIn[1] = 0.0f;
458464 }
459465
460466 void tTwoZero_freeFromPool (tTwoZero* const ft, tMempool* const mp)
461467 {
462468 _tMempool* m = *mp;
463469 _tTwoZero* f = *ft;
470+
464471 mpool_free(f, &m->pool);
465472 }
466473
@@ -535,9 +542,9 @@ void tTwoZeroSampleRateChanged(tTwoZero* const ft) · 68 unmodified lines
535542 }
536543
537544 // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ PoleZero Filter ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ //
538−static void polezero_init(tPoleZero* const pzf)
545+void tPoleZero_init(tPoleZero* const pzf)
539546 {
540− _tPoleZero* f = *pzf;
547+ _tPoleZero* f = *pzf = (_tPoleZero*) leaf_alloc(sizeof(_tPoleZero));
541548
542549 f->gain = 1.0f;
543550 f->b0 = 1.0;
@@ -547,15 +554,10 @@ static void polezero_init(tPoleZero* const pzf) · 3 unmodified lines
547554 f->lastOut = 0.0f;
548555 }
549556
550−void tPoleZero_init(tPoleZero* const pzf)
551−{
552− *pzf = (_tPoleZero*) leaf_alloc(sizeof(_tPoleZero));
553− polezero_init(pzf);
554−}
555−
556557 void tPoleZero_free(tPoleZero* const pzf)
557558 {
558559 _tPoleZero* f = *pzf;
560+
559561 leaf_free(f);
560562 }
561563
@@ -563,13 +565,20 @@ void tPoleZero_initToPool (tPoleZero* const pzf, tMempool* const mp) · 1 unmodified line
563565 {
564566 _tMempool* m = *mp;
565567 _tPoleZero* f = *pzf = (_tPoleZero*) mpool_alloc(sizeof(_tPoleZero), &m->pool);
566− polezero_init(pzf);
568+
569+ f->gain = 1.0f;
570+ f->b0 = 1.0;
571+ f->a0 = 1.0;
572+
573+ f->lastIn = 0.0f;
574+ f->lastOut = 0.0f;
567575 }
568576
569577 void tPoleZero_freeFromPool (tPoleZero* const pzf, tMempool* const mp)
570578 {
571579 _tMempool* m = *mp;
572580 _tPoleZero* f = *pzf;
581+
573582 mpool_free(f, &m->pool);
574583 }
575584
@@ -661,9 +670,9 @@ float tPoleZero_tick(tPoleZero* const pzf, float input) · 85 unmodified lines
661670 }
662671
663672 // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ BiQuad Filter ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ //
664−static void biquad_init(tBiQuad* const ft)
673+void tBiQuad_init(tBiQuad* const ft)
665674 {
666− _tBiQuad* f = *ft;
675+ _tBiQuad* f = *ft = (_tBiQuad*) leaf_alloc(sizeof(_tBiQuad));
667676
668677 f->gain = 1.0f;
669678
@@ -676,29 +685,34 @@ static void biquad_init(tBiQuad* const ft) · 6 unmodified lines
676685 f->lastOut[1] = 0.0f;
677686 }
678687
679−void tBiQuad_init(tBiQuad* const ft)
680−{
681− *ft = (_tBiQuad*) leaf_alloc(sizeof(_tBiQuad));
682− biquad_init(ft);
683−}
684−
685688 void tBiQuad_free(tBiQuad* const ft)
686689 {
687690 _tBiQuad* f = *ft;
691+
688692 leaf_free(f);
689693 }
690694
691695 void tBiQuad_initToPool (tBiQuad* const ft, tMempool* const mp)
692696 {
693697 _tMempool* m = *mp;
694− *ft = (_tBiQuad*) mpool_alloc(sizeof(_tBiQuad), &m->pool);
695− biquad_init(ft);
698+ _tBiQuad* f = *ft = (_tBiQuad*) mpool_alloc(sizeof(_tBiQuad), &m->pool);
699+
700+ f->gain = 1.0f;
701+
702+ f->b0 = 0.0f;
703+ f->a0 = 0.0f;
704+
705+ f->lastIn[0] = 0.0f;
706+ f->lastIn[1] = 0.0f;
707+ f->lastOut[0] = 0.0f;
708+ f->lastOut[1] = 0.0f;
696709 }
697710
698711 void tBiQuad_freeFromPool (tBiQuad* const ft, tMempool* const mp)
699712 {
700713 _tMempool* m = *mp;
701714 _tBiQuad* f = *ft;
715+
702716 mpool_free(f, &m->pool);
703717 }
704718
@@ -827,9 +841,9 @@ void tBiQuadSampleRateChanged(tBiQuad* const ft) · 122 unmodified lines
827841
828842 // Less efficient, more accurate version of SVF, in which cutoff frequency is taken as floating point Hz value and tanf
829843 // is calculated when frequency changes.
830−static void svf_init(tSVF* const svff, SVFType type, float freq, float Q)
844+void tSVF_init(tSVF* const svff, SVFType type, float freq, float Q)
831845 {
832− _tSVF* svf = *svff;
846+ _tSVF* svf = *svff = (_tSVF*) leaf_alloc(sizeof(_tSVF));
833847
834848 svf->type = type;
835849
@@ -843,23 +857,28 @@ static void svf_init(tSVF* const svff, SVFType type, float freq, float Q) · 7 unmodified lines
843857 svf->a3 = svf->g*svf->a2;
844858 }
845859
846−void tSVF_init(tSVF* const svff, SVFType type, float freq, float Q)
847−{
848− *svff = (_tSVF*) leaf_alloc(sizeof(_tSVF));
849− svf_init(svff, type, freq, Q);
850−}
851−
852860 void tSVF_free(tSVF* const svff)
853861 {
854862 _tSVF* svf = *svff;
863+
855864 leaf_free(svf);
856865 }
857866
858867 void tSVF_initToPool (tSVF* const svff, SVFType type, float freq, float Q, tMempool* const mp)
859868 {
860869 _tMempool* m = *mp;
861− *svff = (_tSVF*) mpool_alloc(sizeof(_tSVF), &m->pool);
862− svf_init(svff, type, freq, Q);
870+ _tSVF* svf = *svff = (_tSVF*) mpool_alloc(sizeof(_tSVF), &m->pool);
871+
872+ svf->type = type;
873+
874+ svf->ic1eq = 0;
875+ svf->ic2eq = 0;
876+
877+ svf->g = tanf(PI * freq * leaf.invSampleRate);
878+ svf->k = 1.0f/Q;
879+ svf->a1 = 1.0f/(1.0f + svf->g * (svf->g + svf->k));
880+ svf->a2 = svf->g*svf->a1;
881+ svf->a3 = svf->g*svf->a2;
863882 }
864883
865884 void tSVF_freeFromPool (tSVF* const svff, tMempool* const mp)
@@ -911,9 +930,9 @@ void tSVF_setQ(tSVF* const svff, float Q) · 45 unmodified lines
911930 }
912931
913932 // Efficient version of tSVF where frequency is set based on 12-bit integer input for lookup in tanh wavetable.
914−static void efficientsvf_init(tEfficientSVF* const svff, SVFType type, uint16_t input, float Q)
933+void tEfficientSVF_init(tEfficientSVF* const svff, SVFType type, uint16_t input, float Q)
915934 {
916− _tEfficientSVF* svf = *svff;
935+ _tEfficientSVF* svf = *svff = (_tEfficientSVF*) leaf_alloc(sizeof(_tEfficientSVF));
917936
918937 svf->type = type;
919938
@@ -927,29 +946,35 @@ static void efficientsvf_init(tEfficientSVF* const svff, SVFType type, uint16_ · 7 unmodified lines
927946 svf->a3 = svf->g*svf->a2;
928947 }
929948
930−void tEfficientSVF_init(tEfficientSVF* const svff, SVFType type, uint16_t input, float Q)
931−{
932− *svff = (_tEfficientSVF*) leaf_alloc(sizeof(_tEfficientSVF));
933− efficientsvf_init(svff, type, input, Q);
934−}
935−
936949 void tEfficientSVF_free(tEfficientSVF* const svff)
937950 {
938951 _tEfficientSVF* svf = *svff;
952+
939953 leaf_free(svf);
940954 }
941955
942956 void tEfficientSVF_initToPool (tEfficientSVF* const svff, SVFType type, uint16_t input, float Q, tMempool* const mp)
943957 {
944958 _tMempool* m = *mp;
945− *svff = (_tEfficientSVF*) mpool_alloc(sizeof(_tEfficientSVF), &m->pool);
946− efficientsvf_init(svff, type, input, Q);
959+ _tEfficientSVF* svf = *svff = (_tEfficientSVF*) mpool_alloc(sizeof(_tEfficientSVF), &m->pool);
960+
961+ svf->type = type;
962+
963+ svf->ic1eq = 0;
964+ svf->ic2eq = 0;
965+
966+ svf->g = filtertan[input];
967+ svf->k = 1.0f/Q;
968+ svf->a1 = 1.0f/(1.0f+svf->g*(svf->g+svf->k));
969+ svf->a2 = svf->g*svf->a1;
970+ svf->a3 = svf->g*svf->a2;
947971 }
948972
949973 void tEfficientSVF_freeFromPool (tEfficientSVF* const svff, tMempool* const mp)
950974 {
951975 _tMempool* m = *mp;
952976 _tEfficientSVF* svf = *svff;
977+
953978 mpool_free(svf, &m->pool);
954979 }
955980
@@ -994,39 +1019,41 @@ void tEfficientSVF_setQ(tEfficientSVF* const svff, float Q) · 38 unmodified lines
9941019 }
9951020
9961021 /* Highpass */
997−static void highpass_init(tHighpass* const ft, float freq)
1022+void tHighpass_init(tHighpass* const ft, float freq)
9981023 {
999− _tHighpass* f = *ft;
1024+ _tHighpass* f = *ft = (_tHighpass*) leaf_alloc(sizeof(_tHighpass));
10001025
10011026 f->R = (1.0f - (freq * leaf.twoPiTimesInvSampleRate));
10021027 f->ys = 0.0f;
10031028 f->xs = 0.0f;
1029+
10041030 f->frequency = freq;
10051031 }
10061032
1007−void tHighpass_init(tHighpass* const ft, float freq)
1008−{
1009− *ft = (_tHighpass*) leaf_alloc(sizeof(_tHighpass));
1010− highpass_init(ft, freq);
1011−}
1012−
10131033 void tHighpass_free(tHighpass* const ft)
10141034 {
10151035 _tHighpass* f = *ft;
1036+
10161037 leaf_free(f);
10171038 }
10181039
10191040 void tHighpass_initToPool (tHighpass* const ft, float freq, tMempool* const mp)
10201041 {
10211042 _tMempool* m = *mp;
1022− *ft = (_tHighpass*) mpool_allocAndClear(sizeof(_tHighpass), &m->pool);
1023− highpass_init(ft, freq);
1043+ _tHighpass* f = *ft = (_tHighpass*) mpool_allocAndClear(sizeof(_tHighpass), &m->pool);
1044+
1045+ f->R = (1.0f - (freq * leaf.twoPiTimesInvSampleRate));
1046+ f->ys = 0.0f;
1047+ f->xs = 0.0f;
1048+
1049+ f->frequency = freq;
10241050 }
10251051
10261052 void tHighpass_freeFromPool (tHighpass* const ft, tMempool* const mp)
10271053 {
10281054 _tMempool* m = *mp;
10291055 _tHighpass* f = *ft;
1056+
10301057 mpool_free(f, &m->pool);
10311058 }
10321059
@@ -1059,38 +1086,35 @@ void tHighpassSampleRateChanged(tHighpass* const ft) · 26 unmodified lines
10591086 f->R = (1.0f-((f->frequency * 2.0f * 3.14f) * leaf.invSampleRate));
10601087 }
10611088
1062−///////////////////////////////////////////////////////////////////////
1063−static void butterworth_init(tButterworth* const ft, int N, float f1, float f2)
1089+void tButterworth_init(tButterworth* const ft, int N, float f1, float f2)
10641090 {
1065− _tButterworth* f = *ft;
1091+ _tButterworth* f = *ft = (_tButterworth*) leaf_alloc(sizeof(_tButterworth));
10661092
10671093 f->f1 = f1;
10681094 f->f2 = f2;
10691095 f->gain = 1.0f;
1096+
10701097 f->N = N;
10711098
10721099 if (f->N > NUM_SVF_BW) f->N = NUM_SVF_BW;
1073−}
1074−
1075−void tButterworth_init(tButterworth* const ft, int N, float f1, float f2)
1076−{
1077− _tButterworth* f = *ft = (_tButterworth*) leaf_alloc(sizeof(_tButterworth));
1078− butterworth_init(ft, N, f1, f2);
1079− for(int i = 0; i < f->N/2; ++i)
1100+
1101+ for(int i = 0; i < N/2; ++i)
10801102 {
1081− tSVF_init(&f->low[i], SVFTypeHighpass, f->f1, 0.5f/cosf((1.0f+2.0f*i)*PI/(2*f->N)));
1082− tSVF_init(&f->high[i], SVFTypeLowpass, f->f2, 0.5f/cosf((1.0f+2.0f*i)*PI/(2*f->N)));
1103+ tSVF_init(&f->low[i], SVFTypeHighpass, f1, 0.5f/cosf((1.0f+2.0f*i)*PI/(2*N)));
1104+ tSVF_init(&f->high[i], SVFTypeLowpass, f2, 0.5f/cosf((1.0f+2.0f*i)*PI/(2*N)));
10831105 }
10841106 }
10851107
10861108 void tButterworth_free(tButterworth* const ft)
10871109 {
10881110 _tButterworth* f = *ft;
1111+
10891112 for(int i = 0; i < f->N/2; ++i)
10901113 {
10911114 tSVF_free(&f->low[i]);
10921115 tSVF_free(&f->high[i]);
10931116 }
1117+
10941118 leaf_free(f);
10951119 }
10961120
@@ -1098,11 +1122,19 @@ void tButterworth_initToPool (tButterworth* const ft, int N, float f1, fl · 1 unmodified line
10981122 {
10991123 _tMempool* m = *mp;
11001124 _tButterworth* f = *ft = (_tButterworth*) mpool_alloc(sizeof(_tButterworth), &m->pool);
1101− butterworth_init(ft, N, f1, f2);
1102− for(int i = 0; i < f->N/2; ++i)
1125+
1126+ f->f1 = f1;
1127+ f->f2 = f2;
1128+ f->gain = 1.0f;
1129+
1130+ f->N = N;
1131+
1132+ if (f->N > NUM_SVF_BW) f->N = NUM_SVF_BW;
1133+
1134+ for(int i = 0; i < N/2; ++i)
11031135 {
1104− tSVF_initToPool(&f->low[i], SVFTypeHighpass, f->f1, 0.5f/cosf((1.0f+2.0f*i)*PI/(2*f->N)), mp);
1105− tSVF_initToPool(&f->high[i], SVFTypeLowpass, f->f2, 0.5f/cosf((1.0f+2.0f*i)*PI/(2*f->N)), mp);
1136+ tSVF_initToPool(&f->low[i], SVFTypeHighpass, f1, 0.5f/cosf((1.0f+2.0f*i)*PI/(2*N)), mp);
1137+ tSVF_initToPool(&f->high[i], SVFTypeLowpass, f2, 0.5f/cosf((1.0f+2.0f*i)*PI/(2*N)), mp);
11061138 }
11071139 }
11081140
@@ -1110,11 +1142,13 @@ void tButterworth_freeFromPool (tButterworth* const ft, tMempool* const mp) · 1 unmodified line
11101142 {
11111143 _tMempool* m = *mp;
11121144 _tButterworth* f = *ft;
1145+
11131146 for(int i = 0; i < f->N/2; ++i)
11141147 {
11151148 tSVF_freeFromPool(&f->low[i], mp);
11161149 tSVF_freeFromPool(&f->high[i], mp);
11171150 }
1151+
11181152 mpool_free(f, &m->pool);
11191153 }
11201154
@@ -1159,26 +1193,20 @@ void tButterworth_setFreqs(tButterworth* const ft, float f1, float f2) · 38 unmodified lines
11591193 }
11601194 }
11611195
1162−////////////////////////////////////////////////////////////////////
1163−static void fir_init(tFIR* const firf, float* coeffs, int numTaps)
1196+void tFIR_init(tFIR* const firf, float* coeffs, int numTaps)
11641197 {
1165− _tFIR* fir = *firf;
1198+ _tFIR* fir = *firf = (_tFIR*) leaf_alloc(sizeof(_tFIR));
11661199
11671200 fir->numTaps = numTaps;
11681201 fir->coeff = coeffs;
1202+ fir->past = (float*)leaf_alloc(sizeof(float) * fir->numTaps);
11691203 for (int i = 0; i < fir->numTaps; ++i) fir->past[i] = 0.0f;
11701204 }
11711205
1172−void tFIR_init(tFIR* const firf, float* coeffs, int numTaps)
1173−{
1174− _tFIR* fir = *firf = (_tFIR*) leaf_alloc(sizeof(_tFIR));
1175− fir->past = (float*)leaf_alloc(sizeof(float) * numTaps);
1176− fir_init(firf, coeffs, numTaps);
1177−}
1178−
11791206 void tFIR_free(tFIR* const firf)
11801207 {
11811208 _tFIR* fir = *firf;
1209+
11821210 leaf_free(fir->past);
11831211 leaf_free(fir);
11841212 }
@@ -1187,14 +1215,18 @@ void tFIR_initToPool (tFIR* const firf, float* coeffs, int numTaps, tMemp · 2 unmodified lines
11871215 {
11881216 _tMempool* m = *mp;
11891217 _tFIR* fir = *firf = (_tFIR*) mpool_alloc(sizeof(_tFIR), &m->pool);
1190− fir->past = (float*) mpool_alloc(sizeof(float) * numTaps, &m->pool);
1191− fir_init(firf, coeffs, numTaps);
1218+
1219+ fir->numTaps = numTaps;
1220+ fir->coeff = coeffs;
1221+ fir->past = (float*) mpool_alloc(sizeof(float) * fir->numTaps, &m->pool);
1222+ for (int i = 0; i < fir->numTaps; ++i) fir->past[i] = 0.0f;
11921223 }
11931224
11941225 void tFIR_freeFromPool (tFIR* const firf, tMempool* const mp)
11951226 {
11961227 _tMempool* m = *mp;
11971228 _tFIR* fir = *firf;
1229+
11981230 mpool_free(fir->past, &m->pool);
11991231 mpool_free(fir, &m->pool);
12001232 }
LEAF/Src/leaf-instruments.c+75−62
@@ -17,35 +17,34 @@ · 16 unmodified lines
1717 #endif
1818
1919 // ----------------- COWBELL ----------------------------//
20−static void cowbell_init(t808Cowbell* const cowbellInst, int useStick)
21−{
22− _t808Cowbell* cowbell = *cowbellInst;
23−
24− tSquare_setFreq(&cowbell->p[0], 540.0f);
25− tSquare_setFreq(&cowbell->p[1], 1.48148f * 540.0f);
26−
27− cowbell->oscMix = 0.5f;
28− cowbell->useStick = useStick;
29−}
3020
3121 void t808Cowbell_init(t808Cowbell* const cowbellInst, int useStick)
3222 {
3323 _t808Cowbell* cowbell = *cowbellInst = (_t808Cowbell*) leaf_alloc(sizeof(_t808Cowbell));
3424
3525 tSquare_init(&cowbell->p[0]);
26+ tSquare_setFreq(&cowbell->p[0], 540.0f);
27+
3628 tSquare_init(&cowbell->p[1]);
37−
29+ tSquare_setFreq(&cowbell->p[1], 1.48148f * 540.0f);
30+
31+ cowbell->oscMix = 0.5f;
32+
3833 tSVF_init(&cowbell->bandpassOsc, SVFTypeBandpass, 2500, 1.0f);
34+
3935 tSVF_init(&cowbell->bandpassStick, SVFTypeBandpass, 1800, 1.0f);
4036
4137 tEnvelope_init(&cowbell->envGain, 5.0f, 100.0f, OFALSE);
38+
4239 tEnvelope_init(&cowbell->envFilter, 5.0, 100.0f, OFALSE);
4340
4441 tHighpass_init(&cowbell->highpass, 1000.0f);
42+
4543 tNoise_init(&cowbell->stick, WhiteNoise);
44+
4645 tEnvelope_init(&cowbell->envStick, 5.0f, 5.0f, 0);
4746
48− cowbell_init(cowbellInst, useStick);
47+ cowbell->useStick = useStick;
4948 }
5049
5150 void t808Cowebell_free(t808Cowbell* const cowbellInst)
@@ -70,19 +69,28 @@ void t808Cowbell_initToPool (t808Cowbell* const cowbellInst, int use · 18 unmodified lines
7069 _t808Cowbell* cowbell = *cowbellInst = (_t808Cowbell*) mpool_alloc(sizeof(_t808Cowbell), &m->pool);
7170
7271 tSquare_initToPool(&cowbell->p[0], mp);
72+ tSquare_setFreq(&cowbell->p[0], 540.0f);
73+
7374 tSquare_initToPool(&cowbell->p[1], mp);
74−
75+ tSquare_setFreq(&cowbell->p[1], 1.48148f * 540.0f);
76+
77+ cowbell->oscMix = 0.5f;
78+
7579 tSVF_initToPool(&cowbell->bandpassOsc, SVFTypeBandpass, 2500, 1.0f, mp);
80+
7681 tSVF_initToPool(&cowbell->bandpassStick, SVFTypeBandpass, 1800, 1.0f, mp);
7782
7883 tEnvelope_initToPool(&cowbell->envGain, 5.0f, 100.0f, OFALSE, mp);
84+
7985 tEnvelope_initToPool(&cowbell->envFilter, 5.0, 100.0f, OFALSE, mp);
8086
8187 tHighpass_initToPool(&cowbell->highpass, 1000.0f, mp);
88+
8289 tNoise_initToPool(&cowbell->stick, WhiteNoise, mp);
90+
8391 tEnvelope_initToPool(&cowbell->envStick, 5.0f, 5.0f, 0, mp);
84−
85− cowbell_init(cowbellInst, useStick);
92+
93+ cowbell->useStick = useStick;
8694 }
8795
8896 void t808Cowbell_freeFromPool (t808Cowbell* const cowbellInst, tMempool* const mp)
@@ -174,20 +182,6 @@ void t808Cowbell_setStick(t808Cowbell* const cowbellInst, int useStick) · 85 unmodified lines
174182 }
175183
176184 // ----------------- HIHAT ----------------------------//
177−static void hihat_init(t808Hihat* const hihatInst)
178−{
179− _t808Hihat* hihat = *hihatInst;
180−
181− hihat->freq = 40.0f;
182− hihat->stretch = 0.0f;
183−
184− tSquare_setFreq(&hihat->p[0], 2.0f * hihat->freq);
185− tSquare_setFreq(&hihat->p[1], 3.00f * hihat->freq);
186− tSquare_setFreq(&hihat->p[2], 4.16f * hihat->freq);
187− tSquare_setFreq(&hihat->p[3], 5.43f * hihat->freq);
188− tSquare_setFreq(&hihat->p[4], 6.79f * hihat->freq);
189− tSquare_setFreq(&hihat->p[5], 8.21f * hihat->freq);
190−}
191185
192186 void t808Hihat_init(t808Hihat* const hihatInst)
193187 {
@@ -208,9 +202,18 @@ void t808Hihat_init(t808Hihat* const hihatInst) · 14 unmodified lines
208202 tEnvelope_init(&hihat->envGain, 0.0f, 50.0f, OFALSE);
209203 tEnvelope_init(&hihat->envStick, 0.0f, 7.0f, OFALSE);
210204
205+
211206 tHighpass_init(&hihat->highpass, 7000.0f);
212207
213− hihat_init(hihatInst);
208+ hihat->freq = 40.0f;
209+ hihat->stretch = 0.0f;
210+
211+ tSquare_setFreq(&hihat->p[0], 2.0f * hihat->freq);
212+ tSquare_setFreq(&hihat->p[1], 3.00f * hihat->freq);
213+ tSquare_setFreq(&hihat->p[2], 4.16f * hihat->freq);
214+ tSquare_setFreq(&hihat->p[3], 5.43f * hihat->freq);
215+ tSquare_setFreq(&hihat->p[4], 6.79f * hihat->freq);
216+ tSquare_setFreq(&hihat->p[5], 8.21f * hihat->freq);
214217 }
215218
216219 void t808Hihat_free(t808Hihat* const hihatInst)
@@ -255,10 +258,19 @@ void t808Hihat_initToPool (t808Hihat* const hihatInst, tMempool* const mp) · 38 unmodified lines
255258
256259 tEnvelope_initToPool(&hihat->envGain, 0.0f, 50.0f, OFALSE, mp);
257260 tEnvelope_initToPool(&hihat->envStick, 0.0f, 7.0f, OFALSE, mp);
258−
261+
262+
259263 tHighpass_initToPool(&hihat->highpass, 7000.0f, mp);
260264
261− hihat_init(hihatInst);
265+ hihat->freq = 40.0f;
266+ hihat->stretch = 0.0f;
267+
268+ tSquare_setFreq(&hihat->p[0], 2.0f * hihat->freq);
269+ tSquare_setFreq(&hihat->p[1], 3.00f * hihat->freq);
270+ tSquare_setFreq(&hihat->p[2], 4.16f * hihat->freq);
271+ tSquare_setFreq(&hihat->p[3], 5.43f * hihat->freq);
272+ tSquare_setFreq(&hihat->p[4], 6.79f * hihat->freq);
273+ tSquare_setFreq(&hihat->p[5], 8.21f * hihat->freq);
262274 }
263275
264276 void t808Hihat_freeFromPool (t808Hihat* const hihatInst, tMempool* const mp)
@@ -389,39 +401,33 @@ void t808Hihat_setOscFreq(t808Hihat* const hihatInst, float freq) · 124 unmodified lines
389401 }
390402
391403 // ----------------- SNARE ----------------------------//
392−static void snare_init(t808Snare* const snareInst)
393−{
394− _t808Snare* snare = *snareInst;
395−
396− float ratio[2] = {1.0, 1.5};
397− for (int i = 0; i < 2; i++)
398− {
399− tTriangle_setFreq(&snare->tone[i], ratio[i] * 400.0f);
400− snare->toneGain[i] = 0.5f;
401− }
402− snare->tone1Freq = ratio[0] * 100.0f;
403− snare->tone2Freq = ratio[1] * 100.0f;
404− snare->noiseFilterFreq = 3000.0f;
405− snare->noiseGain = 1.0f;
406−}
407404
408405 void t808Snare_init(t808Snare* const snareInst)
409406 {
410407 _t808Snare* snare = *snareInst = (_t808Snare*) leaf_alloc(sizeof(_t808Snare));
411408
409+ float ratio[2] = {1.0, 1.5};
412410 for (int i = 0; i < 2; i++)
413411 {
414412 tTriangle_init(&snare->tone[i]);
413+
414+ tTriangle_setFreq(&snare->tone[i], ratio[i] * 400.0f);
415415 tSVF_init(&snare->toneLowpass[i], SVFTypeLowpass, 4000, 1.0f);
416416 tEnvelope_init(&snare->toneEnvOsc[i], 0.0f, 50.0f, OFALSE);
417417 tEnvelope_init(&snare->toneEnvGain[i], 1.0f, 150.0f, OFALSE);
418418 tEnvelope_init(&snare->toneEnvFilter[i], 1.0f, 2000.0f, OFALSE);
419+
420+ snare->toneGain[i] = 0.5f;
419421 }
422+
423+ snare->tone1Freq = ratio[0] * 100.0f;
424+ snare->tone2Freq = ratio[1] * 100.0f;
425+ snare->noiseFilterFreq = 3000.0f;
420426 tNoise_init(&snare->noiseOsc, WhiteNoise);
421427 tSVF_init(&snare->noiseLowpass, SVFTypeLowpass, 12000.0f, 0.8f);
422428 tEnvelope_init(&snare->noiseEnvGain, 0.0f, 100.0f, OFALSE);
423429 tEnvelope_init(&snare->noiseEnvFilter, 0.0f, 1000.0f, OFALSE);
424− snare_init(snareInst);
430+ snare->noiseGain = 1.0f;
425431 }
426432
427433 void t808Snare_free (t808Snare* const snareInst)
@@ -449,20 +455,29 @@ void t808Snare_initToPool (t808Snare* const snareInst, tMempool* const mp) · 21 unmodified lines
449455 {
450456 _tMempool* m = *mp;
451457 _t808Snare* snare = *snareInst = (_t808Snare*) mpool_alloc(sizeof(_t808Snare), &m->pool);
452−
458+
459+ float ratio[2] = {1.0, 1.5};
453460 for (int i = 0; i < 2; i++)
454461 {
455462 tTriangle_initToPool(&snare->tone[i], mp);
463+
464+ tTriangle_setFreq(&snare->tone[i], ratio[i] * 400.0f);
456465 tSVF_initToPool(&snare->toneLowpass[i], SVFTypeLowpass, 4000, 1.0f, mp);
457466 tEnvelope_initToPool(&snare->toneEnvOsc[i], 0.0f, 50.0f, OFALSE, mp);
458467 tEnvelope_initToPool(&snare->toneEnvGain[i], 1.0f, 150.0f, OFALSE, mp);
459468 tEnvelope_initToPool(&snare->toneEnvFilter[i], 1.0f, 2000.0f, OFALSE, mp);
469+
470+ snare->toneGain[i] = 0.5f;
460471 }
472+
473+ snare->tone1Freq = ratio[0] * 100.0f;
474+ snare->tone2Freq = ratio[1] * 100.0f;
475+ snare->noiseFilterFreq = 3000.0f;
461476 tNoise_initToPool(&snare->noiseOsc, WhiteNoise, mp);
462477 tSVF_initToPool(&snare->noiseLowpass, SVFTypeLowpass, 12000.0f, 0.8f, mp);
463478 tEnvelope_initToPool(&snare->noiseEnvGain, 0.0f, 100.0f, OFALSE, mp);
464479 tEnvelope_initToPool(&snare->noiseEnvFilter, 0.0f, 1000.0f, OFALSE, mp);
465− snare_init(snareInst);
480+ snare->noiseGain = 1.0f;
466481 }
467482
468483 void t808Snare_freeFromPool (t808Snare* const snareInst, tMempool* const mp)
@@ -577,29 +592,23 @@ float t808Snare_tick(t808Snare* const snareInst) · 108 unmodified lines
577592 }
578593
579594 // ----------------- KICK ----------------------------//
580−static void kick_init (t808Kick* const kickInst)
581−{
582− _t808Kick* kick = *kickInst;
583−
584− tCycle_setFreq(&kick->tone, 50.0f);
585− kick->toneInitialFreq = 40.0f;
586− kick->sighAmountInHz = 7.0f;
587− kick->chirpRatioMinusOne = 3.3f;
588− kick->noiseGain = 0.3f;
589−}
590595
591596 void t808Kick_init (t808Kick* const kickInst)
592597 {
593598 _t808Kick* kick = *kickInst = (_t808Kick*) leaf_alloc(sizeof(_t808Kick));
594599
595600 tCycle_init(&kick->tone);
601+ kick->toneInitialFreq = 40.0f;
602+ kick->sighAmountInHz = 7.0f;
603+ kick->chirpRatioMinusOne = 3.3f;
604+ tCycle_setFreq(&kick->tone, 50.0f);
596605 tSVF_init(&kick->toneLowpass, SVFTypeLowpass, 2000.0f, 0.5f);
597606 tEnvelope_init(&kick->toneEnvOscChirp, 0.0f, 20.0f, OFALSE);
598607 tEnvelope_init(&kick->toneEnvOscSigh, 0.0f, 2500.0f, OFALSE);
599608 tEnvelope_init(&kick->toneEnvGain, 0.0f, 800.0f, OFALSE);
600609 tNoise_init(&kick->noiseOsc, PinkNoise);
601610 tEnvelope_init(&kick->noiseEnvGain, 0.0f, 1.0f, OFALSE);
602− kick_init(kickInst);
611+ kick->noiseGain = 0.3f;
603612 }
604613
605614 void t808Kick_free (t808Kick* const kickInst)
@@ -623,13 +632,17 @@ void t808Kick_initToPool (t808Kick* const kickInst, tMempool* const mp) · 17 unmodified lines
623632 _t808Kick* kick = *kickInst = (_t808Kick*) mpool_alloc(sizeof(_t808Kick), &m->pool);
624633
625634 tCycle_initToPool(&kick->tone, mp);
635+ kick->toneInitialFreq = 40.0f;
636+ kick->sighAmountInHz = 7.0f;
637+ kick->chirpRatioMinusOne = 3.3f;
638+ tCycle_setFreq(&kick->tone, 50.0f);
626639 tSVF_initToPool(&kick->toneLowpass, SVFTypeLowpass, 2000.0f, 0.5f, mp);
627640 tEnvelope_initToPool(&kick->toneEnvOscChirp, 0.0f, 20.0f, OFALSE, mp);
628641 tEnvelope_initToPool(&kick->toneEnvOscSigh, 0.0f, 2500.0f, OFALSE, mp);
629642 tEnvelope_initToPool(&kick->toneEnvGain, 0.0f, 800.0f, OFALSE, mp);
630643 tNoise_initToPool(&kick->noiseOsc, PinkNoise, mp);
631644 tEnvelope_initToPool(&kick->noiseEnvGain, 0.0f, 1.0f, OFALSE, mp);
632− kick_init(kickInst);
645+ kick->noiseGain = 0.3f;
633646 }
634647
635648 void t808Kick_freeFromPool (t808Kick* const kickInst, tMempool* const mp)
LEAF/Src/leaf-mempool.c+8−10
@@ -360,34 +360,32 @@ void leaf_mempool_overrun(void) · 359 unmodified lines
360360 //TODO: we should set up some kind of leaf_error method that reaches user space to notify library users of things that failed.
361361 }
362362
363−static void mempool_init(tMempool* const mp, char* memory, size_t size)
364−{
365− _tMempool* m = *mp;
366− mpool_create (memory, size, &m->pool);
367−}
368−
369363 void tMempool_init(tMempool* const mp, char* memory, size_t size)
370364 {
371− *mp = (_tMempool*) leaf_alloc(sizeof(_tMempool));
372− mempool_init(mp, memory, size);
365+ _tMempool* m = *mp = (_tMempool*) leaf_alloc(sizeof(_tMempool));
366+
367+ mpool_create (memory, size, &m->pool);
373368 }
374369
375370 void tMempool_free(tMempool* const mp)
376371 {
377372 _tMempool* m = *mp;
373+
378374 leaf_free(m);
379375 }
380376
381377 void tMempool_initToPool (tMempool* const mp, char* memory, size_t size, tMempool* const mem)
382378 {
383379 _tMempool* mm = *mem;
384− *mp = (_tMempool*) mpool_alloc(sizeof(_tMempool), &mm->pool);
385− mempool_init(mp, memory, size);
380+ _tMempool* m = *mp = (_tMempool*) mpool_alloc(sizeof(_tMempool), &mm->pool);
381+
382+ mpool_create (memory, size, &m->pool);
386383 }
387384
388385 void tMempool_freeFromPool (tMempool* const mp, tMempool* const mem)
389386 {
390387 _tMempool* mm = *mem;
391388 _tMempool* m = *mp;
389+
392390 mpool_free(m, &mm->pool);
393391 }
LEAF/Src/leaf-midi.c+55−39
@@ -19,9 +19,10 @@ · 18 unmodified lines
1919 //====================================================================================
2020 /* Stack */
2121 //====================================================================================
22−static void stack_init(tStack* const stack)
22+
23+void tStack_init(tStack* const stack)
2324 {
24− _tStack* ns = *stack;
25+ _tStack* ns = *stack = (_tStack*) leaf_alloc(sizeof(_tStack));
2526
2627 ns->ordered = OFALSE;
2728 ns->size = 0;
@@ -31,29 +32,31 @@ static void stack_init(tStack* const stack) · 3 unmodified lines
3132 for (int i = 0; i < STACK_SIZE; i++) ns->data[i] = -1;
3233 }
3334
34−void tStack_init(tStack* const stack)
35−{
36− *stack = (_tStack*) leaf_alloc(sizeof(_tStack));
37− stack_init(stack);
38−}
39−
4035 void tStack_free(tStack* const stack)
4136 {
4237 _tStack* ns = *stack;
38+
4339 leaf_free(ns);
4440 }
4541
4642 void tStack_initToPool (tStack* const stack, tMempool* const mp)
4743 {
4844 _tMempool* m = *mp;
49− *stack = (_tStack*) mpool_alloc(sizeof(_tStack), &m->pool);
50− stack_init(stack);
45+ _tStack* ns = *stack = (_tStack*) mpool_alloc(sizeof(_tStack), &m->pool);
46+
47+ ns->ordered = OFALSE;
48+ ns->size = 0;
49+ ns->pos = 0;
50+ ns->capacity = STACK_SIZE;
51+
52+ for (int i = 0; i < STACK_SIZE; i++) ns->data[i] = -1;
5153 }
5254
5355 void tStack_freeFromPool (tStack* const stack, tMempool* const mp)
5456 {
5557 _tMempool* m = *mp;
5658 _tStack* ns = *stack;
59+
5760 mpool_free(ns, &m->pool);
5861 }
5962
@@ -267,9 +270,9 @@ int tStack_first(tStack* const stack) · 207 unmodified lines
267270
268271
269272 // POLY
270−static void poly_init(tPoly* const polyh, int maxNumVoices)
273+void tPoly_init(tPoly* const polyh, int maxNumVoices)
271274 {
272− _tPoly* poly = *polyh;
275+ _tPoly* poly = *polyh = (_tPoly*) leaf_alloc(sizeof(_tPoly));
273276
274277 poly->numVoices = maxNumVoices;
275278 poly->maxNumVoices = maxNumVoices;
@@ -289,36 +292,27 @@ static void poly_init(tPoly* const polyh, int maxNumVoices) · 13 unmodified lines
289292
290293 poly->glideTime = 5.0f;
291294
295+ poly->ramps = (tRamp*) leaf_alloc(sizeof(tRamp) * poly->maxNumVoices);
296+ poly->rampVals = (float*) leaf_alloc(sizeof(float) * poly->maxNumVoices);
297+ poly->firstReceived = (oBool*) leaf_alloc(sizeof(oBool) * poly->maxNumVoices);
298+ poly->voices = (int**) leaf_alloc(sizeof(int*) * poly->maxNumVoices);
299+
292300 for (int i = 0; i < poly->maxNumVoices; ++i)
293301 {
302+ poly->voices[i] = (int*) leaf_alloc(sizeof(int) * 2);
294303 poly->voices[i][0] = -1;
295304 poly->firstReceived[i] = OFALSE;
305+
306+ tRamp_init(&poly->ramps[i], poly->glideTime, 1);
296307 }
297− poly->pitchBend = 0.0f;
298− poly->pitchGlideIsActive = OFALSE;
299−}
300−
301−void tPoly_init(tPoly* const polyh, int maxNumVoices)
302−{
303− _tPoly* poly = *polyh = (_tPoly*) leaf_alloc(sizeof(_tPoly));
304308
305− poly->ramps = (tRamp*) leaf_alloc(sizeof(tRamp) * maxNumVoices);
306− poly->rampVals = (float*) leaf_alloc(sizeof(float) * maxNumVoices);
307− poly->firstReceived = (oBool*) leaf_alloc(sizeof(oBool) * maxNumVoices);
308− poly->voices = (int**) leaf_alloc(sizeof(int*) * maxNumVoices);
309− for (int i = 0; i < maxNumVoices; ++i)
310− {
311− poly->voices[i] = (int*) leaf_alloc(sizeof(int) * 2);
312− }
313− poly_init(polyh, maxNumVoices);
309+ poly->pitchBend = 0.0f;
314310
315− for (int i = 0; i < poly->maxNumVoices; ++i)
316− {
317− tRamp_init(&poly->ramps[i], poly->glideTime, 1);
318− }
319311 tRamp_init(&poly->pitchBendRamp, 1.0f, 1);
320312 tStack_init(&poly->stack);
321313 tStack_init(&poly->orderStack);
314+
315+ poly->pitchGlideIsActive = OFALSE;
322316 }
323317
324318 void tPoly_free(tPoly* const polyh)
@@ -347,23 +341,45 @@ void tPoly_initToPool (tPoly* const polyh, int maxNumVoices, tMemp · 22 unmodified lines
347341 _tMempool* m = *mp;
348342 _tPoly* poly = *polyh = (_tPoly*) mpool_alloc(sizeof(_tPoly), &m->pool);
349343
350− poly->ramps = (tRamp*) mpool_alloc(sizeof(tRamp) * maxNumVoices, &m->pool);
351− poly->rampVals = (float*) mpool_alloc(sizeof(float) * maxNumVoices, &m->pool);
352− poly->firstReceived = (oBool*) mpool_alloc(sizeof(oBool) * maxNumVoices, &m->pool);
353− poly->voices = (int**) mpool_alloc(sizeof(int*) * maxNumVoices, &m->pool);
354− for (int i = 0; i < maxNumVoices; ++i)
344+ poly->numVoices = maxNumVoices;
345+ poly->maxNumVoices = maxNumVoices;
346+ poly->lastVoiceToChange = 0;
347+
348+ // Arp mode stuff
349+ poly->currentVoice = 0;
350+ poly->maxLength = 128;
351+ poly->currentNote = -1;
352+
353+ //default learned CCs and notes are just the CCs 1-128 - notes are skipped
354+ for (int i = 0; i < 128; i++)
355355 {
356− poly->voices[i] = (int*) mpool_alloc(sizeof(int) * 2, &m->pool);
356+ poly->notes[i][0] = 0;
357+ poly->notes[i][1] = -1;
357358 }
358− poly_init(polyh, maxNumVoices);
359+
360+ poly->glideTime = 5.0f;
361+
362+ poly->ramps = (tRamp*) mpool_alloc(sizeof(tRamp) * poly->maxNumVoices, &m->pool);
363+ poly->rampVals = (float*) mpool_alloc(sizeof(float) * poly->maxNumVoices, &m->pool);
364+ poly->firstReceived = (oBool*) mpool_alloc(sizeof(oBool) * poly->maxNumVoices, &m->pool);
365+ poly->voices = (int**) mpool_alloc(sizeof(int*) * poly->maxNumVoices, &m->pool);
359366
360367 for (int i = 0; i < poly->maxNumVoices; ++i)
361368 {
369+ poly->voices[i] = (int*) mpool_alloc(sizeof(int) * 2, &m->pool);
370+ poly->voices[i][0] = -1;
371+ poly->firstReceived[i] = OFALSE;
372+
362373 tRamp_initToPool(&poly->ramps[i], poly->glideTime, 1, mp);
363374 }
375+
376+ poly->pitchBend = 0.0f;
377+
364378 tRamp_initToPool(&poly->pitchBendRamp, 1.0f, 1, mp);
365379 tStack_initToPool(&poly->stack, mp);
366380 tStack_initToPool(&poly->orderStack, mp);
381+
382+ poly->pitchGlideIsActive = OFALSE;
367383 }
368384
369385 void tPoly_freeFromPool (tPoly* const polyh, tMempool* const mp)
LEAF/Src/leaf-oscillators.c+94−78
@@ -19,36 +19,35 @@ · 18 unmodified lines
1919 #endif
2020
2121 // Cycle
22−static void cycle_init(tCycle* const cy)
22+void tCycle_init(tCycle* const cy)
2323 {
24− _tCycle* c = *cy;
24+ _tCycle* c = *cy = (_tCycle*) leaf_alloc(sizeof(_tCycle));
25+
2526 c->inc = 0.0f;
2627 c->phase = 0.0f;
2728 }
2829
29−void tCycle_init(tCycle* const cy)
30−{
31− *cy = (_tCycle*) leaf_alloc(sizeof(_tCycle));
32− cycle_init(cy);
33−}
34−
3530 void tCycle_free(tCycle* const cy)
3631 {
3732 _tCycle* c = *cy;
33+
3834 leaf_free(c);
3935 }
4036
4137 void tCycle_initToPool (tCycle* const cy, tMempool* const mp)
4238 {
4339 _tMempool* m = *mp;
44− *cy = (_tCycle*) mpool_alloc(sizeof(_tCycle), &m->pool);
45− cycle_init(cy);
40+ _tCycle* c = *cy = (_tCycle*) mpool_alloc(sizeof(_tCycle), &m->pool);
41+
42+ c->inc = 0.0f;
43+ c->phase = 0.0f;
4644 }
4745
4846 void tCycle_freeFromPool (tCycle* const cy, tMempool* const mp)
4947 {
5048 _tMempool* m = *mp;
5149 _tCycle* c = *cy;
50+
5251 mpool_free(c, &m->pool);
5352 }
5453
@@ -91,36 +90,35 @@ void tCycleSampleRateChanged (tCycle* const cy) · 36 unmodified lines
9190
9291 //========================================================================
9392 /* Triangle */
94−static void triangle_init(tTriangle* const cy)
93+void tTriangle_init(tTriangle* const cy)
9594 {
96− _tTriangle* c = *cy;
95+ _tTriangle* c = *cy = (_tTriangle*) leaf_alloc(sizeof(_tTriangle));
96+
9797 c->inc = 0.0f;
9898 c->phase = 0.0f;
9999 }
100100
101−void tTriangle_init(tTriangle* const cy)
102−{
103− *cy = (_tTriangle*) leaf_alloc(sizeof(_tTriangle));
104− triangle_init(cy);
105−}
106−
107101 void tTriangle_free(tTriangle* const cy)
108102 {
109103 _tTriangle* c = *cy;
104+
110105 leaf_free(c);
111106 }
112107
113108 void tTriangle_initToPool (tTriangle* const cy, tMempool* const mp)
114109 {
115110 _tMempool* m = *mp;
116− *cy = (_tTriangle*) mpool_alloc(sizeof(_tTriangle), &m->pool);
117− triangle_init(cy);
111+ _tTriangle* c = *cy = (_tTriangle*) mpool_alloc(sizeof(_tTriangle), &m->pool);
112+
113+ c->inc = 0.0f;
114+ c->phase = 0.0f;
118115 }
119116
120117 void tTriangle_freeFromPool (tTriangle* const cy, tMempool* const mp)
121118 {
122119 _tMempool* m = *mp;
123120 _tTriangle* c = *cy;
121+
124122 mpool_free(c, &m->pool);
125123 }
126124
@@ -223,36 +221,35 @@ void tTriangleSampleRateChanged (tTriangle* const cy) · 96 unmodified lines
223221
224222 //========================================================================
225223 /* Square */
226−static void square_init(tSquare* const cy)
224+void tSquare_init(tSquare* const cy)
227225 {
228− _tSquare* c = *cy;
226+ _tSquare* c = *cy = (_tSquare*) leaf_alloc(sizeof(_tSquare));
227+
229228 c->inc = 0.0f;
230229 c->phase = 0.0f;
231230 }
232231
233−void tSquare_init(tSquare* const cy)
234−{
235− *cy = (_tSquare*) leaf_alloc(sizeof(_tSquare));
236− square_init(cy);
237−}
238−
239232 void tSquare_free(tSquare* const cy)
240233 {
241234 _tSquare* c = *cy;
235+
242236 leaf_free(c);
243237 }
244238
245239 void tSquare_initToPool (tSquare* const cy, tMempool* const mp)
246240 {
247241 _tMempool* m = *mp;
248− *cy = (_tSquare*) mpool_alloc(sizeof(_tSquare), &m->pool);
249− square_init(cy);
242+ _tSquare* c = *cy = (_tSquare*) mpool_alloc(sizeof(_tSquare), &m->pool);
243+
244+ c->inc = 0.0f;
245+ c->phase = 0.0f;
250246 }
251247
252248 void tSquare_freeFromPool(tSquare* const cy, tMempool* const mp)
253249 {
254250 _tMempool* m = *mp;
255251 _tSquare* c = *cy;
252+
256253 mpool_free(c, &m->pool);
257254 }
258255
@@ -353,36 +350,35 @@ void tSquareSampleRateChanged (tSquare* const cy) · 94 unmodified lines
353350
354351 //=====================================================================
355352 // Sawtooth
356−static void sawtooth_init(tSawtooth* const cy)
353+void tSawtooth_init(tSawtooth* const cy)
357354 {
358− _tSawtooth* c = *cy;
355+ _tSawtooth* c = *cy = (_tSawtooth*) leaf_alloc(sizeof(_tSawtooth));
356+
359357 c->inc = 0.0f;
360358 c->phase = 0.0f;
361359 }
362360
363−void tSawtooth_init(tSawtooth* const cy)
364−{
365− *cy = (_tSawtooth*) leaf_alloc(sizeof(_tSawtooth));
366− sawtooth_init(cy);
367−}
368−
369361 void tSawtooth_free(tSawtooth* const cy)
370362 {
371363 _tSawtooth* c = *cy;
364+
372365 leaf_free(c);
373366 }
374367
375368 void tSawtooth_initToPool (tSawtooth* const cy, tMempool* const mp)
376369 {
377370 _tMempool* m = *mp;
378− *cy = (_tSawtooth*) mpool_alloc(sizeof(_tSawtooth), &m->pool);
379− sawtooth_init(cy);
371+ _tSawtooth* c = *cy = (_tSawtooth*) mpool_alloc(sizeof(_tSawtooth), &m->pool);
372+
373+ c->inc = 0.0f;
374+ c->phase = 0.0f;
380375 }
381376
382377 void tSawtooth_freeFromPool (tSawtooth* const cy, tMempool* const mp)
383378 {
384379 _tMempool* m = *mp;
385380 _tSawtooth* c = *cy;
381+
386382 mpool_free(c, &m->pool);
387383 }
388384
@@ -484,36 +480,42 @@ void tSawtoothSampleRateChanged (tSawtooth* const cy) · 95 unmodified lines
484480
485481 //========================================================================
486482 /* Phasor */
487−static void phasor_init(tPhasor* const ph)
483+void tPhasorSampleRateChanged (tPhasor* const ph)
488484 {
489485 _tPhasor* p = *ph;
490− p->phase = 0.0f;
491− p->inc = 0.0f;
492−}
486+
487+ p->inc = p->freq * leaf.invSampleRate;
488+};
493489
494490 void tPhasor_init(tPhasor* const ph)
495491 {
496− *ph = (_tPhasor*) leaf_alloc(sizeof(_tPhasor));
497− phasor_init(ph);
492+ _tPhasor* p = *ph = (_tPhasor*) leaf_alloc(sizeof(_tPhasor));
493+
494+ p->phase = 0.0f;
495+ p->inc = 0.0f;
498496 }
499497
500498 void tPhasor_free(tPhasor* const ph)
501499 {
502500 _tPhasor* p = *ph;
501+
503502 leaf_free(p);
504503 }
505504
506505 void tPhasor_initToPool (tPhasor* const ph, tMempool* const mp)
507506 {
508507 _tMempool* m = *mp;
509− *ph = (_tPhasor*) mpool_alloc(sizeof(_tPhasor), &m->pool);
510− phasor_init(ph);
508+ _tPhasor* p = *ph = (_tPhasor*) mpool_alloc(sizeof(_tPhasor), &m->pool);
509+
510+ p->phase = 0.0f;
511+ p->inc = 0.0f;
511512 }
512513
513514 void tPhasor_freeFromPool(tPhasor* const ph, tMempool* const mp)
514515 {
515516 _tMempool* m = *mp;
516517 _tPhasor* p = *ph;
518+
517519 mpool_free(p, &m->pool);
518520 }
519521
@@ -541,36 +543,35 @@ float tPhasor_tick(tPhasor* const ph) · 21 unmodified lines
541543 }
542544
543545 /* Noise */
544−static void noise_init(tNoise* const ns, NoiseType type)
546+void tNoise_init(tNoise* const ns, NoiseType type)
545547 {
546− _tNoise* n = *ns;
548+ _tNoise* n = *ns = (_tNoise*) leaf_alloc(sizeof(_tNoise));
549+
547550 n->type = type;
548551 n->rand = leaf.random;
549552 }
550553
551−void tNoise_init(tNoise* const ns, NoiseType type)
552−{
553− *ns = (_tNoise*) leaf_alloc(sizeof(_tNoise));
554− noise_init(ns, type);
555−}
556−
557554 void tNoise_free(tNoise* const ns)
558555 {
559556 _tNoise* n = *ns;
557+
560558 leaf_free(n);
561559 }
562560
563561 void tNoise_initToPool (tNoise* const ns, NoiseType type, tMempool* const mp)
564562 {
565563 _tMempool* m = *mp;
566− *ns = (_tNoise*) mpool_alloc(sizeof(_tNoise), &m->pool);
567− noise_init(ns, type);
564+ _tNoise* n = *ns = (_tNoise*) mpool_alloc(sizeof(_tNoise), &m->pool);
565+
566+ n->type = type;
567+ n->rand = leaf.random;
568568 }
569569
570570 void tNoise_freeFromPool (tNoise* const ns, tMempool* const mp)
571571 {
572572 _tMempool* m = *mp;
573573 _tNoise* n = *ns;
574+
574575 mpool_free(n, &m->pool);
575576 }
576577
@@ -595,18 +596,20 @@ float tNoise_tick(tNoise* const ns) · 18 unmodified lines
595596 }
596597 }
597598
598−void tPhasorSampleRateChanged (tPhasor* const ph)
599+//=================================================================================
600+/* Neuron */
601+
602+void tNeuronSampleRateChanged(tNeuron* nr)
599603 {
600− _tPhasor* p = *ph;
601604
602− p->inc = p->freq * leaf.invSampleRate;
603605 }
604606
605−//=================================================================================
606−/* Neuron */
607−static void neuron_init(tNeuron* const nr)
607+void tNeuron_init(tNeuron* const nr)
608608 {
609− _tNeuron* n = *nr;
609+ _tNeuron* n = *nr = (_tNeuron*) leaf_alloc(sizeof(_tNeuron));
610+
611+ tPoleZero_init(&n->f);
612+
610613 tPoleZero_setBlockZero(&n->f, 0.99f);
611614
612615 n->timeStep = 1.0f / 50.0f;
@@ -632,16 +635,10 @@ static void neuron_init(tNeuron* const nr) · 19 unmodified lines
632635 n->rate[2] = n->gL/n->C;
633636 }
634637
635−void tNeuron_init(tNeuron* const nr)
636−{
637− _tNeuron* n = *nr = (_tNeuron*) leaf_alloc(sizeof(_tNeuron));
638− tPoleZero_init(&n->f);
639− neuron_init(nr);
640−}
641−
642638 void tNeuron_free(tNeuron* const nr)
643639 {
644640 _tNeuron* n = *nr;
641+
645642 tPoleZero_free(&n->f);
646643 leaf_free(n);
647644 }
@@ -650,8 +647,32 @@ void tNeuron_initToPool (tNeuron* const nr, tMempool* const mp) · 2 unmodified lines
650647 {
651648 _tMempool* m = *mp;
652649 _tNeuron* n = *nr = (_tNeuron*) mpool_alloc(sizeof(_tNeuron), &m->pool);
650+
653651 tPoleZero_initToPool(&n->f, mp);
654− neuron_init(nr);
652+
653+ tPoleZero_setBlockZero(&n->f, 0.99f);
654+
655+ n->timeStep = 1.0f / 50.0f;
656+
657+ n->current = 0.0f; // 100.0f for sound
658+ n->voltage = 0.0f;
659+
660+ n->mode = NeuronNormal;
661+
662+ n->P[0] = 0.0f;
663+ n->P[1] = 0.0f;
664+ n->P[2] = 1.0f;
665+
666+ n->V[0] = -12.0f;
667+ n->V[1] = 115.0f;
668+ n->V[2] = 10.613f;
669+
670+ n->gK = 36.0f;
671+ n->gN = 120.0f;
672+ n->gL = 0.3f;
673+ n->C = 1.0f;
674+
675+ n->rate[2] = n->gL/n->C;
655676 }
656677
657678 void tNeuron_freeFromPool(tNeuron* const nr, tMempool* const mp)
@@ -830,8 +851,3 @@ void tNeuron_setCurrent (tNeuron* const nr, float current) · 172 unmodified lines
830851 _tNeuron* n = *nr;
831852 n->current = current;
832853 }
833−
834−void tNeuronSampleRateChanged(tNeuron* nr)
835−{
836−
837−}
LEAF/Src/leaf-physical.c+79−79
@@ -17,23 +17,21 @@ · 16 unmodified lines
1717 #endif
1818
1919 /* ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ tPluck ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ */
20−static void pluck_init (tPluck* const pl, float lowestFrequency)
21−{
22− if ( lowestFrequency <= 0.0f ) lowestFrequency = 10.0f;
23−
24− tPluck_setFrequency(pl, 220.0f);
25−}
26−
2720 void tPluck_init (tPluck* const pl, float lowestFrequency)
2821 {
2922 _tPluck* p = *pl = (_tPluck*) leaf_alloc(sizeof(_tPluck));
30−
23+
24+ if ( lowestFrequency <= 0.0f ) lowestFrequency = 10.0f;
25+
3126 tNoise_init(&p->noise, WhiteNoise);
27+
3228 tOnePole_init(&p->pickFilter, 0.0f);
29+
3330 tOneZero_init(&p->loopFilter, 0.0f);
31+
3432 tAllpassDelay_init(&p->delayLine, 0.0f, leaf.sampleRate * 2);
3533
36− pluck_init(pl, lowestFrequency);
34+ tPluck_setFrequency(pl, 220.0f);
3735 }
3836
3937 void tPluck_free (tPluck* const pl)
@@ -53,12 +51,17 @@ void tPluck_initToPool (tPluck* const pl, float lowestFrequency, tMempool* · 13 unmodified lines
5351 _tMempool* m = *mp;
5452 _tPluck* p = *pl = (_tPluck*) mpool_alloc(sizeof(_tPluck), &m->pool);
5553
54+ if ( lowestFrequency <= 0.0f ) lowestFrequency = 10.0f;
55+
5656 tNoise_initToPool(&p->noise, WhiteNoise, mp);
57+
5758 tOnePole_initToPool(&p->pickFilter, 0.0f, mp);
59+
5860 tOneZero_initToPool(&p->loopFilter, 0.0f, mp);
61+
5962 tAllpassDelay_initToPool(&p->delayLine, 0.0f, leaf.sampleRate * 2, mp);
6063
61− pluck_init(pl, lowestFrequency);
64+ tPluck_setFrequency(pl, 220.0f);
6265 }
6366
6467 void tPluck_freeFromPool (tPluck* const pl, tMempool* const mp)
@@ -152,29 +155,18 @@ void tPluckSampleRateChanged(tPluck* const pl) · 87 unmodified lines
152155 }
153156
154157 /* ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ tKarplusStrong ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ */
155−static void karplusstrong_init (tKarplusStrong* const pl, float lowestFrequency)
158+void tKarplusStrong_init (tKarplusStrong* const pl, float lowestFrequency)
156159 {
157− _tKarplusStrong* p = *pl;
160+ _tKarplusStrong* p = *pl = (_tKarplusStrong*) leaf_alloc(sizeof(_tKarplusStrong));
158161
159162 if ( lowestFrequency <= 0.0f ) lowestFrequency = 8.0f;
160163
161− p->pluckAmplitude = 0.3f;
162− p->pickupPosition = 0.4f;
163−
164− p->stretching = 0.9999f;
165− p->baseLoopGain = 0.995f;
166− p->loopGain = 0.999f;
167−
168− tKarplusStrong_setFrequency( pl, 220.0f );
169−}
170−
171−void tKarplusStrong_init (tKarplusStrong* const pl, float lowestFrequency)
172−{
173− _tKarplusStrong* p = *pl = (_tKarplusStrong*) leaf_alloc(sizeof(_tKarplusStrong));
174−
175164 tAllpassDelay_init(&p->delayLine, 0.0f, leaf.sampleRate * 2);
165+
176166 tLinearDelay_init(&p->combDelay, 0.0f, leaf.sampleRate * 2);
167+
177168 tOneZero_init(&p->filter, 0.0f);
169+
178170 tNoise_init(&p->noise, WhiteNoise);
179171
180172 for (int i = 0; i < 4; i++)
@@ -182,7 +174,14 @@ void tKarplusStrong_init (tKarplusStrong* const pl, float lowestFrequency) · 1 unmodified line
182174 tBiQuad_init(&p->biquad[i]);
183175 }
184176
185− karplusstrong_init(pl, lowestFrequency);
177+ p->pluckAmplitude = 0.3f;
178+ p->pickupPosition = 0.4f;
179+
180+ p->stretching = 0.9999f;
181+ p->baseLoopGain = 0.995f;
182+ p->loopGain = 0.999f;
183+
184+ tKarplusStrong_setFrequency( pl, 220.0f );
186185 }
187186
188187 void tKarplusStrong_free (tKarplusStrong* const pl)
@@ -206,10 +205,15 @@ void tKarplusStrong_initToPool (tKarplusStrong* const pl, float lowestFrequ · 17 unmodified lines
206205 {
207206 _tMempool* m = *mp;
208207 _tKarplusStrong* p = *pl = (_tKarplusStrong*) mpool_alloc(sizeof(_tKarplusStrong), &m->pool);
209−
208+
209+ if ( lowestFrequency <= 0.0f ) lowestFrequency = 8.0f;
210+
210211 tAllpassDelay_initToPool(&p->delayLine, 0.0f, leaf.sampleRate * 2, mp);
212+
211213 tLinearDelay_initToPool(&p->combDelay, 0.0f, leaf.sampleRate * 2, mp);
214+
212215 tOneZero_initToPool(&p->filter, 0.0f, mp);
216+
213217 tNoise_initToPool(&p->noise, WhiteNoise, mp);
214218
215219 for (int i = 0; i < 4; i++)
@@ -217,7 +221,14 @@ void tKarplusStrong_initToPool (tKarplusStrong* const pl, float lowestFrequ · 1 unmodified line
217221 tBiQuad_initToPool(&p->biquad[i], mp);
218222 }
219223
220− karplusstrong_init(pl, lowestFrequency);
224+ p->pluckAmplitude = 0.3f;
225+ p->pickupPosition = 0.4f;
226+
227+ p->stretching = 0.9999f;
228+ p->baseLoopGain = 0.995f;
229+ p->loopGain = 0.999f;
230+
231+ tKarplusStrong_setFrequency( pl, 220.0f );
221232 }
222233
223234 void tKarplusStrong_freeFromPool (tKarplusStrong* const pl, tMempool* const mp)
@@ -394,17 +405,6 @@ void tKarplusStrongSampleRateChanged (tKarplusStrong* const pl) · 170 unmodified lines
394405 }
395406
396407 /* Simple Living String*/
397−static void simplelivingstring_init(tSimpleLivingString* const pl, float freq, float dampFreq,
398− float decay, float targetLev, float levSmoothFactor,
399− float levStrength, int levMode)
400−{
401− _tSimpleLivingString* p = *pl;
402−
403− p->curr=0.0f;
404− p->decay=decay;
405− p->levMode=levMode;
406− tSimpleLivingString_setFreq(pl, freq);
407−}
408408
409409 void tSimpleLivingString_init(tSimpleLivingString* const pl, float freq, float dampFreq,
410410 float decay, float targetLev, float levSmoothFactor,
@@ -412,13 +412,15 @@ void tSimpleLivingString_init(tSimpleLivingString* const pl, float freq, floa · 1 unmodified line
412412 {
413413 _tSimpleLivingString* p = *pl = (_tSimpleLivingString*) leaf_alloc(sizeof(_tSimpleLivingString));
414414
415+ p->curr=0.0f;
415416 tExpSmooth_init(&p->wlSmooth, leaf.sampleRate/freq, 0.01); // smoother for string wavelength (not freq, to avoid expensive divisions)
417+ tSimpleLivingString_setFreq(pl, freq);
416418 tLinearDelay_init(&p->delayLine,p->waveLengthInSamples, 2400);
417419 tOnePole_init(&p->bridgeFilter, dampFreq);
418420 tHighpass_init(&p->DCblocker,13);
421+ p->decay=decay;
419422 tFeedbackLeveler_init(&p->fbLev, targetLev, levSmoothFactor, levStrength, levMode);
420−
421− simplelivingstring_init(pl, freq, dampFreq, decay, targetLev, levSmoothFactor, levStrength, levMode);
423+ p->levMode=levMode;
422424 }
423425
424426 void tSimpleLivingString_free(tSimpleLivingString* const pl)
@@ -440,14 +442,16 @@ void tSimpleLivingString_initToPool (tSimpleLivingString* const pl, float fr · 15 unmodified lines
440442 {
441443 _tMempool* m = *mp;
442444 _tSimpleLivingString* p = *pl = (_tSimpleLivingString*) mpool_alloc(sizeof(_tSimpleLivingString), &m->pool);
443−
445+
446+ p->curr=0.0f;
444447 tExpSmooth_initToPool(&p->wlSmooth, leaf.sampleRate/freq, 0.01, mp); // smoother for string wavelength (not freq, to avoid expensive divisions)
448+ tSimpleLivingString_setFreq(pl, freq);
445449 tLinearDelay_initToPool(&p->delayLine,p->waveLengthInSamples, 2400, mp);
446450 tOnePole_initToPool(&p->bridgeFilter, dampFreq, mp);
447451 tHighpass_initToPool(&p->DCblocker,13, mp);
452+ p->decay=decay;
448453 tFeedbackLeveler_initToPool(&p->fbLev, targetLev, levSmoothFactor, levStrength, levMode, mp);
449−
450− simplelivingstring_init(pl, freq, dampFreq, decay, targetLev, levSmoothFactor, levStrength, levMode);
454+ p->levMode=levMode;
451455 }
452456
453457 void tSimpleLivingString_freeFromPool (tSimpleLivingString* const pl, tMempool* const mp)
@@ -540,20 +544,6 @@ float tSimpleLivingString_sample(tSimpleLivingString* const pl) · 86 unmodified lines
540544 }
541545
542546 /* Living String*/
543−static void livingstring_init(tLivingString* const pl, float freq, float pickPos, float prepIndex,
544− float dampFreq, float decay, float targetLev, float levSmoothFactor,
545− float levStrength, int levMode)
546−{
547− _tLivingString* p = *pl;
548−
549− p->curr = 0.0f;
550− p->freq = freq;
551− p->prepIndex = prepIndex;
552− p->dampFreq = dampFreq;
553− p->decay = decay;
554− p->prepIndex = prepIndex;
555− p->levMode = levMode;
556−}
557547
558548 void tLivingString_init(tLivingString* const pl, float freq, float pickPos, float prepIndex,
559549 float dampFreq, float decay, float targetLev, float levSmoothFactor,
@@ -561,24 +551,29 @@ void tLivingString_init(tLivingString* const pl, float freq, float pickPos, f · 1 unmodified line
561551 {
562552 _tLivingString* p = *pl = (_tLivingString*) leaf_alloc(sizeof(_tLivingString));
563553
554+ p->curr=0.0f;
564555 tExpSmooth_init(&p->wlSmooth, leaf.sampleRate/freq, 0.01); // smoother for string wavelength (not freq, to avoid expensive divisions)
565− tExpSmooth_init(&p->ppSmooth, pickPos, 0.01); // smoother for pick position
566556 tLivingString_setFreq(pl, freq);
557+ p->freq = freq;
558+ tExpSmooth_init(&p->ppSmooth, pickPos, 0.01); // smoother for pick position
567559 tLivingString_setPickPos(pl, pickPos);
560+ p->prepIndex=prepIndex;
568561 tLinearDelay_init(&p->delLF,p->waveLengthInSamples, 2400);
569562 tLinearDelay_init(&p->delUF,p->waveLengthInSamples, 2400);
570563 tLinearDelay_init(&p->delUB,p->waveLengthInSamples, 2400);
571564 tLinearDelay_init(&p->delLB,p->waveLengthInSamples, 2400);
565+ p->dampFreq = dampFreq;
572566 tOnePole_init(&p->bridgeFilter, dampFreq);
573567 tOnePole_init(&p->nutFilter, dampFreq);
574568 tOnePole_init(&p->prepFilterU, dampFreq);
575569 tOnePole_init(&p->prepFilterL, dampFreq);
576570 tHighpass_init(&p->DCblockerU,13);
577571 tHighpass_init(&p->DCblockerL,13);
572+ p->decay=decay;
573+ p->prepIndex = prepIndex;
578574 tFeedbackLeveler_init(&p->fbLevU, targetLev, levSmoothFactor, levStrength, levMode);
579575 tFeedbackLeveler_init(&p->fbLevL, targetLev, levSmoothFactor, levStrength, levMode);
580−
581− livingstring_init(pl, freq, pickPos, prepIndex, dampFreq, decay, targetLev, levSmoothFactor, levStrength, levMode);
576+ p->levMode=levMode;
582577 }
583578
584579 void tLivingString_free(tLivingString* const pl)
@@ -610,24 +605,29 @@ void tLivingString_initToPool (tLivingString* const pl, float freq, float · 25 unmodified lines
610605 _tMempool* m = *mp;
611606 _tLivingString* p = *pl = (_tLivingString*) mpool_alloc(sizeof(_tLivingString), &m->pool);
612607
608+ p->curr=0.0f;
613609 tExpSmooth_initToPool(&p->wlSmooth, leaf.sampleRate/freq, 0.01, mp); // smoother for string wavelength (not freq, to avoid expensive divisions)
614− tExpSmooth_initToPool(&p->ppSmooth, pickPos, 0.01, mp); // smoother for pick position
615610 tLivingString_setFreq(pl, freq);
611+ p->freq = freq;
612+ tExpSmooth_initToPool(&p->ppSmooth, pickPos, 0.01, mp); // smoother for pick position
616613 tLivingString_setPickPos(pl, pickPos);
614+ p->prepIndex=prepIndex;
617615 tLinearDelay_initToPool(&p->delLF,p->waveLengthInSamples, 2400, mp);
618616 tLinearDelay_initToPool(&p->delUF,p->waveLengthInSamples, 2400, mp);
619617 tLinearDelay_initToPool(&p->delUB,p->waveLengthInSamples, 2400, mp);
620618 tLinearDelay_initToPool(&p->delLB,p->waveLengthInSamples, 2400, mp);
619+ p->dampFreq = dampFreq;
621620 tOnePole_initToPool(&p->bridgeFilter, dampFreq, mp);
622621 tOnePole_initToPool(&p->nutFilter, dampFreq, mp);
623622 tOnePole_initToPool(&p->prepFilterU, dampFreq, mp);
624623 tOnePole_initToPool(&p->prepFilterL, dampFreq, mp);
625624 tHighpass_initToPool(&p->DCblockerU,13, mp);
626625 tHighpass_initToPool(&p->DCblockerL,13, mp);
626+ p->decay=decay;
627+ p->prepIndex = prepIndex;
627628 tFeedbackLeveler_initToPool(&p->fbLevU, targetLev, levSmoothFactor, levStrength, levMode, mp);
628629 tFeedbackLeveler_initToPool(&p->fbLevL, targetLev, levSmoothFactor, levStrength, levMode, mp);
629−
630− livingstring_init(pl, freq, pickPos, prepIndex, dampFreq, decay, targetLev, levSmoothFactor, levStrength, levMode);
630+ p->levMode=levMode;
631631 }
632632
633633 void tLivingString_freeFromPool (tLivingString* const pl, tMempool* const mp)
@@ -656,8 +656,8 @@ void tLivingString_freeFromPool (tLivingString* const pl, tMempool* const mp · 22 unmodified lines
656656 void tLivingString_setFreq(tLivingString* const pl, float freq)
657657 { // NOTE: It is faster to set wavelength in samples directly
658658 _tLivingString* p = *pl;
659− if (freq < 20) freq = 20;
660− else if (freq > 10000) freq = 10000;
659+ if (freq<20) freq=20;
660+ else if (freq>10000) freq=10000;
661661 p->waveLengthInSamples = leaf.sampleRate/freq;
662662 tExpSmooth_setDest(&p->wlSmooth, p->waveLengthInSamples);
663663 }
@@ -665,8 +665,8 @@ void tLivingString_setFreq(tLivingString* const pl, float freq) · 1 unmodified line
665665 void tLivingString_setWaveLength(tLivingString* const pl, float waveLength)
666666 {
667667 _tLivingString* p = *pl;
668− if (waveLength < 4.8) waveLength = 4.8;
669− else if (waveLength > 2400) waveLength = 2400;
668+ if (waveLength<4.8) waveLength=4.8;
669+ else if (waveLength>2400) waveLength=2400;
670670 p->waveLengthInSamples = waveLength;
671671 tExpSmooth_setDest(&p->wlSmooth, p->waveLengthInSamples);
672672 }
@@ -776,36 +776,36 @@ float tLivingString_sample(tLivingString* const pl) · 103 unmodified lines
776776
777777 ///Reed Table model
778778 //default values from STK are 0.6 offset and -0.8 slope
779−static void reedtable_init (tReedTable* const pm, float offset, float slope)
780−{
781− _tReedTable* p = *pm;
782− p->offset = offset;
783− p->slope = slope;
784−}
785779
786780 void tReedTable_init (tReedTable* const pm, float offset, float slope)
787781 {
788− *pm = (_tReedTable*) leaf_alloc(sizeof(_tReedTable));
789− reedtable_init(pm, offset, slope);
782+ _tReedTable* p = *pm = (_tReedTable*) leaf_alloc(sizeof(_tReedTable));
783+
784+ p->offset = offset;
785+ p->slope = slope;
790786 }
791787
792788 void tReedTable_free (tReedTable* const pm)
793789 {
794790 _tReedTable* p = *pm;
791+
795792 leaf_free(p);
796793 }
797794
798795 void tReedTable_initToPool (tReedTable* const pm, float offset, float slope, tMempool* const mp)
799796 {
800797 _tMempool* m = *mp;
801− *pm = (_tReedTable*) mpool_alloc(sizeof(_tReedTable), &m->pool);
802− reedtable_init(pm, offset, slope);
798+ _tReedTable* p = *pm = (_tReedTable*) mpool_alloc(sizeof(_tReedTable), &m->pool);
799+
800+ p->offset = offset;
801+ p->slope = slope;
803802 }
804803
805804 void tReedTable_freeFromPool (tReedTable* const pm, tMempool* const mp)
806805 {
807806 _tMempool* m = *mp;
808807 _tReedTable* p = *pm;
808+
809809 mpool_free(p, &m->pool);
810810 }
811811
LEAF/Src/leaf-reverb.c+151−96
@@ -19,19 +19,15 @@ · 18 unmodified lines
1919 #endif
2020
2121 // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ PRCReverb ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ //
22−static void prcreverb_init(tPRCReverb* const rev, float t60)
22+void tPRCReverb_init(tPRCReverb* const rev, float t60)
2323 {
24− _tPRCReverb* r = *rev;
24+ _tPRCReverb* r = *rev = (_tPRCReverb*) leaf_alloc(sizeof(_tPRCReverb));
2525
2626 if (t60 <= 0.0f) t60 = 0.001f;
2727
2828 r->inv_441 = 1.0f/44100.0f;
2929
30− // Delay lengths for 44100 Hz sample rate.
31− r->lengths[0] = 341;
32− r->lengths[1] = 613;
33− r->lengths[2] = 1557;
34− r->lengths[3] = 2137;
30+ int lengths[4] = { 341, 613, 1557, 2137 }; // Delay lengths for 44100 Hz sample rate.
3531 double scaler = leaf.sampleRate * r->inv_441;
3632
3733 int delay, i;
@@ -39,34 +35,30 @@ static void prcreverb_init(tPRCReverb* const rev, float t60) · 1 unmodified line
3935 {
4036 for (i=0; i<4; i++)
4137 {
42− delay = (int) scaler * r->lengths[i];
38+ delay = (int) scaler * lengths[i];
4339
4440 if ( (delay & 1) == 0) delay++;
4541
4642 while ( !LEAF_isPrime(delay) ) delay += 2;
4743
48− r->lengths[i] = delay;
44+ lengths[i] = delay;
4945 }
5046 }
5147
48+ tDelay_init(&r->allpassDelays[0], lengths[0], lengths[0] * 2);
49+ tDelay_init(&r->allpassDelays[1], lengths[1], lengths[1] * 2);
50+ tDelay_init(&r->combDelay, lengths[2], lengths[2] * 2);
51+
5252 tPRCReverb_setT60(rev, t60);
5353
5454 r->allpassCoeff = 0.7f;
5555 r->mix = 0.5f;
5656 }
5757
58−void tPRCReverb_init(tPRCReverb* const rev, float t60)
59−{
60− _tPRCReverb* r = *rev = (_tPRCReverb*) leaf_alloc(sizeof(_tPRCReverb));
61− prcreverb_init(rev, t60);
62− tDelay_init(&r->allpassDelays[0], r->lengths[0], r->lengths[0] * 2);
63− tDelay_init(&r->allpassDelays[1], r->lengths[1], r->lengths[1] * 2);
64− tDelay_init(&r->combDelay, r->lengths[2], r->lengths[2] * 2);
65−}
66−
6758 void tPRCReverb_free(tPRCReverb* const rev)
6859 {
6960 _tPRCReverb* r = *rev;
61+
7062 tDelay_free(&r->allpassDelays[0]);
7163 tDelay_free(&r->allpassDelays[1]);
7264 tDelay_free(&r->combDelay);
@@ -77,16 +69,44 @@ void tPRCReverb_initToPool (tPRCReverb* const rev, float t60, tMempool* con · 4 unmodified lines
7769 {
7870 _tMempool* m = *mp;
7971 _tPRCReverb* r = *rev = (_tPRCReverb*) mpool_alloc(sizeof(_tPRCReverb), &m->pool);
80− prcreverb_init(rev, t60);
81− tDelay_initToPool(&r->allpassDelays[0], r->lengths[0], r->lengths[0] * 2, mp);
82− tDelay_initToPool(&r->allpassDelays[1], r->lengths[1], r->lengths[1] * 2, mp);
83− tDelay_initToPool(&r->combDelay, r->lengths[2], r->lengths[2] * 2, mp);
72+
73+ if (t60 <= 0.0f) t60 = 0.001f;
74+
75+ r->inv_441 = 1.0f/44100.0f;
76+
77+ int lengths[4] = { 341, 613, 1557, 2137 }; // Delay lengths for 44100 Hz sample rate.
78+ double scaler = leaf.sampleRate * r->inv_441;
79+
80+ int delay, i;
81+ if (scaler != 1.0f)
82+ {
83+ for (i=0; i<4; i++)
84+ {
85+ delay = (int) scaler * lengths[i];
86+
87+ if ( (delay & 1) == 0) delay++;
88+
89+ while ( !LEAF_isPrime(delay) ) delay += 2;
90+
91+ lengths[i] = delay;
92+ }
93+ }
94+
95+ tDelay_initToPool(&r->allpassDelays[0], lengths[0], lengths[0] * 2, mp);
96+ tDelay_initToPool(&r->allpassDelays[1], lengths[1], lengths[1] * 2, mp);
97+ tDelay_initToPool(&r->combDelay, lengths[2], lengths[2] * 2, mp);
98+
99+ tPRCReverb_setT60(rev, t60);
100+
101+ r->allpassCoeff = 0.7f;
102+ r->mix = 0.5f;
84103 }
85104
86105 void tPRCReverb_freeFromPool (tPRCReverb* const rev, tMempool* const mp)
87106 {
88107 _tMempool* m = *mp;
89108 _tPRCReverb* r = *rev;
109+
90110 tDelay_freeFromPool(&r->allpassDelays[0], mp);
91111 tDelay_freeFromPool(&r->allpassDelays[1], mp);
92112 tDelay_freeFromPool(&r->combDelay, mp);
@@ -152,64 +172,62 @@ void tPRCReverbSampleRateChanged (tPRCReverb* const rev) · 59 unmodified lines
152172 }
153173
154174 /* ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ NReverb ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ */
155−static void nreverb_init(tNReverb* const rev, float t60)
175+void tNReverb_init(tNReverb* const rev, float t60)
156176 {
157− _tNReverb* r = *rev;
177+ _tNReverb* r = *rev = (_tNReverb*) leaf_alloc(sizeof(_tNReverb));
158178
159179 if (t60 <= 0.0f) t60 = 0.001f;
160180
161181 r->inv_441 = 1.0f/44100.0f;
162182
163− int l[15] = {1433, 1601, 1867, 2053, 2251, 2399, 347, 113, 37, 59, 53, 43, 37, 29, 19}; // Delay lengths for 44100 Hz sample rate.
164− for (int i = 0; i < 15; i++) r->lengths[i] = l[i];
183+ int lengths[15] = {1433, 1601, 1867, 2053, 2251, 2399, 347, 113, 37, 59, 53, 43, 37, 29, 19}; // Delay lengths for 44100 Hz sample rate.
165184 double scaler = leaf.sampleRate / 25641.0f;
166185
167186 int delay, i;
187+
168188 for (i=0; i < 15; i++)
169189 {
170− delay = (int) scaler * r->lengths[i];
190+ delay = (int) scaler * lengths[i];
171191 if ( (delay & 1) == 0)
172192 delay++;
173193 while ( !LEAF_isPrime(delay) )
174194 delay += 2;
175− r->lengths[i] = delay;
195+ lengths[i] = delay;
176196 }
177197
178− tNReverb_setT60(rev, t60);
179− r->allpassCoeff = 0.7f;
180− r->mix = 0.3f;
181−
182− for (int i = 0; i < 6; i++)
183− {
184− r->combCoeffs[i] = pow(10.0, (-3 * r->lengths[i] * leaf.invSampleRate / t60));
185− }
186−}
187−
188−void tNReverb_init(tNReverb* const rev, float t60)
189−{
190− _tNReverb* r = *rev = (_tNReverb*) leaf_alloc(sizeof(_tNReverb));
191− nreverb_init(rev, t60);
192− for (int i = 0; i < 6; i++)
198+ for ( i=0; i<6; i++ )
193199 {
194− tLinearDelay_init(&r->combDelays[i], r->lengths[i], r->lengths[i] * 2.0f);
200+ tLinearDelay_init(&r->combDelays[i], lengths[i], lengths[i] * 2.0f);
201+ tLinearDelay_clear(&r->combDelays[i]);
202+ r->combCoeffs[i] = pow(10.0, (-3 * lengths[i] * leaf.invSampleRate / t60));
195203 }
196− for (int i = 0; i < 8; i++)
204+
205+ for ( i=0; i<8; i++ )
197206 {
198− tLinearDelay_init(&r->allpassDelays[i], r->lengths[i+6], r->lengths[i+6] * 2.0f);
207+ tLinearDelay_init(&r->allpassDelays[i], lengths[i+6], lengths[i+6] * 2.0f);
208+ tLinearDelay_clear(&r->allpassDelays[i]);
199209 }
210+
211+
212+ tNReverb_setT60(rev, t60);
213+ r->allpassCoeff = 0.7f;
214+ r->mix = 0.3f;
200215 }
201216
202217 void tNReverb_free(tNReverb* const rev)
203218 {
204219 _tNReverb* r = *rev;
220+
205221 for (int i = 0; i < 6; i++)
206222 {
207223 tLinearDelay_free(&r->combDelays[i]);
208224 }
225+
209226 for (int i = 0; i < 8; i++)
210227 {
211228 tLinearDelay_free(&r->allpassDelays[i]);
212229 }
230+
213231 leaf_free(r);
214232 }
215233
@@ -217,29 +235,58 @@ void tNReverb_initToPool (tNReverb* const rev, float t60, tMempool* const · 1 unmodified line
217235 {
218236 _tMempool* m = *mp;
219237 _tNReverb* r = *rev = (_tNReverb*) mpool_alloc(sizeof(_tNReverb), &m->pool);
220− nreverb_init(rev, t60);
221− for (int i = 0; i < 6; i++)
238+
239+ if (t60 <= 0.0f) t60 = 0.001f;
240+
241+ r->inv_441 = 1.0f/44100.0f;
242+
243+ int lengths[15] = {1433, 1601, 1867, 2053, 2251, 2399, 347, 113, 37, 59, 53, 43, 37, 29, 19}; // Delay lengths for 44100 Hz sample rate.
244+ double scaler = leaf.sampleRate / 25641.0f;
245+
246+ int delay, i;
247+
248+ for (i=0; i < 15; i++)
222249 {
223− tLinearDelay_initToPool(&r->combDelays[i], r->lengths[i], r->lengths[i] * 2.0f, mp);
250+ delay = (int) scaler * lengths[i];
251+ if ( (delay & 1) == 0)
252+ delay++;
253+ while ( !LEAF_isPrime(delay) )
254+ delay += 2;
255+ lengths[i] = delay;
224256 }
225− for (int i = 0; i < 8; i++)
257+
258+ for ( i=0; i<6; i++ )
259+ {
260+ tLinearDelay_initToPool(&r->combDelays[i], lengths[i], lengths[i] * 2.0f, mp);
261+ r->combCoeffs[i] = pow(10.0, (-3 * lengths[i] * leaf.invSampleRate / t60));
262+ }
263+
264+ for ( i=0; i<8; i++ )
226265 {
227− tLinearDelay_initToPool(&r->allpassDelays[i], r->lengths[i+6], r->lengths[i+6] * 2.0f, mp);
266+ tLinearDelay_initToPool(&r->allpassDelays[i], lengths[i+6], lengths[i+6] * 2.0f, mp);
228267 }
268+
269+
270+ tNReverb_setT60(rev, t60);
271+ r->allpassCoeff = 0.7f;
272+ r->mix = 0.3f;
229273 }
230274
231275 void tNReverb_freeFromPool (tNReverb* const rev, tMempool* const mp)
232276 {
233277 _tMempool* m = *mp;
234278 _tNReverb* r = *rev;
279+
235280 for (int i = 0; i < 6; i++)
236281 {
237282 tLinearDelay_freeFromPool(&r->combDelays[i], mp);
238283 }
284+
239285 for (int i = 0; i < 8; i++)
240286 {
241287 tLinearDelay_freeFromPool(&r->allpassDelays[i], mp);
242288 }
289+
243290 mpool_free(r, &m->pool);
244291 }
245292
@@ -383,76 +430,66 @@ void tNReverbSampleRateChanged (tNReverb* const rev) · 137 unmodified lines
383430 float in_allpass_delays[4] = { 4.771f, 3.595f, 12.73f, 9.307f };
384431 float in_allpass_gains[4] = { 0.75f, 0.75f, 0.625f, 0.625f };
385432
386−static void dattorroreverb_init (tDattorroReverb* const rev)
433+
434+void tDattorroReverb_init (tDattorroReverb* const rev)
387435 {
388− _tDattorroReverb* r = *rev;
436+ _tDattorroReverb* r = *rev = (_tDattorroReverb*) leaf_alloc(sizeof(_tDattorroReverb));
389437
390438 r->size_max = 2.0f;
391439 r->size = 1.f;
440+ r->t = r->size * leaf.sampleRate * 0.001f;
392441 r->frozen = 0;
393442 // INPUT
394− for (int i = 0; i < 4; i++)
395− {
396− tAllpass_setGain(&r->in_allpass[i], in_allpass_gains[i]);
397− }
398−
399− // FEEDBACK 1
400− tAllpass_setGain(&r->f1_allpass, 0.7f);
401− tCycle_setFreq(&r->f1_lfo, 0.1f);
402−
403− // FEEDBACK 2
404− tAllpass_setGain(&r->f2_allpass, 0.7f);
405− tCycle_setFreq(&r->f2_lfo, 0.07f);
406−
407− // PARAMETERS
408− tDattorroReverb_setMix(rev, 0.5f);
409− tDattorroReverb_setInputDelay(rev, 0.f);
410− tDattorroReverb_setInputFilter(rev, 10000.f);
411− tDattorroReverb_setFeedbackFilter(rev, 5000.f);
412− tDattorroReverb_setFeedbackGain(rev, 0.4f);
413−}
414−
415−void tDattorroReverb_init (tDattorroReverb* const rev)
416−{
417− _tDattorroReverb* r = *rev = (_tDattorroReverb*) leaf_alloc(sizeof(_tDattorroReverb));
418− float size_max = 2.0f;
419− r->t = leaf.sampleRate * 0.001f;
420− // INPUT
421443 tTapeDelay_init(&r->in_delay, 0.f, SAMP(200.f));
422444 tOnePole_init(&r->in_filter, 1.f);
423445
424446 for (int i = 0; i < 4; i++)
425447 {
426448 tAllpass_init(&r->in_allpass[i], SAMP(in_allpass_delays[i]), SAMP(20.f)); // * r->size_max
449+ tAllpass_setGain(&r->in_allpass[i], in_allpass_gains[i]);
427450 }
428451
429452 // FEEDBACK 1
430453 tAllpass_init(&r->f1_allpass, SAMP(30.51f), SAMP(100.f)); // * r->size_max
454+ tAllpass_setGain(&r->f1_allpass, 0.7f);
431455
432− tTapeDelay_init(&r->f1_delay_1, SAMP(141.69f), SAMP(200.0f) * size_max + 1);
433− tTapeDelay_init(&r->f1_delay_2, SAMP(89.24f), SAMP(100.0f) * size_max + 1);
434− tTapeDelay_init(&r->f1_delay_3, SAMP(125.f), SAMP(200.0f) * size_max + 1);
456+ tTapeDelay_init(&r->f1_delay_1, SAMP(141.69f), SAMP(200.0f) * r->size_max + 1);
457+ tTapeDelay_init(&r->f1_delay_2, SAMP(89.24f), SAMP(100.0f) * r->size_max + 1);
458+ tTapeDelay_init(&r->f1_delay_3, SAMP(125.f), SAMP(200.0f) * r->size_max + 1);
435459
436460 tOnePole_init(&r->f1_filter, 1.f);
437461
438462 tHighpass_init(&r->f1_hp, 20.f);
439463
440464 tCycle_init(&r->f1_lfo);
465+ tCycle_setFreq(&r->f1_lfo, 0.1f);
441466
442467 // FEEDBACK 2
443468 tAllpass_init(&r->f2_allpass, SAMP(22.58f), SAMP(100.f)); // * r->size_max
469+ tAllpass_setGain(&r->f2_allpass, 0.7f);
444470
445− tTapeDelay_init(&r->f2_delay_1, SAMP(149.62f), SAMP(200.f) * size_max + 1);
446− tTapeDelay_init(&r->f2_delay_2, SAMP(60.48f), SAMP(100.f) * size_max + 1);
447− tTapeDelay_init(&r->f2_delay_3, SAMP(106.28f), SAMP(200.f) * size_max + 1);
471+ tTapeDelay_init(&r->f2_delay_1, SAMP(149.62f), SAMP(200.f) * r->size_max + 1);
472+ tTapeDelay_init(&r->f2_delay_2, SAMP(60.48f), SAMP(100.f) * r->size_max + 1);
473+ tTapeDelay_init(&r->f2_delay_3, SAMP(106.28f), SAMP(200.f) * r->size_max + 1);
448474
449475 tOnePole_init(&r->f2_filter, 1.f);
450476
451477 tHighpass_init(&r->f2_hp, 20.f);
452478
453479 tCycle_init(&r->f2_lfo);
480+ tCycle_setFreq(&r->f2_lfo, 0.07f);
481+
482+
483+ // PARAMETERS
484+ tDattorroReverb_setMix(rev, 0.5f);
485+
486+ tDattorroReverb_setInputDelay(rev, 0.f);
487+
488+ tDattorroReverb_setInputFilter(rev, 10000.f);
489+
490+ tDattorroReverb_setFeedbackFilter(rev, 5000.f);
454491
455− dattorroreverb_init(rev);
492+ tDattorroReverb_setFeedbackGain(rev, 0.4f);
456493 }
457494
458495 void tDattorroReverb_free (tDattorroReverb* const rev)
@@ -501,8 +538,11 @@ void tDattorroReverb_initToPool (tDattorroReverb* const rev, tMempool* · 42 unmodified lines
501538 {
502539 _tMempool* m = *mp;
503540 _tDattorroReverb* r = *rev = (_tDattorroReverb*) mpool_alloc(sizeof(_tDattorroReverb), &m->pool);
504− float size_max = 2.0f;
505− r->t = leaf.sampleRate * 0.001f;
541+
542+ r->size_max = 2.0f;
543+ r->size = 1.f;
544+ r->t = r->size * leaf.sampleRate * 0.001f;
545+ r->frozen = 0;
506546 // INPUT
507547 tTapeDelay_initToPool(&r->in_delay, 0.f, SAMP(200.f), mp);
508548 tOnePole_initToPool(&r->in_filter, 1.f, mp);
@@ -510,35 +550,50 @@ void tDattorroReverb_initToPool (tDattorroReverb* const rev, tMempool* · 1 unmodified line
510550 for (int i = 0; i < 4; i++)
511551 {
512552 tAllpass_initToPool(&r->in_allpass[i], SAMP(in_allpass_delays[i]), SAMP(20.f), mp); // * r->size_max
553+ tAllpass_setGain(&r->in_allpass[i], in_allpass_gains[i]);
513554 }
514555
515556 // FEEDBACK 1
516557 tAllpass_initToPool(&r->f1_allpass, SAMP(30.51f), SAMP(100.f), mp); // * r->size_max
558+ tAllpass_setGain(&r->f1_allpass, 0.7f);
517559
518− tTapeDelay_initToPool(&r->f1_delay_1, SAMP(141.69f), SAMP(200.0f) * size_max + 1, mp);
519− tTapeDelay_initToPool(&r->f1_delay_2, SAMP(89.24f), SAMP(100.0f) * size_max + 1, mp);
520− tTapeDelay_initToPool(&r->f1_delay_3, SAMP(125.f), SAMP(200.0f) * size_max + 1, mp);
560+ tTapeDelay_initToPool(&r->f1_delay_1, SAMP(141.69f), SAMP(200.0f) * r->size_max + 1, mp);
561+ tTapeDelay_initToPool(&r->f1_delay_2, SAMP(89.24f), SAMP(100.0f) * r->size_max + 1, mp);
562+ tTapeDelay_initToPool(&r->f1_delay_3, SAMP(125.f), SAMP(200.0f) * r->size_max + 1, mp);
521563
522564 tOnePole_initToPool(&r->f1_filter, 1.f, mp);
523565
524566 tHighpass_initToPool(&r->f1_hp, 20.f, mp);
525567
526568 tCycle_initToPool(&r->f1_lfo, mp);
569+ tCycle_setFreq(&r->f1_lfo, 0.1f);
527570
528571 // FEEDBACK 2
529572 tAllpass_initToPool(&r->f2_allpass, SAMP(22.58f), SAMP(100.f), mp); // * r->size_max
573+ tAllpass_setGain(&r->f2_allpass, 0.7f);
530574
531− tTapeDelay_initToPool(&r->f2_delay_1, SAMP(149.62f), SAMP(200.f) * size_max + 1, mp);
532− tTapeDelay_initToPool(&r->f2_delay_2, SAMP(60.48f), SAMP(100.f) * size_max + 1, mp);
533− tTapeDelay_initToPool(&r->f2_delay_3, SAMP(106.28f), SAMP(200.f) * size_max + 1, mp);
575+ tTapeDelay_initToPool(&r->f2_delay_1, SAMP(149.62f), SAMP(200.f) * r->size_max + 1, mp);
576+ tTapeDelay_initToPool(&r->f2_delay_2, SAMP(60.48f), SAMP(100.f) * r->size_max + 1, mp);
577+ tTapeDelay_initToPool(&r->f2_delay_3, SAMP(106.28f), SAMP(200.f) * r->size_max + 1, mp);
534578
535579 tOnePole_initToPool(&r->f2_filter, 1.f, mp);
536580
537581 tHighpass_initToPool(&r->f2_hp, 20.f, mp);
538582
539583 tCycle_initToPool(&r->f2_lfo, mp);
584+ tCycle_setFreq(&r->f2_lfo, 0.07f);
585+
540586
541− dattorroreverb_init(rev);
587+ // PARAMETERS
588+ tDattorroReverb_setMix(rev, 0.5f);
589+
590+ tDattorroReverb_setInputDelay(rev, 0.f);
591+
592+ tDattorroReverb_setInputFilter(rev, 10000.f);
593+
594+ tDattorroReverb_setFeedbackFilter(rev, 5000.f);
595+
596+ tDattorroReverb_setFeedbackGain(rev, 0.4f);
542597 }
543598
544599 void tDattorroReverb_freeFromPool (tDattorroReverb* const rev, tMempool* const mp)
LEAF/Src/leaf-sampling.c+18−35
@@ -23,9 +23,13 @@ · 22 unmodified lines
2323 #endif
2424
2525 //==============================================================================
26−static void buffer_init (tBuffer* const sb, uint32_t length)
26+
27+void tBuffer_init (tBuffer* const sb, uint32_t length)
2728 {
28− _tBuffer* s = *sb;
29+ _tBuffer* s = *sb = (_tBuffer*) leaf_alloc(sizeof(_tBuffer));
30+
31+ s->buff = (float*) leaf_alloc( sizeof(float) * length);
32+
2933 s->bufferLength = length;
3034 s->recordedLength = 0;
3135 s->active = 0;
@@ -33,16 +37,10 @@ static void buffer_init (tBuffer* const sb, uint32_t length) · 1 unmodified line
3337 s->mode = RecordOneShot;
3438 }
3539
36−void tBuffer_init (tBuffer* const sb, uint32_t length)
37−{
38− _tBuffer* s = *sb = (_tBuffer*) leaf_alloc(sizeof(_tBuffer));
39− buffer_init(sb, length);
40− s->buff = (float*) leaf_alloc( sizeof(float) * length);
41−}
42−
4340 void tBuffer_free (tBuffer* const sb)
4441 {
4542 _tBuffer* s = *sb;
43+
4644 leaf_free(s->buff);
4745 leaf_free(s);
4846 }
@@ -51,14 +49,20 @@ void tBuffer_initToPool (tBuffer* const sb, uint32_t length, tMempool* const mp · 2 unmodified lines
5149 {
5250 _tMempool* m = *mp;
5351 _tBuffer* s = *sb = (_tBuffer*) mpool_alloc(sizeof(_tBuffer), &m->pool);
54− buffer_init(sb, length);
52+
5553 s->buff = (float*) mpool_alloc( sizeof(float) * length, &m->pool);
54+
55+ s->bufferLength = length;
56+ s->recordedLength = 0;
57+ s->idx = 0;
58+ s->mode = RecordOneShot;
5659 }
5760
5861 void tBuffer_freeFromPool (tBuffer* const sb, tMempool* const mp)
5962 {
6063 _tMempool* m = *mp;
6164 _tBuffer* s = *sb;
65+
6266 mpool_free(s->buff, &m->pool);
6367 mpool_free(s, &m->pool);
6468 }
@@ -158,9 +162,9 @@ static void handleStartEndChange(tSampler* const sp); · 93 unmodified lines
158162
159163 static void attemptStartEndChange(tSampler* const sp);
160164
161−static void sampler_init(tSampler* const sp, tBuffer* const b)
165+void tSampler_init(tSampler* const sp, tBuffer* const b)
162166 {
163− _tSampler* p = *sp;
167+ _tSampler* p = *sp = (_tSampler*) leaf_alloc(sizeof(_tSampler));
164168 _tBuffer* s = *b;
165169
166170 p->samp = s;
@@ -184,42 +188,21 @@ static void sampler_init(tSampler* const sp, tBuffer* const b) · 17 unmodified lines
184188
185189 p->cfxlen = 500; // default 300 sample crossfade
186190
191+ tRamp_init(&p->gain, 7.0f, 1);
187192 tRamp_setVal(&p->gain, 0.f);
188193
189194 p->targetstart = -1;
190195 p->targetend = -1;
191196 }
192197
193−void tSampler_init(tSampler* const sp, tBuffer* const b)
194−{
195− _tSampler* p = *sp = (_tSampler*) leaf_alloc(sizeof(_tSampler));
196− tRamp_init(&p->gain, 7.0f, 1);
197− sampler_init(sp, b);
198−}
199−
200198 void tSampler_free (tSampler* const sp)
201199 {
202200 _tSampler* p = *sp;
203201 tRamp_free(&p->gain);
202+
204203 leaf_free(p);
205204 }
206205
207−void tSampler_initToPool (tSampler* const sp, tBuffer* const b, tMempool* mp)
208−{
209− _tMempool* m = *mp;
210− _tSampler* p = *sp = (_tSampler*) mpool_alloc(sizeof(_tSampler), &m->pool);
211− tRamp_initToPool(&p->gain, 7.0f, 1, mp);
212− sampler_init(sp, b);
213−}
214−
215−void tSampler_freeFromPool (tSampler* const sp, tMempool* mp)
216−{
217− _tMempool* m = *mp;
218− _tSampler* p = *sp;
219− tRamp_freeFromPool(&p->gain, mp);
220− mpool_free(p, &m->pool);
221−}
222−
223206 void tSampler_setSample (tSampler* const sp, tBuffer* const b)
224207 {
225208 _tSampler* p = *sp;
LEAF_JUCEPlugin/Source/MyTest.cpp+1−1
@@ -46,7 +46,7 @@ void LEAFTest_init (float sampleRate, int blockSize) · 45 unmodified lines
4646 tSVF_init(&bp1, SVFTypeBandpass, 100, 4.0f);
4747 tSVF_init(&bp2, SVFTypeBandpass, 1000, 4.0f);
4848
49− tFormantShifter_init(&fs, 20);
49+ tFormantShifter_init(&fs, 2048, 20);
5050
5151 // Init and set record
5252 tBuffer_init (&buff, leaf.sampleRate); // init, 1 second buffer

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