ref: b0581564da7738318ea9f7805fb2bd3b0b73bcc4
parent: 9cb36a1965a989fd17f8efee6a0655d79a0f2a76
author: Matthew Wang <mjw7@princeton.edu>
date: Wed Feb 5 08:20:05 EST 2020
fix init bugs in poly and feedbackLeveler
--- a/LEAF/Src/leaf-dynamics.c
+++ b/LEAF/Src/leaf-dynamics.c
@@ -114,10 +114,10 @@
{
_tFeedbackLeveler* p = *fb;
- p->curr=0.0f;
- p->targetLevel=targetLevel;
- p->mode=mode;
- p->strength=strength;
+ p->curr = 0.0f;
+ p->targetLevel = targetLevel;
+ p->mode = mode;
+ p->strength = strength;
}
void tFeedbackLeveler_init(tFeedbackLeveler* const fb, float targetLevel, float factor, float strength, int mode)
@@ -139,7 +139,7 @@
_tMempool* m = *mp;
_tFeedbackLeveler* p = *fb = (_tFeedbackLeveler*) mpool_alloc(sizeof(_tFeedbackLeveler), &m->pool);
feedbackleveler_init(fb, targetLevel, factor, strength, mode);
- tPowerFollower_init(&p->pwrFlw,factor);
+ tPowerFollower_initToPool(&p->pwrFlw, factor, mp);
}
void tFeedbackLeveler_freeFromPool (tFeedbackLeveler* const fb, tMempool* const mp)
--- a/LEAF/Src/leaf-effects.c
+++ b/LEAF/Src/leaf-effects.c
@@ -1273,7 +1273,6 @@
tPitchShift_free(&r->ps[i]);
leaf_free(r->outBuffers[i]);
}
- tPeriodDetection_free(&r->pd);
leaf_free(r->tickOutput);
leaf_free(r->freq);
leaf_free(r->ps);
--- a/LEAF/Src/leaf-envelopes.c
+++ b/LEAF/Src/leaf-envelopes.c
@@ -603,12 +603,12 @@
{ // 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
_tExpSmooth* smooth = *expsmooth;
- smooth->curr=val;
- smooth->dest=val;
- if (factor<0) factor=0;
- if (factor>1) factor=1;
- smooth->factor=factor;
- smooth->oneminusfactor=1.0f-factor;
+ smooth->curr = val;
+ smooth->dest = val;
+ if (factor < 0) factor = 0;
+ if (factor > 1) factor = 1;
+ smooth->factor = factor;
+ smooth->oneminusfactor = 1.0f - factor;
}
void tExpSmooth_init(tExpSmooth* const expsmooth, float val, float factor)
--- a/LEAF/Src/leaf-midi.c
+++ b/LEAF/Src/leaf-midi.c
@@ -301,6 +301,11 @@
void tPoly_init(tPoly* const polyh, int maxNumVoices)
{
_tPoly* poly = *polyh = (_tPoly*) leaf_alloc(sizeof(_tPoly));
+
+ poly->ramps = (tRamp*) leaf_alloc(sizeof(tRamp) * maxNumVoices);
+ poly->rampVals = (float*) leaf_alloc(sizeof(float) * maxNumVoices);
+ poly->firstReceived = (oBool*) leaf_alloc(sizeof(oBool) * maxNumVoices);
+ poly->voices = (int**) leaf_alloc(sizeof(int*) * maxNumVoices);
for (int i = 0; i < maxNumVoices; ++i)
{
poly->voices[i] = (int*) leaf_alloc(sizeof(int) * 2);
@@ -307,11 +312,6 @@
}
poly_init(polyh, maxNumVoices);
- poly->ramps = (tRamp*) leaf_alloc(sizeof(tRamp) * poly->maxNumVoices);
- poly->rampVals = (float*) leaf_alloc(sizeof(float) * poly->maxNumVoices);
- poly->firstReceived = (oBool*) leaf_alloc(sizeof(oBool) * poly->maxNumVoices);
- poly->voices = (int**) leaf_alloc(sizeof(int*) * poly->maxNumVoices);
-
for (int i = 0; i < poly->maxNumVoices; ++i)
{
tRamp_init(&poly->ramps[i], poly->glideTime, 1);
@@ -346,16 +346,16 @@
{
_tMempool* m = *mp;
_tPoly* poly = *polyh = (_tPoly*) mpool_alloc(sizeof(_tPoly), &m->pool);
+
+ poly->ramps = (tRamp*) mpool_alloc(sizeof(tRamp) * maxNumVoices, &m->pool);
+ poly->rampVals = (float*) mpool_alloc(sizeof(float) * maxNumVoices, &m->pool);
+ poly->firstReceived = (oBool*) mpool_alloc(sizeof(oBool) * maxNumVoices, &m->pool);
+ poly->voices = (int**) mpool_alloc(sizeof(int*) * maxNumVoices, &m->pool);
for (int i = 0; i < maxNumVoices; ++i)
{
poly->voices[i] = (int*) mpool_alloc(sizeof(int) * 2, &m->pool);
}
poly_init(polyh, maxNumVoices);
-
- poly->ramps = (tRamp*) mpool_alloc(sizeof(tRamp) * poly->maxNumVoices, &m->pool);
- poly->rampVals = (float*) mpool_alloc(sizeof(float) * poly->maxNumVoices, &m->pool);
- poly->firstReceived = (oBool*) mpool_alloc(sizeof(oBool) * poly->maxNumVoices, &m->pool);
- poly->voices = (int**) mpool_alloc(sizeof(int*) * poly->maxNumVoices, &m->pool);
for (int i = 0; i < poly->maxNumVoices; ++i)
{
--- a/LEAF/Src/leaf-physical.c
+++ b/LEAF/Src/leaf-physical.c
@@ -19,8 +19,6 @@
/* ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ tPluck ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ */
static void pluck_init (tPluck* const pl, float lowestFrequency)
{
- _tPluck* p = *pl;
-
if ( lowestFrequency <= 0.0f ) lowestFrequency = 10.0f;
tPluck_setFrequency(pl, 220.0f);
@@ -548,7 +546,7 @@
{
_tLivingString* p = *pl;
- p->curr=0.0f;
+ p->curr = 0.0f;
p->freq = freq;
p->prepIndex = prepIndex;
p->dampFreq = dampFreq;
@@ -658,8 +656,8 @@
void tLivingString_setFreq(tLivingString* const pl, float freq)
{ // NOTE: It is faster to set wavelength in samples directly
_tLivingString* p = *pl;
- if (freq<20) freq=20;
- else if (freq>10000) freq=10000;
+ if (freq < 20) freq = 20;
+ else if (freq > 10000) freq = 10000;
p->waveLengthInSamples = leaf.sampleRate/freq;
tExpSmooth_setDest(&p->wlSmooth, p->waveLengthInSamples);
}
@@ -667,8 +665,8 @@
void tLivingString_setWaveLength(tLivingString* const pl, float waveLength)
{
_tLivingString* p = *pl;
- if (waveLength<4.8) waveLength=4.8;
- else if (waveLength>2400) waveLength=2400;
+ if (waveLength < 4.8) waveLength = 4.8;
+ else if (waveLength > 2400) waveLength = 2400;
p->waveLengthInSamples = waveLength;
tExpSmooth_setDest(&p->wlSmooth, p->waveLengthInSamples);
}
@@ -787,7 +785,7 @@
void tReedTable_init (tReedTable* const pm, float offset, float slope)
{
- _tReedTable* p = *pm = (_tReedTable*) leaf_alloc(sizeof(_tReedTable));
+ *pm = (_tReedTable*) leaf_alloc(sizeof(_tReedTable));
reedtable_init(pm, offset, slope);
}
@@ -800,7 +798,7 @@
void tReedTable_initToPool (tReedTable* const pm, float offset, float slope, tMempool* const mp)
{
_tMempool* m = *mp;
- _tReedTable* p = *pm = (_tReedTable*) mpool_alloc(sizeof(_tReedTable), &m->pool);
+ *pm = (_tReedTable*) mpool_alloc(sizeof(_tReedTable), &m->pool);
reedtable_init(pm, offset, slope);
}