ref: 5c365acaa20ffd1684e9cb4bb2c8bdfa1593a184
parent: 99c38ddf6e7f4a82136000f02c66b6b1219de031
author: spiricom <jeff@snyderphonics.com>
date: Fri Jun 12 19:14:57 EDT 2020
leaf version used in vocodec that was sent to beta testers
--- a/leaf/Inc/leaf-filters.h
+++ b/leaf/Inc/leaf-filters.h
@@ -415,7 +415,6 @@
float cL, cB, cH; // coefficients for low-, band-, and highpass signals
// parameters:
- float fs; // sample-rate
float fc; // characteristic frequency
float G; // gain
float invG; //1/gain
--- a/leaf/Src/leaf-delay.c
+++ b/leaf/Src/leaf-delay.c
@@ -33,11 +33,11 @@
{
_tMempool* m = *mp;
_tDelay* d = *dl = (_tDelay*) mpool_alloc(sizeof(_tDelay), m);
-
+
d->maxDelay = maxDelay;
-
+
d->delay = delay;
-
+
d->buff = (float*) mpool_alloc(sizeof(float) * maxDelay, m);
d->inPoint = 0;
@@ -72,16 +72,16 @@
float tDelay_tick (tDelay* const dl, float input)
{
_tDelay* d = *dl;
-
+
// Input
d->lastIn = input;
d->buff[d->inPoint] = input * d->gain;
if (++(d->inPoint) == d->maxDelay) d->inPoint = 0;
-
+
// Output
d->lastOut = d->buff[d->outPoint];
if (++(d->outPoint) == d->maxDelay) d->outPoint = 0;
-
+
return d->lastOut;
}
@@ -88,13 +88,13 @@
int tDelay_setDelay (tDelay* const dl, uint32_t delay)
{
_tDelay* d = *dl;
-
+
d->delay = LEAF_clip(0.0f, delay, d->maxDelay);
-
+
// read chases write
if ( d->inPoint >= delay ) d->outPoint = d->inPoint - d->delay;
else d->outPoint = d->maxDelay + d->inPoint - d->delay;
-
+
return 0;
}
@@ -101,20 +101,20 @@
float tDelay_tapOut (tDelay* const dl, uint32_t tapDelay)
{
_tDelay* d = *dl;
-
+
int32_t tap = d->inPoint - tapDelay - 1;
-
+
// Check for wraparound.
while ( tap < 0 ) tap += d->maxDelay;
-
+
return d->buff[tap];
-
+
}
void tDelay_tapIn (tDelay* const dl, float value, uint32_t tapDelay)
{
_tDelay* d = *dl;
-
+
int32_t tap = d->inPoint - tapDelay - 1;
// Check for wraparound.
@@ -181,17 +181,17 @@
{
_tMempool* m = *mp;
_tLinearDelay* d = *dl = (_tLinearDelay*) mpool_alloc(sizeof(_tLinearDelay), m);
-
+
d->maxDelay = maxDelay;
-
+
if (delay > maxDelay) d->delay = maxDelay;
else if (delay < 0.0f) d->delay = 0.0f;
else d->delay = delay;
-
+
d->buff = (float*) mpool_alloc(sizeof(float) * maxDelay, m);
-
+
d->gain = 1.0f;
-
+
d->lastIn = 0.0f;
d->lastOut = 0.0f;
@@ -222,9 +222,9 @@
float tLinearDelay_tick (tLinearDelay* const dl, float input)
{
_tLinearDelay* d = *dl;
-
+
d->buff[d->inPoint] = input * d->gain;
-
+
// Increment input pointer modulo length.
if (++(d->inPoint) == d->maxDelay ) d->inPoint = 0;
@@ -239,7 +239,7 @@
// Increment output pointer modulo length
if ( (++d->outPoint) >= d->maxDelay ) d->outPoint = 0;
-
+
return d->lastOut;
}
@@ -246,7 +246,7 @@
void tLinearDelay_tickIn (tLinearDelay* const dl, float input)
{
_tLinearDelay* d = *dl;
-
+
d->buff[d->inPoint] = input * d->gain;
// Increment input pointer modulo length.
@@ -256,7 +256,7 @@
float tLinearDelay_tickOut (tLinearDelay* const dl)
{
_tLinearDelay* d = *dl;
-
+
uint32_t idx = (uint32_t) d->outPoint;
// First 1/2 of interpolation
d->lastOut = d->buff[idx] * d->omAlpha;
@@ -275,21 +275,21 @@
int tLinearDelay_setDelay (tLinearDelay* const dl, float delay)
{
_tLinearDelay* d = *dl;
-
+
d->delay = LEAF_clip(0.0f, delay, d->maxDelay);
-
+
float outPointer = d->inPoint - d->delay;
-
+
while ( outPointer < 0 )
outPointer += d->maxDelay; // modulo maximum length
-
+
d->outPoint = (uint32_t) outPointer; // integer part
-
+
d->alpha = outPointer - d->outPoint; // fractional part
d->omAlpha = 1.0f - d->alpha;
-
+
if ( d->outPoint == d->maxDelay ) d->outPoint = 0;
-
+
return 0;
}
@@ -296,11 +296,11 @@
float tLinearDelay_tapOut (tLinearDelay* const dl, uint32_t tapDelay)
{
_tLinearDelay* d = *dl;
-
+
uint32_t tap = d->inPoint - tapDelay - 1;
// Check for wraparound.
while ( tap < 0 ) tap += d->maxDelay;
-
+
return d->buff[tap];
}
@@ -307,12 +307,12 @@
void tLinearDelay_tapIn (tLinearDelay* const dl, float value, uint32_t tapDelay)
{
_tLinearDelay* d = *dl;
-
+
uint32_t tap = d->inPoint - tapDelay - 1;
-
+
// Check for wraparound.
while ( tap < 0 ) tap += d->maxDelay;
-
+
d->buff[tap] = value;
}
@@ -319,9 +319,9 @@
float tLinearDelay_addTo (tLinearDelay* const dl, float value, uint32_t tapDelay)
{
_tLinearDelay* d = *dl;
-
+
int32_t tap = d->inPoint - tapDelay - 1;
-
+
// Check for wraparound.
while ( tap < 0 ) tap += d->maxDelay;
@@ -579,15 +579,15 @@
{
_tMempool* m = *mp;
_tAllpassDelay* d = *dl = (_tAllpassDelay*) mpool_alloc(sizeof(_tAllpassDelay), m);
-
+
d->maxDelay = maxDelay;
-
+
if (delay > maxDelay) d->delay = maxDelay;
else if (delay < 0.0f) d->delay = 0.0f;
else d->delay = delay;
-
+
d->buff = (float*) mpool_alloc(sizeof(float) * maxDelay, m);
-
+
d->gain = 1.0f;
d->lastIn = 0.0f;
@@ -622,23 +622,23 @@
float tAllpassDelay_tick (tAllpassDelay* const dl, float input)
{
_tAllpassDelay* d = *dl;
-
+
d->buff[d->inPoint] = input * d->gain;
-
+
// Increment input pointer modulo length.
if ( ++(d->inPoint) >= d->maxDelay ) d->inPoint = 0;
-
+
// Do allpass interpolation delay.
float out = d->lastOut * -d->coeff;
out += d->apInput + ( d->coeff * d->buff[d->outPoint] );
d->lastOut = out;
-
+
// Save allpass input
d->apInput = d->buff[d->outPoint];
-
+
// Increment output pointer modulo length.
if (++(d->outPoint) >= d->maxDelay ) d->outPoint = 0;
-
+
return d->lastOut;
}
@@ -645,20 +645,20 @@
int tAllpassDelay_setDelay (tAllpassDelay* const dl, float delay)
{
_tAllpassDelay* d = *dl;
-
+
d->delay = LEAF_clip(0.5f, delay, d->maxDelay);
-
+
// outPoint chases inPoint
float outPointer = (float)d->inPoint - d->delay + 1.0f;
-
+
while ( outPointer < 0 ) outPointer += d->maxDelay; // mod max length
-
+
d->outPoint = (uint32_t) outPointer; // integer part
-
+
if ( d->outPoint >= d->maxDelay ) d->outPoint = 0;
-
+
d->alpha = 1.0f + (float)d->outPoint - outPointer; // fractional part
-
+
if ( d->alpha < 0.5f )
{
// The optimal range for alpha is about 0.5 - 1.5 in order to
@@ -670,9 +670,9 @@
d->alpha += 1.0f;
}
-
+
d->coeff = (1.0f - d->alpha) / (1.0f + d->alpha); // coefficient for allpass
-
+
return 0;
}
@@ -679,25 +679,25 @@
float tAllpassDelay_tapOut (tAllpassDelay* const dl, uint32_t tapDelay)
{
_tAllpassDelay* d = *dl;
-
+
int32_t tap = d->inPoint - tapDelay - 1;
-
+
// Check for wraparound.
while ( tap < 0 ) tap += d->maxDelay;
-
+
return d->buff[tap];
-
+
}
void tAllpassDelay_tapIn (tAllpassDelay* const dl, float value, uint32_t tapDelay)
{
_tAllpassDelay* d = *dl;
-
+
int32_t tap = d->inPoint - tapDelay - 1;
-
+
// Check for wraparound.
while ( tap < 0 ) tap += d->maxDelay;
-
+
d->buff[tap] = value;
}
@@ -704,12 +704,12 @@
float tAllpassDelay_addTo (tAllpassDelay* const dl, float value, uint32_t tapDelay)
{
_tAllpassDelay* d = *dl;
-
+
int32_t tap = d->inPoint - tapDelay - 1;
-
+
// Check for wraparound.
while ( tap < 0 ) tap += d->maxDelay;
-
+
return (d->buff[tap] += value);
}
@@ -759,20 +759,20 @@
{
_tMempool* m = *mp;
_tTapeDelay* d = *dl = (_tTapeDelay*) mpool_alloc(sizeof(_tTapeDelay), m);
-
+
d->maxDelay = maxDelay;
-
+
d->buff = (float*) mpool_alloc(sizeof(float) * maxDelay, m);
-
+
d->gain = 1.0f;
-
+
d->lastIn = 0.0f;
d->lastOut = 0.0f;
-
+
d->idx = 0.0f;
d->inc = 1.0f;
d->inPoint = 0;
-
+
tTapeDelay_setDelay(dl, delay);
}
@@ -780,7 +780,7 @@
{
_tMempool* m = *mp;
_tTapeDelay* d = *dl;
-
+
mpool_free((char*)d->buff, m);
mpool_free((char*)d, m);
}
@@ -799,28 +799,28 @@
float tTapeDelay_tick (tTapeDelay* const dl, float input)
{
_tTapeDelay* d = *dl;
-
+
d->buff[d->inPoint] = input * d->gain;
-
+
// Increment input pointer modulo length.
if (++(d->inPoint) == d->maxDelay ) d->inPoint = 0;
int idx = (int) d->idx;
float alpha = d->idx - idx;
-
+
d->lastOut = LEAF_interpolate_hermite_x (d->buff[((idx - 1) + d->maxDelay) % d->maxDelay],
d->buff[idx],
d->buff[(idx + 1) % d->maxDelay],
d->buff[(idx + 2) % d->maxDelay],
alpha);
-
+
float diff = (d->inPoint - d->idx);
while (diff < 0.f) diff += d->maxDelay;
-
+
d->inc = 1.0f + (diff - d->delay) / d->delay; //* SMOOTH_FACTOR;
d->idx += d->inc;
-
+
if (d->idx >= d->maxDelay) d->idx = 0.0f;
if (d->lastOut)
@@ -851,30 +851,30 @@
float tTapeDelay_tapOut (tTapeDelay* const dl, float tapDelay)
{
_tTapeDelay* d = *dl;
-
+
float tap = (float) d->inPoint - tapDelay - 1.f;
-
+
// Check for wraparound.
while ( tap < 0.f ) tap += (float)d->maxDelay;
-
+
int idx = (int) tap;
-
+
float alpha = tap - idx;
-
+
float samp = LEAF_interpolate_hermite_x (d->buff[((idx - 1) + d->maxDelay) % d->maxDelay],
d->buff[idx],
d->buff[(idx + 1) % d->maxDelay],
d->buff[(idx + 2) % d->maxDelay],
alpha);
-
+
return samp;
-
+
}
void tTapeDelay_tapIn (tTapeDelay* const dl, float value, uint32_t tapDelay)
{
_tTapeDelay* d = *dl;
-
+
int32_t tap = d->inPoint - tapDelay - 1;
// Check for wraparound.
--- a/leaf/Src/leaf-effects.c
+++ b/leaf/Src/leaf-effects.c
@@ -859,12 +859,14 @@
v->kout = oo;
v->kval = k & 0x1;
+#ifdef NO_DENORMAL_CHECK
+#else
if(fabs(v->f[0][11])<1.0e-10) v->f[0][11] = 0.0f; //catch HF envelope denormal
for(i=1;i<nb;i++)
if(fabs(v->f[i][3])<1.0e-10 || fabs(v->f[i][7])<1.0e-10)
for(k=3; k<12; k++) v->f[i][k] = 0.0f; //catch reson & envelope denormals
-
+#endif
if(fabs(o)>10.0f) tVocoder_suspend(voc); //catch instability
return o;
--- a/leaf/Src/leaf-envelopes.c
+++ b/leaf/Src/leaf-envelopes.c
@@ -1559,7 +1559,10 @@
{
s->currentOut = s->prevOut + ((in - s->prevOut) * s->invDownSlide);
}
+#ifdef NO_DENORMAL_CHECK
+#else
if (s->currentOut < VSF) s->currentOut = 0.0f;
+#endif
s->prevIn = in;
s->prevOut = s->currentOut;
return s->currentOut;
@@ -1578,7 +1581,10 @@
{
s->currentOut = s->prevOut + ((in - s->prevOut) * s->invDownSlide);
}
+#ifdef NO_DENORMAL_CHECK
+#else
if (s->currentOut < VSF) s->currentOut = 0.0f;
+#endif
s->prevIn = in;
s->prevOut = s->currentOut;
return s->currentOut;
--- a/leaf/Src/leaf-sampling.c
+++ b/leaf/Src/leaf-sampling.c
@@ -268,12 +268,12 @@
float* buff = p->samp->buff;
// Variables so start is also before end
- int32_t start = p->start;
- int32_t end = p->end;
+ int myStart = p->start;
+ int myEnd = p->end;
if (p->flip < 0)
{
- start = p->end;
- end = p->start;
+ myStart = p->end;
+ myEnd = p->start;
}
// Get the direction and a reverse flag for some calcs
@@ -306,17 +306,17 @@
buff[i4],
alpha);
- uint32_t cfxlen = p->cfxlen;
+ int32_t cfxlen = p->cfxlen;
if (p->len * 0.25f < cfxlen) cfxlen = p->len * 0.25f;
// Determine crossfade points
- uint32_t fadeLeftStart = 0;
- if (start >= cfxlen) fadeLeftStart = start - cfxlen;
- uint32_t fadeLeftEnd = fadeLeftStart + cfxlen;
+ int32_t fadeLeftStart = 0;
+ if (myStart >= cfxlen) fadeLeftStart = myStart - cfxlen;
+ int32_t fadeLeftEnd = fadeLeftStart + cfxlen;
- uint32_t fadeRightEnd = end;// + (fadeLeftEnd - start);
+ int32_t fadeRightEnd = myEnd;// + (fadeLeftEnd - start);
// if (fadeRightEnd >= length) fadeRightEnd = length - 1;
- uint32_t fadeRightStart = fadeRightEnd - cfxlen;
+ int32_t fadeRightStart = fadeRightEnd - cfxlen;
@@ -401,7 +401,7 @@
}
}
- float inc = fmod(p->inc, p->len);
+ float inc = fmodf(p->inc, (float)p->len);
p->idx += (dir * inc);
if (p->flipStart >= 0)
{
@@ -424,11 +424,11 @@
if (p->mode == PlayLoop)
{
- if((int)p->idx < start)
+ if((int)p->idx < myStart)
{
p->idx += (float)(fadeRightEnd - fadeLeftEnd);
}
- if((int)p->idx > end)
+ if((int)p->idx > myEnd)
{
p->idx -= (float)(fadeRightEnd - fadeLeftEnd);
@@ -436,15 +436,15 @@
}
else if (p->mode == PlayBackAndForth)
{
- if (p->idx < start)
+ if (p->idx < myStart)
{
p->bnf = -p->bnf;
- p->idx = start + 1;
+ p->idx = myStart + 1;
}
- else if (p->idx > end)
+ else if (p->idx > myEnd)
{
p->bnf = -p->bnf;
- p->idx = end - 1;
+ p->idx = myEnd - 1;
}
}
@@ -451,7 +451,15 @@
if (p->mode == PlayNormal)
{
- float ticksToEnd = rev ? ((idx - start) * p->iinc) : ((end - idx) * p->iinc);
+ if (p->idx < myStart)
+ {
+ p->idx = myStart;
+ }
+ else if (p->idx > myEnd)
+ {
+ p->idx = myEnd;
+ }
+ float ticksToEnd = rev ? ((idx - myStart) * p->iinc) : ((myEnd - idx) * p->iinc);
if (ticksToEnd < (0.007f * leaf.sampleRate))
{
tRamp_setDest(&p->gain, 0.f);