ref: ef901ea9042b8d353fe6f976bbc04ced54b7d87a
parent: f9bde6c72bc7d6bf4f0a9d30ed904eb766577d3f
author: spiricom <jeff@snyderphonics.com>
date: Tue Jul 21 10:27:08 EDT 2020
fixed a few float/double issues found by setting more agressive warning flags
--- a/leaf/Inc/leaf-effects.h
+++ b/leaf/Inc/leaf-effects.h
@@ -125,16 +125,16 @@
void tTalkbox_free (tTalkbox* const);
float tTalkbox_tick (tTalkbox* const, float synth, float voice);
- float tTalkbox_tickFrozen (tTalkbox* const voc, float synth, float voice);
+ float tTalkbox_tickFrozen (tTalkbox* const voc, float synth, float voice);
void tTalkbox_update (tTalkbox* const);
void tTalkbox_suspend (tTalkbox* const);
void tTalkbox_lpcDurbin (float *r, int p, float *k, float *g);
- void tTalkbox_lpc (float *buf, float *car, double* dl, double* Rt, int32_t n, int32_t o, float warp, int warpOn, float *k, int freeze, float *G);
+ void tTalkbox_lpc (float *buf, float *car, double* dl, double* Rt, int32_t n, int32_t o, float warp, int warpOn, float *k, int freeze, float *G);
void tTalkbox_setQuality (tTalkbox* const, float quality);
- void tTalkbox_setWarpFactor (tTalkbox* const voc, float warp);
- void tTalkbox_setWarpOn (tTalkbox* const voc, float warpOn);
- void tTalkbox_setFreeze (tTalkbox* const voc, float freeze);
- void tTalkbox_warpedAutocorrelate (float * x, double* dl, double* Rt, unsigned int L, float * R, unsigned int P, float lambda);
+ void tTalkbox_setWarpFactor (tTalkbox* const voc, float warp);
+ void tTalkbox_setWarpOn (tTalkbox* const voc, float warpOn);
+ void tTalkbox_setFreeze (tTalkbox* const voc, float freeze);
+ void tTalkbox_warpedAutocorrelate (float * x, double* dl, double* Rt, unsigned int L, float * R, unsigned int P, float lambda);
//==============================================================================
@@ -238,16 +238,16 @@
void tTalkboxFloat_free (tTalkboxFloat* const);
float tTalkboxFloat_tick (tTalkboxFloat* const, float synth, float voice);
- float tTalkboxFloat_tickFrozen (tTalkboxFloat* const voc, float synth, float voice);
+ float tTalkboxFloat_tickFrozen (tTalkboxFloat* const voc, float synth, float voice);
void tTalkboxFloat_update (tTalkboxFloat* const);
void tTalkboxFloat_suspend (tTalkboxFloat* const);
void tTalkboxFloat_lpcDurbin (float *r, int p, float *k, float *g);
- void tTalkboxFloat_lpc (float *buf, float *car, float* dl, float* Rt, int32_t n, int32_t o, float warp, int warpOn, float *k, int freeze, float *G);
+ void tTalkboxFloat_lpc (float *buf, float *car, float* dl, float* Rt, int32_t n, int32_t o, float warp, int warpOn, float *k, int freeze, float *G);
void tTalkboxFloat_setQuality (tTalkboxFloat* const, float quality);
- void tTalkboxFloat_setWarpFactor (tTalkboxFloat* const voc, float warp);
- void tTalkboxFloat_setWarpOn (tTalkboxFloat* const voc, float warpOn);
- void tTalkboxFloat_setFreeze (tTalkboxFloat* const voc, float freeze);
- void tTalkboxFloat_warpedAutocorrelate (float * x, float* dl, float* Rt, unsigned int L, float * R, unsigned int P, float lambda);
+ void tTalkboxFloat_setWarpFactor (tTalkboxFloat* const voc, float warp);
+ void tTalkboxFloat_setWarpOn (tTalkboxFloat* const voc, int warpOn);
+ void tTalkboxFloat_setFreeze (tTalkboxFloat* const voc, int freeze);
+ void tTalkboxFloat_warpedAutocorrelate (float * x, float* dl, float* Rt, unsigned int L, float * R, unsigned int P, float lambda);
//==============================================================================
@@ -359,8 +359,8 @@
@} */
- typedef struct _tRosenbergGlottalPulse
- {
+ typedef struct _tRosenbergGlottalPulse
+ {
tMempool mempool;
float phase;
float openLength;
@@ -368,21 +368,21 @@
float invPulseLengthMinusOpenLength;
float freq;
float inc;
- } _tRosenbergGlottalPulse;
+ } _tRosenbergGlottalPulse;
- typedef _tRosenbergGlottalPulse* tRosenbergGlottalPulse;
+ typedef _tRosenbergGlottalPulse* tRosenbergGlottalPulse;
- void tRosenbergGlottalPulse_init (tRosenbergGlottalPulse* const);
- void tRosenbergGlottalPulse_initToPool (tRosenbergGlottalPulse* const, tMempool* const);
- void tRosenbergGlottalPulse_free (tRosenbergGlottalPulse* const);
+ void tRosenbergGlottalPulse_init (tRosenbergGlottalPulse* const);
+ void tRosenbergGlottalPulse_initToPool (tRosenbergGlottalPulse* const, tMempool* const);
+ void tRosenbergGlottalPulse_free (tRosenbergGlottalPulse* const);
- float tRosenbergGlottalPulse_tick (tRosenbergGlottalPulse* const);
- float tRosenbergGlottalPulse_tickHQ (tRosenbergGlottalPulse* const gp);
- void tRosenbergGlottalPulse_setFreq (tRosenbergGlottalPulse* const, float freq);
+ float tRosenbergGlottalPulse_tick (tRosenbergGlottalPulse* const);
+ float tRosenbergGlottalPulse_tickHQ (tRosenbergGlottalPulse* const gp);
+ void tRosenbergGlottalPulse_setFreq (tRosenbergGlottalPulse* const, float freq);
- void tRosenbergGlottalPulse_setOpenLength (tRosenbergGlottalPulse* const, float openLength);
+ void tRosenbergGlottalPulse_setOpenLength (tRosenbergGlottalPulse* const, float openLength);
- void tRosenbergGlottalPulse_setPulseLength (tRosenbergGlottalPulse* const, float pulseLength);
+ void tRosenbergGlottalPulse_setPulseLength (tRosenbergGlottalPulse* const, float pulseLength);
void tRosenbergGlottalPulse_setOpenLengthAndPulseLength (tRosenbergGlottalPulse* const gp, float openLength, float pulseLength);
//==============================================================================
--- a/leaf/Inc/leaf-math.h
+++ b/leaf/Inc/leaf-math.h
@@ -38,7 +38,7 @@
#define WSCALE 1.30612244898f
#define PI (3.14159265358979f)
#define TWO_PI (6.28318530717958f)
-#define HALF_PI (1.570796326794897f)
+#define HALF_PI (1.570796326794897f)
#define VSF 1.0e-38f
@@ -91,9 +91,11 @@
#define TWO_TO_32 4294967296.0f
#define INV_TWO_TO_32 0.000000000232831f
-#define ONE_OVER_SQRT2 0.707106781186548f
+#define ONE_OVER_SQRT2 0.707106781186548f
#define LOGTEN 2.302585092994
+ float log2f_approx(float X);
+ float log2f_approx2(float x);
// Jones shaper
float LEAF_shaper (float input, float m_drive);
--- a/leaf/Inc/leaf-physical.h
+++ b/leaf/Inc/leaf-physical.h
@@ -291,7 +291,7 @@
float freq, waveLengthInSamples; // the frequency of the string, determining delay length
float dampFreq; // frequency for the bridge LP filter, in Hz
float decay; // amplitude damping factor for the string (only active in mode 0)
- float levMode;
+ int levMode;
float curr;
tLinearDelay delayLine;
tOnePole bridgeFilter;
@@ -399,7 +399,7 @@
float prepIndex; // the amount of pressure on the pickpoint of the string (near 0=soft obj, near 1=hard obj)
float dampFreq; // frequency for the bridge LP filter, in Hz
float decay; // amplitude damping factor for the string (only active in mode 0)
- float levMode;
+ int levMode;
float curr;
tLinearDelay delLF,delUF,delUB,delLB; // delay for lower/upper/forward/backward part of the waveguide model
tOnePole bridgeFilter, nutFilter, prepFilterU, prepFilterL;
@@ -517,7 +517,7 @@
float prepIndex; // the amount of pressure on the pickpoint of the string (near 0=soft obj, near 1=hard obj)
float dampFreq; // frequency for the bridge LP filter, in Hz
float decay; // amplitude damping factor for the string (only active in mode 0)
- float levMode;
+ int levMode;
float curr;
tLinearDelay delLF,delUF, delMF, delMB, delUB,delLB; // delay for lower/upper/forward/backward part of the waveguide model
tOnePole bridgeFilter, nutFilter, prepFilterU, prepFilterL;
--- a/leaf/Src/leaf-analysis.c
+++ b/leaf/Src/leaf-analysis.c
@@ -96,7 +96,7 @@
z->count = 0;
z->maxWindowSize = maxWindowSize;
z->currentWindowSize = maxWindowSize;
- z->invCurrentWindowSize = 1.0f / maxWindowSize;
+ z->invCurrentWindowSize = 1.0f / (float)maxWindowSize;
z->position = 0;
z->prevPosition = maxWindowSize;
z->inBuffer = (float*) mpool_calloc(sizeof(float) * maxWindowSize, m);
@@ -392,7 +392,7 @@
{
_tAttackDetection* a = *ad;
a->atk = inAtk;
- a->atk_coeff = pow(0.01, 1.0/(a->atk * a->samplerate * 0.001));
+ a->atk_coeff = powf(0.01f, 1.0f/(a->atk * a->samplerate * 0.001f));
}
void tAttackDetection_setRelease(tAttackDetection* const ad, int inRel)
@@ -399,7 +399,7 @@
{
_tAttackDetection* a = *ad;
a->rel = inRel;
- a->rel_coeff = pow(0.01, 1.0/(a->rel * a->samplerate * 0.001));
+ a->rel_coeff = powf(0.01f, 1.0f/(a->rel * a->samplerate * 0.001f));
}
@@ -602,7 +602,7 @@
int n, tindex = s->timeindex;
int framesize = s->framesize;
int mask = framesize - 1;
- float norm = 1. / sqrt((float)(framesize * 2));
+ float norm = 1.f / sqrtf((float)(framesize * 2));
float *inputbuf = s->inputbuf;
float *processbuf = s->processbuf;
@@ -646,7 +646,7 @@
{
processbuf[n] = processbuf[n] * processbuf[n]
+ processbuf[fftsize-n] * processbuf[fftsize-n]; // imag coefficients appear reversed
- processbuf[fftsize-n] = 0.;
+ processbuf[fftsize-n] = 0.f;
}
// store power spectrum up to SR/4 for possible later use
@@ -677,7 +677,7 @@
// minimum RMS implemented as minimum autocorrelation at index 0
// functionally equivalent to white noise floor
- float rms = s->minrms / sqrt(1.0f / (float)framesize);
+ float rms = s->minrms / sqrtf(1.0f / (float)framesize);
float minrzero = rms * rms;
float rzero = processbuf[0];
if(rzero < minrzero) rzero = minrzero;
@@ -689,7 +689,7 @@
for(n=1, m=s->timeindex+1; n<seek; n++, m++)
{
signal1 = inputbuf[(n + timeindexminusone)&mask];
- signal2 = inputbuf[(framesizeplustimeindex - n)&mask];
+ signal2 = inputbuf[(framesizeplustimeindex - n)&mask]; //could this be switched to float resolution without issue? -JS
normintegral -= (double)(signal1 * signal1 + signal2 * signal2);
processbuf[n] /= (float)normintegral * 0.5f;
}
@@ -824,7 +824,7 @@
for(n=5; n<maxperiod; n++)
{
- biasbuf[n] = 1.0f - (float)logf(n - 4) * bias;
+ biasbuf[n] = 1.0f - (float)logf(n - 4.f) * bias;
}
}
@@ -864,7 +864,7 @@
p->tolerance = 1.0f;
p->timeConstant = DEFTIMECONSTANT;
p->radius = expf(-1000.0f * p->hopSize * leaf.invSampleRate / p->timeConstant);
- p->fidelityThreshold = 0.95;
+ p->fidelityThreshold = 0.95f;
}
void tPeriodDetection_free (tPeriodDetection* const pd)
@@ -903,7 +903,7 @@
// Fidelity threshold recommended by Katja Vetters is 0.95 for most instruments/voices http://www.katjaas.nl/helmholtz/helmholtz.html
if (fidelity > p->fidelityThreshold)
{
- p->period = tSNAC_getPeriod(&p->snac);
+ p->period = tSNAC_getPeriod(&p->snac);
}
p->curBlock++;
@@ -979,7 +979,7 @@
{
_tZeroCrossing2* z = *zc;
- z->_peak = fmax(s, z->_peak);
+ z->_peak = fmaxf(s, z->_peak);
if ((z->_width == 0.0f) && (s < (z->_peak * 0.3f)))
z->_width = pos - z->_leading_edge;
}
@@ -1056,11 +1056,11 @@
int size = z->_window_size / 2;
// Ensure size is a power of 2
- z->_size = pow(2, ceil(log2(size)));
+ z->_size = pow(2.0, ceil(log2((double)size)));
z->_mask = z->_size - 1;
z->_info = (tZeroCrossing2*) mpool_alloc(sizeof(tZeroCrossing2) * z->_size, m);
- for (int i = 0; i < z->_size; i++)
+ for (uint i = 0; i < z->_size; i++)
tZeroCrossing2_initToPool(&z->_info[i], mp);
z->_pos = 0;
@@ -1088,7 +1088,7 @@
// centered on the actual zero.
s += z->_hysteresis * 0.5f;
- if (z->_num_edges >= z->_size)
+ if (z->_num_edges >= (int)z->_size)
reset(zc);
if ((z->_frame == z->_window_size/2) && (z->_num_edges == 0))
@@ -1137,7 +1137,7 @@
{
_tZeroCrossings* z = *zc;
- return z->_size;
+ return (int)z->_size;
}
int tZeroCrossings_getFrame(tZeroCrossings* const zc)
@@ -1165,7 +1165,7 @@
{
_tZeroCrossings* z = *zc;
- return fmax(z->_peak, z->_peak_update);
+ return fmaxf(z->_peak, z->_peak_update);
}
int tZeroCrossings_isReset(tZeroCrossings* const zc)
@@ -1187,7 +1187,7 @@
z->_peak_update = 0.0f;
}
- if (z->_num_edges >= z->_size)
+ if (z->_num_edges >= (int)z->_size)
reset(zc);
if (s > 0.0f)
@@ -1444,7 +1444,7 @@
if (shift == 0)
{
- for (int i = 0; i != b->_mid_array; ++i)
+ for (uint i = 0; i != b->_mid_array; ++i)
// built in compiler popcount functions should be faster but we want this to be portable
// could try to add some define that call the correct function depending on compiler
// or let the user pointer popcount() to whatever they want
@@ -1454,7 +1454,7 @@
else
{
const int shift2 = value_size - shift;
- for (int i = 0; i != b->_mid_array; ++i)
+ for (uint i = 0; i != b->_mid_array; ++i)
{
unsigned int v = *p2++ >> shift;
v |= *p2 << shift2;
@@ -1721,7 +1721,7 @@
static inline void sub_collector_init(_sub_collector* collector, tZeroCrossings* const crossings, float pdt, int range)
{
collector->_zc = *crossings;
- collector->_harmonic_threshold = HARMONIC_PERIODICITY_FACTOR * 2.0f / collector->_zc->_window_size;
+ collector->_harmonic_threshold = HARMONIC_PERIODICITY_FACTOR * 2.0f / (float)collector->_zc->_window_size;
collector->_periodicity_diff_threshold = pdt;
collector->_range = range;
collector->_fundamental._i1 = -1;
@@ -1756,7 +1756,7 @@
if (info._periodicity > collector->_fundamental._periodicity &&
harmonic != collector->_fundamental._harmonic)
{
- float periodicity_diff = fabs(info._periodicity - collector->_fundamental._periodicity);
+ float periodicity_diff = fabsf(info._periodicity - collector->_fundamental._periodicity);
// If incoming periodicity is within the harmonic
// periodicity threshold, then replace _fundamental with
--- a/leaf/Src/leaf-delay.c
+++ b/leaf/Src/leaf-delay.c
@@ -58,7 +58,7 @@
void tDelay_clear(tDelay* const dl)
{
_tDelay* d = *dl;
- for (int i = 0; i < d->maxDelay; i++)
+ for (uint i = 0; i < d->maxDelay; i++)
{
d->buff[i] = 0;
}
@@ -202,11 +202,11 @@
void tLinearDelay_clear(tLinearDelay* const dl)
{
- _tLinearDelay* d = *dl;
- for (int i = 0; i < d->maxDelay; i++)
- {
- d->buff[i] = 0;
- }
+ _tLinearDelay* d = *dl;
+ for (uint i = 0; i < d->maxDelay; i++)
+ {
+ d->buff[i] = 0;
+ }
}
float tLinearDelay_tick (tLinearDelay* const dl, float input)
@@ -247,19 +247,19 @@
{
_tLinearDelay* d = *dl;
- uint32_t idx = (uint32_t) d->outPoint;
- // First 1/2 of interpolation
- d->lastOut = d->buff[idx] * d->omAlpha;
- // Second 1/2 of interpolation
- if ((idx + 1) < d->maxDelay)
- d->lastOut += d->buff[idx+1] * d->alpha;
- else
- d->lastOut += d->buff[0] * d->alpha;
+ uint32_t idx = (uint32_t) d->outPoint;
+ // First 1/2 of interpolation
+ d->lastOut = d->buff[idx] * d->omAlpha;
+ // Second 1/2 of interpolation
+ if ((idx + 1) < d->maxDelay)
+ d->lastOut += d->buff[idx+1] * d->alpha;
+ else
+ d->lastOut += d->buff[0] * d->alpha;
- // Increment output pointer modulo length
- if ( (++d->outPoint) >= d->maxDelay ) d->outPoint = 0;
+ // Increment output pointer modulo length
+ if ( (++d->outPoint) >= d->maxDelay ) d->outPoint = 0;
- return d->lastOut;
+ return d->lastOut;
}
int tLinearDelay_setDelay (tLinearDelay* const dl, float delay)
@@ -287,7 +287,7 @@
{
_tLinearDelay* d = *dl;
- uint32_t tap = d->inPoint - tapDelay - 1;
+ int32_t tap = d->inPoint - tapDelay - 1;
// Check for wraparound.
while ( tap < 0 ) tap += d->maxDelay;
@@ -298,7 +298,7 @@
{
_tLinearDelay* d = *dl;
- uint32_t tap = d->inPoint - tapDelay - 1;
+ int32_t tap = d->inPoint - tapDelay - 1;
// Check for wraparound.
while ( tap < 0 ) tap += d->maxDelay;
@@ -396,16 +396,16 @@
void tHermiteDelay_clear(tHermiteDelay* const dl)
{
- _tHermiteDelay* d = *dl;
- for (int i = 0; i < d->maxDelay; i++)
- {
- d->buff[i] = 0;
- }
+ _tHermiteDelay* d = *dl;
+ for (uint i = 0; i < d->maxDelay; i++)
+ {
+ d->buff[i] = 0;
+ }
}
float tHermiteDelay_tick (tHermiteDelay* const dl, float input)
{
- _tHermiteDelay* d = *dl;
+ _tHermiteDelay* d = *dl;
d->buff[d->inPoint] = input * d->gain;
@@ -428,7 +428,7 @@
void tHermiteDelay_tickIn (tHermiteDelay* const dl, float input)
{
- _tHermiteDelay* d = *dl;
+ _tHermiteDelay* d = *dl;
d->buff[d->inPoint] = input * d->gain;
@@ -438,7 +438,7 @@
float tHermiteDelay_tickOut (tHermiteDelay* const dl)
{
- _tHermiteDelay* d = *dl;
+ _tHermiteDelay* d = *dl;
uint32_t idx = (uint32_t) d->outPoint;
@@ -458,7 +458,7 @@
int tHermiteDelay_setDelay (tHermiteDelay* const dl, float delay)
{
- _tHermiteDelay* d = *dl;
+ _tHermiteDelay* d = *dl;
d->delay = LEAF_clip(0.0f, delay, d->maxDelay);
@@ -479,9 +479,9 @@
float tHermiteDelay_tapOut (tHermiteDelay* const dl, uint32_t tapDelay)
{
- _tHermiteDelay* d = *dl;
+ _tHermiteDelay* d = *dl;
- uint32_t tap = d->inPoint - tapDelay - 1;
+ int32_t tap = d->inPoint - tapDelay - 1;
// Check for wraparound.
while ( tap < 0 ) tap += d->maxDelay;
@@ -492,7 +492,7 @@
void tHermiteDelay_tapIn (tHermiteDelay* const dl, float value, uint32_t tapDelay)
{
- _tHermiteDelay* d = *dl;
+ _tHermiteDelay* d = *dl;
int32_t tap = d->inPoint - tapDelay - 1;
@@ -504,7 +504,7 @@
float tHermiteDelay_addTo (tHermiteDelay* const dl, float value, uint32_t tapDelay)
{
- _tHermiteDelay* d = *dl;
+ _tHermiteDelay* d = *dl;
int32_t tap = d->inPoint - tapDelay - 1;
@@ -522,19 +522,19 @@
float tHermiteDelay_getLastOut (tHermiteDelay* const dl)
{
- _tHermiteDelay* d = *dl;
+ _tHermiteDelay* d = *dl;
return d->lastOut;
}
float tHermiteDelay_getLastIn (tHermiteDelay* const dl)
{
- _tHermiteDelay* d = *dl;
+ _tHermiteDelay* d = *dl;
return d->lastIn;
}
void tHermiteDelay_setGain (tHermiteDelay* const dl, float gain)
{
- _tHermiteDelay* d = *dl;
+ _tHermiteDelay* d = *dl;
if (gain < 0.0f) d->gain = 0.0f;
else d->gain = gain;
}
@@ -541,7 +541,7 @@
float tHermiteDelay_getGain (tHermiteDelay* const dl)
{
- _tHermiteDelay* d = *dl;
+ _tHermiteDelay* d = *dl;
return d->gain;
}
@@ -593,7 +593,7 @@
void tAllpassDelay_clear(tAllpassDelay* const dl)
{
_tAllpassDelay* d = *dl;
- for (int i = 0; i < d->maxDelay; i++)
+ for (uint i = 0; i < d->maxDelay; i++)
{
d->buff[i] = 0;
}
@@ -763,7 +763,7 @@
void tTapeDelay_clear(tTapeDelay* const dl)
{
_tTapeDelay* d = *dl;
- for (int i = 0; i < d->maxDelay; i++)
+ for (uint i = 0; i < d->maxDelay; i++)
{
d->buff[i] = 0;
}
--- a/leaf/Src/leaf-effects.c
+++ b/leaf/Src/leaf-effects.c
@@ -180,9 +180,9 @@
for(i=0; i<=p; i++)
{
- a[i] = 0.0f; //probably don't need to clear at[] or k[]
+ a[i] = 0.0f; //probably don't need to clear at[] or k[]
}
- k[0] = 0.0f;
+ k[0] = 0.0f;
at[0] = 0.0f;
for(i=1; i<=p; i++)
{
@@ -261,45 +261,45 @@
int32_t i, j, nn=n;
- if (warpOn == 0)
- {
- for(j=0; j<=o; j++, nn--) //buf[] is already emphasized and windowed
- {
- z[j] = r[j] = 0.0f;
- for(i=0; i<nn; i++) r[j] += buf[i] * buf[i+j]; //autocorrelation
- }
- }
- else
- {
- for(j=0; j<=o; j++, nn--) //buf[] is already emphasized and windowed
- {
- z[j] = r[j] = 0.0f;
- }
- tTalkbox_warpedAutocorrelate(buf, dl, Rt, n, r, o, warp);
- }
+ if (warpOn == 0)
+ {
+ for(j=0; j<=o; j++, nn--) //buf[] is already emphasized and windowed
+ {
+ z[j] = r[j] = 0.0f;
+ for(i=0; i<nn; i++) r[j] += buf[i] * buf[i+j]; //autocorrelation
+ }
+ }
+ else
+ {
+ for(j=0; j<=o; j++, nn--) //buf[] is already emphasized and windowed
+ {
+ z[j] = r[j] = 0.0f;
+ }
+ tTalkbox_warpedAutocorrelate(buf, dl, Rt, n, r, o, warp);
+ }
- r[0] *= 1.001f; //stability fix
+ r[0] *= 1.001f; //stability fix
- float min = 0.000001f;
- if (!freeze)
- {
- if(r[0] < min)
- {
-// for(i=0; i<n; i++)
-// {
- buf[i] = 0.0f;
- return;
-// }
- }
+ float min = 0.000001f;
+ if (!freeze)
+ {
+ if(r[0] < min)
+ {
+ for(i=0; i<n; i++)
+ {
+ buf[i] = 0.0f;
+ return;
+ }
+ }
- tTalkbox_lpcDurbin(r, o, k, G); //calc reflection coeffs
+ tTalkbox_lpcDurbin(r, o, k, G); //calc reflection coeffs
- //this is for stability to keep reflection coefficients inside the unit circle
- //in mda's code it's .995 but in Harma's papers I've seen 0.998. just needs to be less than 1 it seems but maybe some wiggle room to avoid instability from floating point precision -JS
- for(i=0; i<=o; i++)
- {
- if(k[i] > 0.998f) k[i] = 0.998f; else if(k[i] < -0.998f) k[i] = -.998f;
- }
+ //this is for stability to keep reflection coefficients inside the unit circle
+ //in mda's code it's .995 but in Harma's papers I've seen 0.998. just needs to be less than 1 it seems but maybe some wiggle room to avoid instability from floating point precision -JS
+ for(i=0; i<=o; i++)
+ {
+ if(k[i] > 0.998f) k[i] = 0.998f; else if(k[i] < -0.998f) k[i] = -.998f;
+ }
}
for(i=0; i<n; i++)
{
@@ -320,7 +320,7 @@
v->O = (int32_t)((0.0001f + 0.0004f * v->param[3]) * leaf.sampleRate);
if (v->O >= ORD_MAX)
{
- v->O = ORD_MAX-1;
+ v->O = ORD_MAX-1;
}
}
@@ -506,10 +506,10 @@
for(i=0; i<=p; i++)
{
- a[i] = 0.0f; //probably don't need to clear at[]
+ a[i] = 0.0f; //probably don't need to clear at[]
}
- k[0] = 0.0f;
+ k[0] = 0.0f;
at[0] = 0.0f;
for(i=1; i<=p; i++)
{
@@ -588,45 +588,45 @@
int32_t i, j, nn=n;
- if (warpOn == 0)
- {
- for(j=0; j<=o; j++, nn--) //buf[] is already emphasized and windowed
- {
- z[j] = r[j] = 0.0f;
- for(i=0; i<nn; i++) r[j] += buf[i] * buf[i+j]; //autocorrelation
- }
- }
- else
- {
- for(j=0; j<=o; j++, nn--) //buf[] is already emphasized and windowed
- {
- z[j] = r[j] = 0.0f;
- }
- tTalkboxFloat_warpedAutocorrelate(buf, dl, Rt, n, r, o, warp);
- }
+ if (warpOn == 0)
+ {
+ for(j=0; j<=o; j++, nn--) //buf[] is already emphasized and windowed
+ {
+ z[j] = r[j] = 0.0f;
+ for(i=0; i<nn; i++) r[j] += buf[i] * buf[i+j]; //autocorrelation
+ }
+ }
+ else
+ {
+ for(j=0; j<=o; j++, nn--) //buf[] is already emphasized and windowed
+ {
+ z[j] = r[j] = 0.0f;
+ }
+ tTalkboxFloat_warpedAutocorrelate(buf, dl, Rt, n, r, o, warp);
+ }
- r[0] *= 1.001f; //stability fix
+ r[0] *= 1.001f; //stability fix
- float min = 0.000001f;
- if (!freeze)
- {
- if(r[0] < min)
- {
-// for(i=0; i<n; i++)
-// {
- buf[i] = 0.0f;
- return;
-// }
- }
+ float min = 0.000001f;
+ if (!freeze)
+ {
+ if(r[0] < min)
+ {
+ for(i=0; i<n; i++)
+ {
+ buf[i] = 0.0f;
+ return;
+ }
+ }
- tTalkbox_lpcDurbin(r, o, k, G); //calc reflection coeffs
+ tTalkbox_lpcDurbin(r, o, k, G); //calc reflection coeffs
- //this is for stability to keep reflection coefficients inside the unit circle
- //but in Harma's papers I've seen 0.998. just needs to be less than 1 it seems but maybe some wiggle room to avoid instability from floating point precision -JS
- for(i=0; i<=o; i++)
- {
- if(k[i] > 0.998f) k[i] = 0.998f; else if(k[i] < -0.998f) k[i] = -.998f;
- }
+ //this is for stability to keep reflection coefficients inside the unit circle
+ //but in Harma's papers I've seen 0.998. just needs to be less than 1 it seems but maybe some wiggle room to avoid instability from floating point precision -JS
+ for(i=0; i<=o; i++)
+ {
+ if(k[i] > 0.998f) k[i] = 0.998f; else if(k[i] < -0.998f) k[i] = -.998f;
+ }
}
for(i=0; i<n; i++)
{
@@ -647,7 +647,7 @@
v->O = (int32_t)((0.0001f + 0.0004f * v->param[3]) * leaf.sampleRate);
if (v->O >= ORD_MAX)
{
- v->O = ORD_MAX-1;
+ v->O = ORD_MAX-1;
}
}
@@ -658,7 +658,7 @@
v->warpFactor = warpFactor;
}
-void tTalkboxFloat_setWarpOn(tTalkboxFloat* const voc, float warpOn)
+void tTalkboxFloat_setWarpOn(tTalkboxFloat* const voc, int warpOn)
{
_tTalkboxFloat* v = *voc;
@@ -665,7 +665,7 @@
v->warpOn = warpOn;
}
-void tTalkboxFloat_setFreeze(tTalkboxFloat* const voc, float freeze)
+void tTalkboxFloat_setFreeze(tTalkboxFloat* const voc, int freeze)
{
_tTalkboxFloat* v = *voc;
@@ -764,30 +764,30 @@
}
else
{
- v->f[0][12] = (float)pow(10.0, -1.7 - 2.7f * v->param[4]); //envelope speed
+ v->f[0][12] = powf(10.0f, -1.7f - 2.7f * v->param[4]); //envelope speed
rr = 0.022f / (float)v->nbnd; //minimum proportional to frequency to stop distortion
for(i=1;i<v->nbnd;i++)
{
- v->f[i][12] = (float)(0.025 - rr * (double)i);
+ v->f[i][12] = (float)(0.025f - rr * (float)i);
if(v->f[0][12] < v->f[i][12]) v->f[i][12] = v->f[0][12];
}
v->f[0][12] = 0.5f * v->f[0][12]; //only top band is at full rate
}
- rr = 1.0 - pow(10.0f, -1.0f - 1.2f * v->param[5]);
+ rr = 1.0f - powf(10.0f, -1.0f - 1.2f * v->param[5]);
sh = (float)pow(2.0f, 3.0f * v->param[6] - 1.0f); //filter bank range shift
for(i=1;i<v->nbnd;i++)
{
v->f[i][2] *= sh;
- th = acos((2.0 * rr * cos(tpofs * v->f[i][2])) / (1.0 + rr * rr));
- v->f[i][0] = (float)(2.0 * rr * cos(th)); //a0
- v->f[i][1] = (float)(-rr * rr); //a1
+ th = acosf((2.0f * rr * cosf(tpofs * v->f[i][2])) / (1.0f + rr * rr));
+ v->f[i][0] = (2.0f * rr * cosf(th)); //a0
+ v->f[i][1] = (-rr * rr); //a1
//was .98
v->f[i][2] *= 0.96f; //shift 2nd stage slightly to stop high resonance peaks
- th = acos((2.0 * rr * cos(tpofs * v->f[i][2])) / (1.0 + rr * rr));
- v->f[i][2] = (float)(2.0 * rr * cos(th));
+ th = acosf((2.0f * rr * cosf(tpofs * v->f[i][2])) / (1.0f + rr * rr));
+ v->f[i][2] = (2.0f * rr * cosf(th));
}
}
@@ -1733,14 +1733,14 @@
float tempPeriod = tPeriodDetection_tick(&r->pd, sample);
if (tempPeriod < 1000.0f) //to avoid trying to follow consonants JS
- {
- r->inputPeriod = tempPeriod;
- }
+ {
+ r->inputPeriod = tempPeriod;
+ }
- for (int v = 0; v < r->numVoices; ++v)
- {
- r->tickOutput[v] = tPitchShift_shiftToFreq(&r->ps[v], r->freq[v]);
- }
+ for (int v = 0; v < r->numVoices; ++v)
+ {
+ r->tickOutput[v] = tPitchShift_shiftToFreq(&r->ps[v], r->freq[v]);
+ }
return r->tickOutput;
}
@@ -2057,11 +2057,11 @@
//make sure you don't divide by zero, doofies
if (fs->intensity != 0.0f)
{
- fs->invIntensity = 1.0f/fs->intensity;
+ fs->invIntensity = 1.0f/fs->intensity;
}
else
{
- fs->invIntensity = 1.0f;
+ fs->invIntensity = 1.0f;
}
}
--- a/leaf/Src/leaf-envelopes.c
+++ b/leaf/Src/leaf-envelopes.c
@@ -544,7 +544,7 @@
{
_tADSR2* adsr = *adsrenv;
adsr->attack = LEAF_clip(0.0f, attack * 0.001f, 1.0f);
- adsr->attackLambda = fastPow(ADSR2_LAMBDA_BASE, -adsr->attack) * ADSR2_INV_MIN_TIME;
+ adsr->attackLambda = fastPowf(ADSR2_LAMBDA_BASE, -adsr->attack) * ADSR2_INV_MIN_TIME;
}
@@ -552,7 +552,7 @@
{
_tADSR2* adsr = *adsrenv;
adsr->decay = LEAF_clip(0.0f, decay * 0.001f, 1.0f);
- adsr->decayLambda = fastPow(ADSR2_LAMBDA_BASE, -adsr->decay) * ADSR2_INV_MIN_TIME;
+ adsr->decayLambda = fastPowf(ADSR2_LAMBDA_BASE, -adsr->decay) * ADSR2_INV_MIN_TIME;
}
@@ -574,7 +574,7 @@
{
_tADSR2* adsr = *adsrenv;
adsr->release = LEAF_clip(0.0f, release * 0.001f, 1.0f);
- adsr->releaseLambda = fastPow(ADSR2_LAMBDA_BASE, -adsr->release) * ADSR2_INV_MIN_TIME;
+ adsr->releaseLambda = fastPowf(ADSR2_LAMBDA_BASE, -adsr->release) * ADSR2_INV_MIN_TIME;
}
// 0.999999 is slow leak, 0.9 is fast leak
@@ -644,9 +644,9 @@
//This one doesn't use any lookup table - by Nigel Redmon from his blog. Thanks, Nigel!
//-JS
-float calcADSR3Coef(double rate, double targetRatio)
+float calcADSR3Coef(float rate, float targetRatio)
{
- return (rate <= 0.0f) ? 0.0f : exp(-log((1.0 + targetRatio) / targetRatio) / rate);
+ return (rate <= 0.0f) ? 0.0f : expf(-logf((1.0f + targetRatio) / targetRatio) / rate);
}
@@ -725,7 +725,7 @@
_tADSR3* adsr = *adsrenv;
adsr->releaseRate = release * adsr->sampleRateInMs;
- adsr->releaseCoef = calcADSR3Coef(adsr->releaseRate, adsr->targetRatioDR);
+ adsr->releaseCoef = calcADSR3Coef(adsr->releaseRate, (float)adsr->targetRatioDR);
adsr->releaseBase = -adsr->targetRatioDR * (1.0f - adsr->releaseCoef);
}
@@ -785,6 +785,8 @@
adsr->output = 0.0f;
adsr->state = env_idle;
}
+ default:
+ break;
}
//smooth the gain value -- this is not ideal, a retrigger while the envelope is still going with a new gain will cause a jump, although it will be smoothed quickly. Maybe doing the math so the range is computed based on the gain rather than 0.->1. is preferable? But that's harder to get the exponential curve right without a lookup.
adsr->gain = (adsr->factor*adsr->targetGainSquared)+(adsr->oneMinusFactor*adsr->gain);
@@ -1182,14 +1184,14 @@
{
_tRamp* r = *ramp;
- if (time < r->minimum_time)
- {
- r->time = r->minimum_time;
- }
- else
- {
- r->time = time;
- }
+ if (time < r->minimum_time)
+ {
+ r->time = r->minimum_time;
+ }
+ else
+ {
+ r->time = time;
+ }
r->factor = (1.0f / r->time) * r->inv_sr_ms * (float)r->samples_per_tick;
r->inc = (r->dest - r->curr) * r->factor;
@@ -1216,10 +1218,10 @@
r->curr += r->inc;
if (((r->curr >= r->dest) && (r->inc > 0.0f)) || ((r->curr <= r->dest) && (r->inc < 0.0f)))
- {
- r->inc = 0.0f;
- r->curr=r->dest;
- }
+ {
+ r->inc = 0.0f;
+ r->curr=r->dest;
+ }
return r->curr;
}
@@ -1243,7 +1245,7 @@
/* RampUpDown */
void tRampUpDown_init(tRampUpDown* const r, float upTime, float downTime, int samples_per_tick)
{
- tRampUpDown_initToPool(r, upTime, downTime, samples_per_tick, &leaf.mempool);
+ tRampUpDown_initToPool(r, upTime, downTime, samples_per_tick, &leaf.mempool);
}
void tRampUpDown_initToPool(tRampUpDown* const r, float upTime, float downTime, int samples_per_tick, tMempool* const mp)
@@ -1341,29 +1343,29 @@
if (r->dest < r->curr)
{
- test = r->curr + r->downInc;
- if (test > r->dest)
- {
- r->curr = test;
- }
- else
- {
- r->downInc = 0.0f;
- r->curr = r->dest;
- }
+ test = r->curr + r->downInc;
+ if (test > r->dest)
+ {
+ r->curr = test;
+ }
+ else
+ {
+ r->downInc = 0.0f;
+ r->curr = r->dest;
+ }
}
else if (r->dest > r->curr)
{
- test = r->curr + r->upInc;
- if (test < r->dest)
- {
- r->curr = test;
- }
- else
- {
- r->upInc = 0.0f;
- r->curr = r->dest;
- }
+ test = r->curr + r->upInc;
+ if (test < r->dest)
+ {
+ r->curr = test;
+ }
+ else
+ {
+ r->upInc = 0.0f;
+ r->curr = r->dest;
+ }
}
return r->curr;
}
@@ -1381,7 +1383,7 @@
/* Exponential Smoother */
void tExpSmooth_init(tExpSmooth* const expsmooth, float val, float factor)
-{ // 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
+{ // 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_initToPool(expsmooth, val, factor, &leaf.mempool);
}
@@ -1407,34 +1409,34 @@
}
void tExpSmooth_setFactor(tExpSmooth* const expsmooth, float factor)
-{ // 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
+{ // 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;
- if (factor<0)
- factor=0;
- else
- if (factor>1) factor=1;
- smooth->factor=factor;
- smooth->oneminusfactor=1.0f-factor;
+ if (factor<0)
+ factor=0;
+ else
+ if (factor>1) factor=1;
+ smooth->factor=factor;
+ smooth->oneminusfactor=1.0f-factor;
}
void tExpSmooth_setDest(tExpSmooth* const expsmooth, float dest)
{
_tExpSmooth* smooth = *expsmooth;
- smooth->dest=dest;
+ smooth->dest=dest;
}
void tExpSmooth_setVal(tExpSmooth* const expsmooth, float val)
{
_tExpSmooth* smooth = *expsmooth;
- smooth->curr=val;
+ smooth->curr=val;
}
void tExpSmooth_setValAndDest(tExpSmooth* const expsmooth, float val)
{
_tExpSmooth* smooth = *expsmooth;
- smooth->curr=val;
- smooth->dest=val;
+ smooth->curr=val;
+ smooth->dest=val;
}
float tExpSmooth_tick(tExpSmooth* const expsmooth)
@@ -1455,7 +1457,7 @@
void tSlide_init (tSlide* const sl, float upSlide, float downSlide)
{
- tSlide_initToPool (sl, upSlide, downSlide, &leaf.mempool);
+ tSlide_initToPool (sl, upSlide, downSlide, &leaf.mempool);
}
void tSlide_initToPool (tSlide* const sl, float upSlide, float downSlide, tMempool* const mp)
@@ -1470,12 +1472,12 @@
s->dest = 0.0f;
if (upSlide < 1.0f)
{
- upSlide = 1.0f;
+ upSlide = 1.0f;
}
if (downSlide < 1.0f)
{
- downSlide = 1.0f;
+ downSlide = 1.0f;
}
s->invUpSlide = 1.0f / upSlide;
s->invDownSlide = 1.0f / downSlide;
@@ -1490,63 +1492,63 @@
void tSlide_setUpSlide(tSlide* const sl, float upSlide)
{
- _tSlide* s = *sl;
- s->invUpSlide = 1.0f / upSlide;
+ _tSlide* s = *sl;
+ s->invUpSlide = 1.0f / upSlide;
}
void tSlide_setDownSlide(tSlide* const sl, float downSlide)
{
- _tSlide* s = *sl;
- s->invDownSlide = 1.0f / downSlide;
+ _tSlide* s = *sl;
+ s->invDownSlide = 1.0f / downSlide;
}
void tSlide_setDest(tSlide* const sl, float dest)
{
- _tSlide* s = *sl;
- s->dest = dest;
+ _tSlide* s = *sl;
+ s->dest = dest;
}
float tSlide_tickNoInput(tSlide* const sl)
{
- _tSlide* s = *sl;
- float in = s->dest;
+ _tSlide* s = *sl;
+ float in = s->dest;
- if (in >= s->prevOut)
- {
- s->currentOut = s->prevOut + ((in - s->prevOut) * s->invUpSlide);
- }
- else
- {
- s->currentOut = s->prevOut + ((in - s->prevOut) * s->invDownSlide);
- }
+ if (in >= s->prevOut)
+ {
+ s->currentOut = s->prevOut + ((in - s->prevOut) * s->invUpSlide);
+ }
+ else
+ {
+ s->currentOut = s->prevOut + ((in - s->prevOut) * s->invDownSlide);
+ }
#ifdef NO_DENORMAL_CHECK
#else
- if (s->currentOut < VSF) s->currentOut = 0.0f;
+ if (s->currentOut < VSF) s->currentOut = 0.0f;
#endif
- s->prevIn = in;
- s->prevOut = s->currentOut;
- return s->currentOut;
+ s->prevIn = in;
+ s->prevOut = s->currentOut;
+ return s->currentOut;
}
float tSlide_tick(tSlide* const sl, float in)
{
- _tSlide* s = *sl;
+ _tSlide* s = *sl;
- if (in >= s->prevOut)
- {
- s->currentOut = s->prevOut + ((in - s->prevOut) * s->invUpSlide);
- }
- else
- {
- s->currentOut = s->prevOut + ((in - s->prevOut) * s->invDownSlide);
- }
+ if (in >= s->prevOut)
+ {
+ s->currentOut = s->prevOut + ((in - s->prevOut) * s->invUpSlide);
+ }
+ else
+ {
+ s->currentOut = s->prevOut + ((in - s->prevOut) * s->invDownSlide);
+ }
#ifdef NO_DENORMAL_CHECK
#else
- if (s->currentOut < VSF) s->currentOut = 0.0f;
+ if (s->currentOut < VSF) s->currentOut = 0.0f;
#endif
- s->prevIn = in;
- s->prevOut = s->currentOut;
- return s->currentOut;
+ s->prevIn = in;
+ s->prevOut = s->currentOut;
+ return s->currentOut;
}
--- a/leaf/Src/leaf-filters.c
+++ b/leaf/Src/leaf-filters.c
@@ -1075,7 +1075,7 @@
}
}
-void tFIR_init(tFIR* const firf, float* coeffs, int numTaps)
+void tFIR_init(tFIR* const firf, float* coeffs, int numTaps)
{
tFIR_initToPool(firf, coeffs, numTaps, &leaf.mempool);
}
@@ -1100,15 +1100,15 @@
mpool_free((char*)fir, fir->mempool);
}
-float tFIR_tick(tFIR* const firf, float input)
+float tFIR_tick(tFIR* const firf, float input)
{
_tFIR* fir = *firf;
- fir->past[0] = input;
- float y = 0.0f;
- for (int i = 0; i < fir->numTaps; ++i) y += fir->past[i]*fir->coeff[i];
- for (int i = fir->numTaps-1; i > 0; --i) fir->past[i] = fir->past[i-1];
- return y;
+ fir->past[0] = input;
+ float y = 0.0f;
+ for (int i = 0; i < fir->numTaps; ++i) y += fir->past[i]*fir->coeff[i];
+ for (int i = fir->numTaps-1; i > 0; --i) fir->past[i] = fir->past[i-1];
+ return y;
}
//---------------------------------------------
@@ -1119,7 +1119,7 @@
void tMedianFilter_init (tMedianFilter* const f, int size)
{
- tMedianFilter_initToPool(f, size, &leaf.mempool);
+ tMedianFilter_initToPool(f, size, &leaf.mempool);
}
void tMedianFilter_initToPool (tMedianFilter* const mf, int size, tMempool* const mp)
@@ -1130,15 +1130,15 @@
f->size = size;
f->middlePosition = size / 2;
- f->last = size - 1;
- f->pos = -1;
+ f->last = size - 1;
+ f->pos = -1;
f->val = (float*) mpool_alloc(sizeof(float) * size, m);
f->age = (int*) mpool_alloc(sizeof(int) * size, m);
for (int i = 0; i < f->size; ++i)
- {
- f->val[i] = 0.0f;
- f->age[i] = i;
- }
+ {
+ f->val[i] = 0.0f;
+ f->age[i] = i;
+ }
}
void tMedianFilter_free (tMedianFilter* const mf)
@@ -1152,41 +1152,41 @@
float tMedianFilter_tick (tMedianFilter* const mf, float input)
{
- _tMedianFilter* f = *mf;
+ _tMedianFilter* f = *mf;
- for(int i=0; i<f->size; i++) {
- int thisAge = f->age[i];
- if(thisAge == f->last) {
- f->pos = i;
- }
- else {
- thisAge++;
- f->age[i] = thisAge;
- }
- }
+ for(int i=0; i<f->size; i++) {
+ int thisAge = f->age[i];
+ if(thisAge == f->last) {
+ f->pos = i;
+ }
+ else {
+ thisAge++;
+ f->age[i] = thisAge;
+ }
+ }
- while( f->pos!=0 ) {
- float test = f->val[f->pos-1];
- if(input < test) {
- f->val[f->pos]=test;
- f->age[f->pos]=f->age[f->pos-1];
- f->pos -= 1;
- } else {break;}
- }
+ while( f->pos!=0 ) {
+ float test = f->val[f->pos-1];
+ if(input < test) {
+ f->val[f->pos]=test;
+ f->age[f->pos]=f->age[f->pos-1];
+ f->pos -= 1;
+ } else {break;}
+ }
- while(f->pos != f->last) {
- float test = f->val[f->pos+1];
- if( input > test) {
- f->val[f->pos] = test;
- f->age[f->pos] = f->age[f->pos+1];
- f->pos += 1;
- } else {break;}
- }
+ while(f->pos != f->last) {
+ float test = f->val[f->pos+1];
+ if( input > test) {
+ f->val[f->pos] = test;
+ f->age[f->pos] = f->age[f->pos+1];
+ f->pos += 1;
+ } else {break;}
+ }
- f->val[f->pos] = input;
- f->age[f->pos] = 0;
+ f->val[f->pos] = input;
+ f->age[f->pos] = 0;
- return f->val[f->middlePosition];
+ return f->val[f->middlePosition];
}
/////
@@ -1193,7 +1193,7 @@
void tVZFilter_init (tVZFilter* const vf, VZFilterType type, float freq, float bandWidth)
{
- tVZFilter_initToPool(vf, type, freq, bandWidth, &leaf.mempool);
+ tVZFilter_initToPool(vf, type, freq, bandWidth, &leaf.mempool);
}
void tVZFilter_initToPool (tVZFilter* const vf, VZFilterType type, float freq, float bandWidth, tMempool* const mp)
@@ -1202,17 +1202,17 @@
_tVZFilter* f = *vf = (_tVZFilter*) mpool_alloc(sizeof(_tVZFilter), m);
f->mempool = m;
- f->fc = freq;
- f->type = type;
- f->G = ONE_OVER_SQRT2;
- f->invG = 1.0f/ONE_OVER_SQRT2;
- f->B = bandWidth;
- f->m = 0.0f;
- f->s1 = 0.0f;
- f->s2 = 0.0f;
- f->sr = leaf.sampleRate;
- f->inv_sr = leaf.invSampleRate;
- tVZFilter_calcCoeffs(vf);
+ f->fc = freq;
+ f->type = type;
+ f->G = ONE_OVER_SQRT2;
+ f->invG = 1.0f/ONE_OVER_SQRT2;
+ f->B = bandWidth;
+ f->m = 0.0f;
+ f->s1 = 0.0f;
+ f->s2 = 0.0f;
+ f->sr = leaf.sampleRate;
+ f->inv_sr = leaf.invSampleRate;
+ tVZFilter_calcCoeffs(vf);
}
void tVZFilter_free (tVZFilter* const vf)
@@ -1221,103 +1221,103 @@
mpool_free((char*)f, f->mempool);
}
-void tVZFilter_setSampleRate (tVZFilter* const vf, float sampleRate)
+void tVZFilter_setSampleRate (tVZFilter* const vf, float sampleRate)
{
- _tVZFilter* f = *vf;
- f->sr = sampleRate;
- f->inv_sr = 1.0f/sampleRate;
+ _tVZFilter* f = *vf;
+ f->sr = sampleRate;
+ f->inv_sr = 1.0f/sampleRate;
}
-float tVZFilter_tick (tVZFilter* const vf, float in)
+float tVZFilter_tick (tVZFilter* const vf, float in)
{
- _tVZFilter* f = *vf;
+ _tVZFilter* f = *vf;
- float yL, yB, yH;
+ float yL, yB, yH;
- // compute highpass output via Eq. 5.1:
- yH = (in - f->R2*f->s1 - f->g*f->s1 - f->s2) * f->h;
+ // compute highpass output via Eq. 5.1:
+ yH = (in - f->R2*f->s1 - f->g*f->s1 - f->s2) * f->h;
- // compute bandpass output by applying 1st integrator to highpass output:
- yB = tanhf(f->g*yH) + f->s1;
- f->s1 = f->g*yH + yB; // state update in 1st integrator
+ // compute bandpass output by applying 1st integrator to highpass output:
+ yB = tanhf(f->g*yH) + f->s1;
+ f->s1 = f->g*yH + yB; // state update in 1st integrator
- // compute lowpass output by applying 2nd integrator to bandpass output:
- yL = tanhf(f->g*yB) + f->s2;
- f->s2 = f->g*yB + yL; // state update in 2nd integrator
+ // compute lowpass output by applying 2nd integrator to bandpass output:
+ yL = tanhf(f->g*yB) + f->s2;
+ f->s2 = f->g*yB + yL; // state update in 2nd integrator
- //according to the Vadim paper, we could add saturation to this model by adding a tanh in the integration stage.
- //
- //seems like that might look like this:
+ //according to the Vadim paper, we could add saturation to this model by adding a tanh in the integration stage.
+ //
+ //seems like that might look like this:
// y = tanh(g*x) + s; // output computation
// s = g*x + y; // state update
- //instead of this:
+ //instead of this:
// y = g*x + s; // output computation
// s = g*x + y; // state update
- return f->cL*yL + f->cB*yB + f->cH*yH;
+ return f->cL*yL + f->cB*yB + f->cH*yH;
}
-float tVZFilter_tickEfficient (tVZFilter* const vf, float in)
+float tVZFilter_tickEfficient (tVZFilter* const vf, float in)
{
- _tVZFilter* f = *vf;
+ _tVZFilter* f = *vf;
- float yL, yB, yH;
+ float yL, yB, yH;
- // compute highpass output via Eq. 5.1:
- yH = (in - f->R2*f->s1 - f->g*f->s1 - f->s2) * f->h;
+ // compute highpass output via Eq. 5.1:
+ yH = (in - f->R2*f->s1 - f->g*f->s1 - f->s2) * f->h;
- // compute bandpass output by applying 1st integrator to highpass output:
- yB = (f->g*yH) + f->s1;
- f->s1 = f->g*yH + yB; // state update in 1st integrator
+ // compute bandpass output by applying 1st integrator to highpass output:
+ yB = (f->g*yH) + f->s1;
+ f->s1 = f->g*yH + yB; // state update in 1st integrator
- // compute lowpass output by applying 2nd integrator to bandpass output:
- yL = (f->g*yB) + f->s2;
- f->s2 = f->g*yB + yL; // state update in 2nd integrator
+ // compute lowpass output by applying 2nd integrator to bandpass output:
+ yL = (f->g*yB) + f->s2;
+ f->s2 = f->g*yB + yL; // state update in 2nd integrator
- //according to the Vadim paper, we could add saturation to this model by adding a tanh in the integration stage.
- //
- //seems like that might look like this:
+ //according to the Vadim paper, we could add saturation to this model by adding a tanh in the integration stage.
+ //
+ //seems like that might look like this:
// y = tanh(g*x) + s; // output computation
// s = g*x + y; // state update
- //instead of this:
+ //instead of this:
// y = g*x + s; // output computation
// s = g*x + y; // state update
- return f->cL*yL + f->cB*yB + f->cH*yH;
+ return f->cL*yL + f->cB*yB + f->cH*yH;
}
-float tVZFilter_tickEfficientBP (tVZFilter* const vf, float in)
+float tVZFilter_tickEfficientBP (tVZFilter* const vf, float in)
{
- _tVZFilter* f = *vf;
+ _tVZFilter* f = *vf;
- float yL, yB, yH;
+ float yL, yB, yH;
- // compute highpass output via Eq. 5.1:
- yH = (in - f->R2*f->s1 - f->g*f->s1 - f->s2) * f->h;
+ // compute highpass output via Eq. 5.1:
+ yH = (in - f->R2*f->s1 - f->g*f->s1 - f->s2) * f->h;
- // compute bandpass output by applying 1st integrator to highpass output:
- yB = (f->g*yH) + f->s1;
- f->s1 = f->g*yH + yB; // state update in 1st integrator
+ // compute bandpass output by applying 1st integrator to highpass output:
+ yB = (f->g*yH) + f->s1;
+ f->s1 = f->g*yH + yB; // state update in 1st integrator
- // compute lowpass output by applying 2nd integrator to bandpass output:
- yL = (f->g*yB) + f->s2;
- f->s2 = f->g*yB + yL; // state update in 2nd integrator
+ // compute lowpass output by applying 2nd integrator to bandpass output:
+ yL = (f->g*yB) + f->s2;
+ f->s2 = f->g*yB + yL; // state update in 2nd integrator
- //according to the Vadim paper, we could add saturation to this model by adding a tanh in the integration stage.
- //
- //seems like that might look like this:
+ //according to the Vadim paper, we could add saturation to this model by adding a tanh in the integration stage.
+ //
+ //seems like that might look like this:
// y = tanh(g*x) + s; // output computation
// s = g*x + y; // state update
- //instead of this:
+ //instead of this:
// y = g*x + s; // output computation
// s = g*x + y; // state update
- return f->cL*yL + f->cB*yB + f->cH*yH;
+ return f->cL*yL + f->cB*yB + f->cH*yH;
}
@@ -1325,159 +1325,159 @@
void tVZFilter_calcCoeffs (tVZFilter* const vf)
{
- _tVZFilter* f = *vf;
- f->g = tanf(PI * f->fc * f->inv_sr); // embedded integrator gain (Fig 3.11)
+ _tVZFilter* f = *vf;
+ f->g = tanf(PI * f->fc * f->inv_sr); // embedded integrator gain (Fig 3.11)
- switch( f->type )
- {
- case Bypass:
- {
- f->R2 = f->invG; // can we use an arbitrary value here, for example R2 = 1?
- f->cL = 1.0f;
- f->cB = f->R2;
- f->cH = 1.0f;
- }
- break;
- case Lowpass:
- {
- f->R2 = f->invG;
- f->cL = 1.0f; f->cB = 0.0f; f->cH = 0.0f;
- }
- break;
- case Highpass:
- {
- f->R2 = f->invG;
- f->cL = 0.0f; f->cB = 0.0f; f->cH = 1.0f;
- }
- break;
- case BandpassSkirt:
- {
- f->R2 = f->invG;
- f->cL = 0.0f; f->cB = 1.0f; f->cH = 0.0f;
- }
- break;
- case BandpassPeak:
- {
- f->R2 = 2.0f*tVZFilter_BandwidthToR(vf, f->B);
- f->cL = 0.0f; f->cB = f->R2; f->cH = 0.0f;
- }
- break;
- case BandReject:
- {
- f->R2 = 2.0f*tVZFilter_BandwidthToR(vf, f->B);
- f->cL = 1.0f; f->cB = 0.0f; f->cH = 1.0f;
- }
- break;
- case Bell:
- {
- float fl = f->fc*powf(2.0f, (-f->B)*0.5f); // lower bandedge frequency (in Hz)
- float wl = tanf(PI*fl*f->inv_sr); // warped radian lower bandedge frequency /(2*fs)
- float r = f->g/wl;
- r *= r; // warped frequency ratio wu/wl == (wc/wl)^2 where wu is the
- // warped upper bandedge, wc the center
- f->R2 = 2.0f*sqrtf(((r*r+1.0f)/r-2.0f)/(4.0f*f->G));
- f->cL = 1.0f; f->cB = f->R2*f->G; f->cH = 1.0f;
- }
- break;
- case Lowshelf:
- {
- float A = sqrtf(f->G);
- f->g /= sqrtf(A); // scale SVF-cutoff frequency for shelvers
- f->R2 = 2*sinhf(f->B*logf(2.0f)*0.5f);
- f->cL = f->G; f->cB = f->R2*A; f->cH = 1.0f;
- }
- break;
- case Highshelf:
- {
- float A = sqrtf(f->G);
- f->g *= sqrtf(A); // scale SVF-cutoff frequency for shelvers
- f->R2 = 2.0f*sinhf(f->B*logf(2.0f)*0.5f);
- f->cL = 1.0f; f->cB = f->R2*A; f->cH = f->G;
- }
- break;
- case Allpass:
- {
- f->R2 = 2.0f*tVZFilter_BandwidthToR(vf, f->B);
- f->cL = 1.0f; f->cB = -f->R2; f->cH = 1.0f;
- }
- break;
+ switch( f->type )
+ {
+ case Bypass:
+ {
+ f->R2 = f->invG; // can we use an arbitrary value here, for example R2 = 1?
+ f->cL = 1.0f;
+ f->cB = f->R2;
+ f->cH = 1.0f;
+ }
+ break;
+ case Lowpass:
+ {
+ f->R2 = f->invG;
+ f->cL = 1.0f; f->cB = 0.0f; f->cH = 0.0f;
+ }
+ break;
+ case Highpass:
+ {
+ f->R2 = f->invG;
+ f->cL = 0.0f; f->cB = 0.0f; f->cH = 1.0f;
+ }
+ break;
+ case BandpassSkirt:
+ {
+ f->R2 = f->invG;
+ f->cL = 0.0f; f->cB = 1.0f; f->cH = 0.0f;
+ }
+ break;
+ case BandpassPeak:
+ {
+ f->R2 = 2.0f*tVZFilter_BandwidthToR(vf, f->B);
+ f->cL = 0.0f; f->cB = f->R2; f->cH = 0.0f;
+ }
+ break;
+ case BandReject:
+ {
+ f->R2 = 2.0f*tVZFilter_BandwidthToR(vf, f->B);
+ f->cL = 1.0f; f->cB = 0.0f; f->cH = 1.0f;
+ }
+ break;
+ case Bell:
+ {
+ float fl = f->fc*powf(2.0f, (-f->B)*0.5f); // lower bandedge frequency (in Hz)
+ float wl = tanf(PI*fl*f->inv_sr); // warped radian lower bandedge frequency /(2*fs)
+ float r = f->g/wl;
+ r *= r; // warped frequency ratio wu/wl == (wc/wl)^2 where wu is the
+ // warped upper bandedge, wc the center
+ f->R2 = 2.0f*sqrtf(((r*r+1.0f)/r-2.0f)/(4.0f*f->G));
+ f->cL = 1.0f; f->cB = f->R2*f->G; f->cH = 1.0f;
+ }
+ break;
+ case Lowshelf:
+ {
+ float A = sqrtf(f->G);
+ f->g /= sqrtf(A); // scale SVF-cutoff frequency for shelvers
+ f->R2 = 2*sinhf(f->B*logf(2.0f)*0.5f);
+ f->cL = f->G; f->cB = f->R2*A; f->cH = 1.0f;
+ }
+ break;
+ case Highshelf:
+ {
+ float A = sqrtf(f->G);
+ f->g *= sqrtf(A); // scale SVF-cutoff frequency for shelvers
+ f->R2 = 2.0f*sinhf(f->B*logf(2.0f)*0.5f);
+ f->cL = 1.0f; f->cB = f->R2*A; f->cH = f->G;
+ }
+ break;
+ case Allpass:
+ {
+ f->R2 = 2.0f*tVZFilter_BandwidthToR(vf, f->B);
+ f->cL = 1.0f; f->cB = -f->R2; f->cH = 1.0f;
+ }
+ break;
- // experimental - maybe we must find better curves for cL, cB, cH:
- case Morph:
- {
- f->R2 = f->invG;
- float x = 2.0f*f->m-1.0f;
+ // experimental - maybe we must find better curves for cL, cB, cH:
+ case Morph:
+ {
+ f->R2 = f->invG;
+ float x = 2.0f*f->m-1.0f;
- f->cL = maximum(-x, 0.0f); /*cL *= cL;*/
- f->cH = minimum( x, 0.0f); /*cH *= cH;*/
- f->cB = 1.0f-x*x;
+ f->cL = maximum(-x, 0.0f); /*cL *= cL;*/
+ f->cH = minimum( x, 0.0f); /*cH *= cH;*/
+ f->cB = 1.0f-x*x;
- // bottom line: we need to test different versions for how they feel when tweaking the
- // morph parameter
+ // bottom line: we need to test different versions for how they feel when tweaking the
+ // morph parameter
- // this scaling ensures constant magnitude at the cutoff point (we divide the coefficients by
- // the magnitude response value at the cutoff frequency and scale back by the gain):
- float s = f->G * sqrtf((f->R2*f->R2) / (f->cL*f->cL + f->cB*f->cB + f->cH*f->cH - 2.0f*f->cL*f->cH));
- f->cL *= s; f->cB *= s; f->cH *= s;
- }
- break;
+ // this scaling ensures constant magnitude at the cutoff point (we divide the coefficients by
+ // the magnitude response value at the cutoff frequency and scale back by the gain):
+ float s = f->G * sqrtf((f->R2*f->R2) / (f->cL*f->cL + f->cB*f->cB + f->cH*f->cH - 2.0f*f->cL*f->cH));
+ f->cL *= s; f->cB *= s; f->cH *= s;
+ }
+ break;
- }
+ }
- f->h = 1.0f / (1.0f + f->R2*f->g + f->g*f->g); // factor for feedback precomputation
+ f->h = 1.0f / (1.0f + f->R2*f->g + f->g*f->g); // factor for feedback precomputation
}
-void tVZFilter_setBandwidth (tVZFilter* const vf, float B)
+void tVZFilter_setBandwidth (tVZFilter* const vf, float B)
{
- _tVZFilter* f = *vf;
- f->B = LEAF_clip(0.0f, B, 100.0f);
- tVZFilter_calcCoeffs(vf);
+ _tVZFilter* f = *vf;
+ f->B = LEAF_clip(0.0f, B, 100.0f);
+ tVZFilter_calcCoeffs(vf);
}
void tVZFilter_setFreq (tVZFilter* const vf, float freq)
{
- _tVZFilter* f = *vf;
- f->fc = LEAF_clip(0.0f, freq, 0.5f*leaf.sampleRate);
- tVZFilter_calcCoeffs(vf);
+ _tVZFilter* f = *vf;
+ f->fc = LEAF_clip(0.0f, freq, 0.5f*leaf.sampleRate);
+ tVZFilter_calcCoeffs(vf);
}
void tVZFilter_setFreqAndBandwidth (tVZFilter* const vf, float freq, float bw)
{
- _tVZFilter* f = *vf;
- f->B = LEAF_clip(0.0f,bw, 100.0f);
- f->fc = LEAF_clip(0.0f, freq, 0.5f*leaf.sampleRate);
- tVZFilter_calcCoeffs(vf);
+ _tVZFilter* f = *vf;
+ f->B = LEAF_clip(0.0f,bw, 100.0f);
+ f->fc = LEAF_clip(0.0f, freq, 0.5f*leaf.sampleRate);
+ tVZFilter_calcCoeffs(vf);
}
-void tVZFilter_setGain (tVZFilter* const vf, float gain)
+void tVZFilter_setGain (tVZFilter* const vf, float gain)
{
- _tVZFilter* f = *vf;
- f->G = LEAF_clip(0.000001f, gain, 100.0f);
- f->invG = 1.0f/f->G;
- tVZFilter_calcCoeffs(vf);
+ _tVZFilter* f = *vf;
+ f->G = LEAF_clip(0.000001f, gain, 100.0f);
+ f->invG = 1.0f/f->G;
+ tVZFilter_calcCoeffs(vf);
}
-void tVZFilter_setMorph (tVZFilter* const vf, float morph)
+void tVZFilter_setMorph (tVZFilter* const vf, float morph)
{
- _tVZFilter* f = *vf;
- f->m = LEAF_clip(0.0f, morph, 1.0f);
- tVZFilter_calcCoeffs(vf);
+ _tVZFilter* f = *vf;
+ f->m = LEAF_clip(0.0f, morph, 1.0f);
+ tVZFilter_calcCoeffs(vf);
}
-void tVZFilter_setType (tVZFilter* const vf, VZFilterType type)
+void tVZFilter_setType (tVZFilter* const vf, VZFilterType type)
{
- _tVZFilter* f = *vf;
- f->type = type;
- tVZFilter_calcCoeffs(vf);
+ _tVZFilter* f = *vf;
+ f->type = type;
+ tVZFilter_calcCoeffs(vf);
}
float tVZFilter_BandwidthToR(tVZFilter* const vf, float B)
{
- _tVZFilter* f = *vf;
+ _tVZFilter* f = *vf;
float fl = f->fc*powf(2.0f, -B*0.5f); // lower bandedge frequency (in Hz)
float gl = tanf(PI*fl*f->inv_sr); // warped radian lower bandedge frequency /(2*fs)
float r = gl/f->g; // ratio between warped lower bandedge- and center-frequencies
- // unwarped: r = pow(2, -B/2) -> approximation for low
- // center-frequencies
+ // unwarped: r = pow(2, -B/2) -> approximation for low
+ // center-frequencies
return sqrtf((1.0f-r*r)*(1.0f-r*r)/(4.0f*r*r));
}
@@ -1485,29 +1485,29 @@
void tDiodeFilter_init (tDiodeFilter* const vf, float cutoff, float resonance)
{
- tDiodeFilter_initToPool(vf, cutoff, resonance, &leaf.mempool);
+ tDiodeFilter_initToPool(vf, cutoff, resonance, &leaf.mempool);
}
void tDiodeFilter_initToPool (tDiodeFilter* const vf, float cutoff, float resonance, tMempool* const mp)
{
- _tMempool* m = *mp;
- _tDiodeFilter* f = *vf = (_tDiodeFilter*) mpool_alloc(sizeof(_tDiodeFilter), m);
+ _tMempool* m = *mp;
+ _tDiodeFilter* f = *vf = (_tDiodeFilter*) mpool_alloc(sizeof(_tDiodeFilter), m);
f->mempool = m;
- // initialization (the resonance factor is between 0 and 8 according to the article)
- f->f = tan(PI * cutoff/leaf.sampleRate);
- f->r = (7.f * resonance + 0.5f);
- f->Vt = 0.5f;
- f->n = 1.836f;
- f->zi = 0.0f; //previous input value
- f->gamma = f->Vt*f->n;
- f->s0 = 0.01f;
- f->s1 = 0.02f;
- f->s2 = 0.03f;
- f->s3 = 0.04f;
- f->g0inv = 1.f/(2.f*f->Vt);
- f->g1inv = 1.f/(2.f*f->gamma);
- f->g2inv = 1.f/(6.f*f->gamma);
+ // initialization (the resonance factor is between 0 and 8 according to the article)
+ f->f = (float)tan((double)(PI * cutoff/leaf.sampleRate));
+ f->r = (7.f * resonance + 0.5f);
+ f->Vt = 0.5f;
+ f->n = 1.836f;
+ f->zi = 0.0f; //previous input value
+ f->gamma = f->Vt*f->n;
+ f->s0 = 0.01f;
+ f->s1 = 0.02f;
+ f->s2 = 0.03f;
+ f->s3 = 0.04f;
+ f->g0inv = 1.f/(2.f*f->Vt);
+ f->g1inv = 1.f/(2.f*f->gamma);
+ f->g2inv = 1.f/(6.f*f->gamma);
}
void tDiodeFilter_free (tDiodeFilter* const vf)
@@ -1523,63 +1523,63 @@
return ((a + 105.0f)*a + 945.0f) / ((15.0f*a + 420.0f)*a + 945.0f);
}
-float tDiodeFilter_tick (tDiodeFilter* const vf, float in)
+float tDiodeFilter_tick (tDiodeFilter* const vf, float in)
{
- _tDiodeFilter* f = *vf;
+ _tDiodeFilter* f = *vf;
- // the input x[n+1] is given by 'in', and x[n] by zi
- // input with half delay
- float ih = 0.5f * (in + f->zi);
+ // the input x[n+1] is given by 'in', and x[n] by zi
+ // input with half delay
+ float ih = 0.5f * (in + f->zi);
- // evaluate the non-linear factors
- float t0 = f->f*tanhXdX((ih - f->r * f->s3)*f->g0inv)*f->g0inv;
- float t1 = f->f*tanhXdX((f->s1-f->s0)*f->g1inv)*f->g1inv;
- float t2 = f->f*tanhXdX((f->s2-f->s1)*f->g1inv)*f->g1inv;
- float t3 = f->f*tanhXdX((f->s3-f->s2)*f->g1inv)*f->g1inv;
- float t4 = f->f*tanhXdX((f->s3)*f->g2inv)*f->g2inv;
+ // evaluate the non-linear factors
+ float t0 = f->f*tanhXdX((ih - f->r * f->s3)*f->g0inv)*f->g0inv;
+ float t1 = f->f*tanhXdX((f->s1-f->s0)*f->g1inv)*f->g1inv;
+ float t2 = f->f*tanhXdX((f->s2-f->s1)*f->g1inv)*f->g1inv;
+ float t3 = f->f*tanhXdX((f->s3-f->s2)*f->g1inv)*f->g1inv;
+ float t4 = f->f*tanhXdX((f->s3)*f->g2inv)*f->g2inv;
- // This formula gives the result for y3 thanks to MATLAB
- float y3 = (f->s2 + f->s3 + t2*(f->s1 + f->s2 + f->s3 + t1*(f->s0 + f->s1 + f->s2 + f->s3 + t0*in)) + t1*(2.0f*f->s2 + 2.0f*f->s3))*t3 + f->s3 + 2.0f*f->s3*t1 + t2*(2.0f*f->s3 + 3.0f*f->s3*t1);
+ // This formula gives the result for y3 thanks to MATLAB
+ float y3 = (f->s2 + f->s3 + t2*(f->s1 + f->s2 + f->s3 + t1*(f->s0 + f->s1 + f->s2 + f->s3 + t0*in)) + t1*(2.0f*f->s2 + 2.0f*f->s3))*t3 + f->s3 + 2.0f*f->s3*t1 + t2*(2.0f*f->s3 + 3.0f*f->s3*t1);
// if (isnan(y3))
// {
// __HAL_TIM_SET_COMPARE(&htim3, TIM_CHANNEL_2, 400);
// }
- float tempy3denom = (t4 + t1*(2.0f*t4 + 4.0f) + t2*(t4 + t1*(t4 + f->r*t0 + 4.0f) + 3.0f) + 2.0f)*t3 + t4 + t1*(2.0f*t4 + 2.0f) + t2*(2.0f*t4 + t1*(3.0f*t4 + 3.0f) + 2.0f) + 1.0f;
+ float tempy3denom = (t4 + t1*(2.0f*t4 + 4.0f) + t2*(t4 + t1*(t4 + f->r*t0 + 4.0f) + 3.0f) + 2.0f)*t3 + t4 + t1*(2.0f*t4 + 2.0f) + t2*(2.0f*t4 + t1*(3.0f*t4 + 3.0f) + 2.0f) + 1.0f;
// if (isnan(tempy3denom))
// {
// __HAL_TIM_SET_COMPARE(&htim3, TIM_CHANNEL_2, 400);
// }
- if (tempy3denom == 0.0f)
- {
- tempy3denom = 0.000001f;
- }
- y3 = y3 / tempy3denom;
+ if (tempy3denom == 0.0f)
+ {
+ tempy3denom = 0.000001f;
+ }
+ y3 = y3 / tempy3denom;
// if (isnan(y3))
// {
// __HAL_TIM_SET_COMPARE(&htim3, TIM_CHANNEL_2, 400);
// }
- if (t1 == 0.0f)
- {
- t1 = 0.000001f;
- }
- if (t2 == 0.0f)
- {
- t2 = 0.000001f;
- }
- if (t3 == 0.0f)
- {
- t3 = 0.000001f;
- }
- // Other outputs
- float y2 = (f->s3 - (1+t4+t3)*y3) / (-t3);
- float y1 = (f->s2 - (1+t3+t2)*y2 + t3*y3) / (-t2);
- float y0 = (f->s1 - (1+t2+t1)*y1 + t2*y2) / (-t1);
- float xx = (in - f->r*y3);
+ if (t1 == 0.0f)
+ {
+ t1 = 0.000001f;
+ }
+ if (t2 == 0.0f)
+ {
+ t2 = 0.000001f;
+ }
+ if (t3 == 0.0f)
+ {
+ t3 = 0.000001f;
+ }
+ // Other outputs
+ float y2 = (f->s3 - (1+t4+t3)*y3) / (-t3);
+ float y1 = (f->s2 - (1+t3+t2)*y2 + t3*y3) / (-t2);
+ float y0 = (f->s1 - (1+t2+t1)*y1 + t2*y2) / (-t1);
+ float xx = (in - f->r*y3);
- // update state
- f->s0 += 2.0f * (t0*xx + t1*(y1-y0));
+ // update state
+ f->s0 += 2.0f * (t0*xx + t1*(y1-y0));
// if (isnan(f->s0))
// {
// __HAL_TIM_SET_COMPARE(&htim3, TIM_CHANNEL_2, 400);
@@ -1589,12 +1589,12 @@
// {
// __HAL_TIM_SET_COMPARE(&htim3, TIM_CHANNEL_2, 400);
// }
- f->s1 += 2.0f * (t2*(y2-y1) - t1*(y1-y0));
- f->s2 += 2.0f * (t3*(y3-y2) - t2*(y2-y1));
- f->s3 += 2.0f * (-t4*(y3) - t3*(y3-y2));
+ f->s1 += 2.0f * (t2*(y2-y1) - t1*(y1-y0));
+ f->s2 += 2.0f * (t3*(y3-y2) - t2*(y2-y1));
+ f->s3 += 2.0f * (-t4*(y3) - t3*(y3-y2));
- f->zi = in;
- return y3*f->r;
+ f->zi = in;
+ return y3*f->r;
}
@@ -1602,15 +1602,15 @@
void tDiodeFilter_setFreq (tDiodeFilter* const vf, float cutoff)
{
- _tDiodeFilter* f = *vf;
- f->f = tanf(PI * LEAF_clip(10.0f, cutoff, 20000.0f)*leaf.invSampleRate);
+ _tDiodeFilter* f = *vf;
+ f->f = tanf(PI * LEAF_clip(10.0f, cutoff, 20000.0f)*leaf.invSampleRate);
}
void tDiodeFilter_setQ (tDiodeFilter* const vf, float resonance)
{
- _tDiodeFilter* f = *vf;
- f->r = LEAF_clip(0.5, (7.f * resonance + 0.5f), 8.0f);
+ _tDiodeFilter* f = *vf;
+ f->r = LEAF_clip(0.5, (7.f * resonance + 0.5f), 8.0f);
}
--- a/leaf/Src/leaf-math.c
+++ b/leaf/Src/leaf-math.c
@@ -2,7 +2,6 @@
leaf-math.c
Created: 22 Jan 2017 7:02:56pm
- Author: Michael R Mulshine
==============================================================================*/
@@ -40,6 +39,12 @@
return(Y);
}
+//another log2Approximation
+float log2f_approx2(float x)
+{
+ return (0.1640425613334452f * x*x*x) + (-1.098865286222744f * x*x) + (3.148297929334117f * x) + -2.213475204444817f;
+}
+
float interpolate3max(float *buf, const int peakindex)
{
float a = buf[peakindex-1];
@@ -472,12 +477,12 @@
//0.001 base gives a good curve that goes from 1 to near zero
void LEAF_generate_exp(float* buffer, float base, float start, float end, float offset, int size)
{
- float increment = (end - start) / (float)size;
- float x = start;
- for (int i = 0; i < size; i++)
- {
- buffer[i] = powf(base, x) + offset;
- x += increment;
+ float increment = (end - start) / (float)size;
+ float x = start;
+ for (int i = 0; i < size; i++)
+ {
+ buffer[i] = powf(base, x) + offset;
+ x += increment;
}
}
--- a/leaf/Src/leaf-oscillators.c
+++ b/leaf/Src/leaf-oscillators.c
@@ -132,12 +132,12 @@
// Wavetable synthesis
- temp = SINE_TABLE_SIZE * c->phase;
- intPart = (int)temp;
- fracPart = temp - (float)intPart;
- samp0 = __leaf_table_sinewave[intPart];
- if (++intPart >= SINE_TABLE_SIZE) intPart = 0;
- samp1 = __leaf_table_sinewave[intPart];
+ temp = SINE_TABLE_SIZE * c->phase;
+ intPart = (int)temp;
+ fracPart = temp - (float)intPart;
+ samp0 = __leaf_table_sinewave[intPart];
+ if (++intPart >= SINE_TABLE_SIZE) intPart = 0;
+ samp1 = __leaf_table_sinewave[intPart];
return (samp0 + (samp1 - samp0) * fracPart);
}
@@ -400,7 +400,7 @@
}
out += LEAF_poly_blep(c->phase, c->inc);
- out -= LEAF_poly_blep(fmod(c->phase + (1.0f - c->skew), 1.0f), c->inc);
+ out -= LEAF_poly_blep(fmodf(c->phase + (1.0f - c->skew), 1.0f), c->inc);
out = (skew * c->inc * out) + ((1 - c->inc) * c->lastOut);
c->lastOut = out;
@@ -463,7 +463,7 @@
if (c->phase < c->width) out = 1.0f;
else out = -1.0f;
out += LEAF_poly_blep(c->phase, c->inc);
- out -= LEAF_poly_blep(fmod(c->phase + (1.0f - c->width), 1.0f), c->inc);
+ out -= LEAF_poly_blep(fmodf(c->phase + (1.0f - c->width), 1.0f), c->inc);
c->phase += c->inc;
if (c->phase >= 1.0f)
@@ -962,9 +962,9 @@
p = 0.0f;
w = freq / leaf.sampleRate;
- if (w < 1e-5) w = 1e-5;
- if (w > 0.5) w = 0.5;
- b = 0.5 * (1.0 + c->waveform );
+ if (w < 1e-5f) w = 1e-5f;
+ if (w > 0.5f) w = 0.5f;
+ b = 0.5f * (1.0f + c->waveform );
if (b < w) b = w;
if (b > 1.0f - w) b = 1.0f - w;
/* for variable-width rectangular wave, we could do DC compensation with:
@@ -983,10 +983,10 @@
a = 0.5f; // when a = 1, LPfilter is disabled
t = freq / leaf.sampleRate;
- if (t < 1e-5) t = 1e-5;
- if (t > 0.5) t = 0.5;
+ if (t < 1e-5f) t = 1e-5f;
+ if (t > 0.5f) t = 0.5f;
dw = (t - w) ;
- t = 0.5 * (1.0 + c->waveform );
+ t = 0.5f * (1.0f + c->waveform );
if (t < w) t = w;
if (t > 1.0f - w) t = 1.0f - w;
db = (t - b) ;
@@ -1173,9 +1173,9 @@
// w = (exp2ap (freq[1] + vco->_port[OCTN] + vco->_port[TUNE] + expm[1] * vco->_port[EXPG] + 8.03136)
// + 1e3 * linm[1] * vco->_port[LING]) / SAMPLERATE;
w = freq / leaf.sampleRate;
- if (w < 1e-5) w = 1e-5;
- if (w > 0.5) w = 0.5;
- b = 0.5 * (1.0 + c->waveform);
+ if (w < 1e-5f) w = 1e-5f;
+ if (w > 0.5f) w = 0.5f;
+ b = 0.5f * (1.0f + c->waveform);
if (b < w) b = w;
if (b > 1.0f - w) b = 1.0f - w;
p = 0.5f * b;
@@ -1190,10 +1190,10 @@
a = 0.5f; // when a = 1, LPfilter is disabled
t = freq / leaf.sampleRate;
- if (t < 1e-5) t = 1e-5;
- if (t > 0.5) t = 0.5;
+ if (t < 1e-5f) t = 1e-5f;
+ if (t > 0.5f) t = 0.5f;
dw = (t - w) ;
- t = 0.5 * (1.0 + c->waveform );
+ t = 0.5f * (1.0f + c->waveform );
if (t < w) t = w;
if (t > 1.0f - w) t = 1.0f - w;
db = (t - b) ;
@@ -1380,8 +1380,8 @@
if (c->_init) {
p = 0.5f;
w = freq / leaf.sampleRate;
- if (w < 1e-5) w = 1e-5;
- if (w > 0.5) w = 0.5;
+ if (w < 1e-5f) w = 1e-5f;
+ if (w > 0.5f) w = 0.5f;
/* if we valued alias-free startup over low startup time, we could do:
* p -= w;
* place_slope_dd(_f, j, 0.0f, w, -1.0f); */
@@ -1392,8 +1392,8 @@
a = 0.5f; // when a = 1, LPfilter is disabled
t = freq / leaf.sampleRate;
- if (t < 1e-5) t = 1e-5;
- if (t > 0.5) t = 0.5;
+ if (t < 1e-5f) t = 1e-5f;
+ if (t > 0.5f) t = 0.5f;
dw = (t - w); // n= 1
w += dw;
p += w;
--- a/leaf/Src/leaf-physical.c
+++ b/leaf/Src/leaf-physical.c
@@ -360,7 +360,7 @@
p->mempool = m;
p->curr=0.0f;
- tExpSmooth_initToPool(&p->wlSmooth, leaf.sampleRate/freq, 0.01, mp); // smoother for string wavelength (not freq, to avoid expensive divisions)
+ tExpSmooth_initToPool(&p->wlSmooth, leaf.sampleRate/freq, 0.01f, mp); // smoother for string wavelength (not freq, to avoid expensive divisions)
tSimpleLivingString_setFreq(pl, freq);
tLinearDelay_initToPool(&p->delayLine,p->waveLengthInSamples, 2400, mp);
tLinearDelay_clear(&p->delayLine);
@@ -398,7 +398,7 @@
{
_tSimpleLivingString* p = *pl;
- if (waveLength<4.8) waveLength=4.8;
+ if (waveLength<4.8) waveLength=4.8f;
else if (waveLength>2400) waveLength=2400;
p->waveLengthInSamples = waveLength;
tExpSmooth_setDest(&p->wlSmooth, p->waveLengthInSamples);
@@ -477,10 +477,10 @@
p->mempool = m;
p->curr=0.0f;
- tExpSmooth_initToPool(&p->wlSmooth, leaf.sampleRate/freq, 0.01, mp); // smoother for string wavelength (not freq, to avoid expensive divisions)
+ tExpSmooth_initToPool(&p->wlSmooth, leaf.sampleRate/freq, 0.01f, mp); // smoother for string wavelength (not freq, to avoid expensive divisions)
tLivingString_setFreq(pl, freq);
p->freq = freq;
- tExpSmooth_initToPool(&p->ppSmooth, pickPos, 0.01, mp); // smoother for pick position
+ tExpSmooth_initToPool(&p->ppSmooth, pickPos, 0.01f, mp); // smoother for pick position
tLivingString_setPickPos(pl, pickPos);
p->prepIndex=prepIndex;
tLinearDelay_initToPool(&p->delLF,p->waveLengthInSamples, 2400, mp);
@@ -530,8 +530,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.f) freq=20.f;
+ else if (freq>10000.f) freq=10000.f;
p->waveLengthInSamples = leaf.sampleRate/freq;
tExpSmooth_setDest(&p->wlSmooth, p->waveLengthInSamples);
}
@@ -539,8 +539,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.8f) waveLength=4.8f;
+ else if (waveLength>2400.f) waveLength=2400.f;
p->waveLengthInSamples = waveLength;
tExpSmooth_setDest(&p->wlSmooth, p->waveLengthInSamples);
}
@@ -669,7 +669,7 @@
p->mempool = m;
p->curr=0.0f;
- tExpSmooth_initToPool(&p->wlSmooth, leaf.sampleRate/freq, 0.01, mp); // smoother for string wavelength (not freq, to avoid expensive divisions)
+ tExpSmooth_initToPool(&p->wlSmooth, leaf.sampleRate/freq, 0.01f, mp); // smoother for string wavelength (not freq, to avoid expensive divisions)
tComplexLivingString_setFreq(pl, freq);
p->freq = freq;
tExpSmooth_initToPool(&p->pickPosSmooth, pickPos, 0.01f, mp); // smoother for pick position
--- a/leaf/Src/leaf-reverb.c
+++ b/leaf/Src/leaf-reverb.c
@@ -89,7 +89,7 @@
r->t60 = t60;
- r->combCoeff = pow(10.0f, (-3.0f * tDelay_getDelay(&r->combDelay) * leaf.invSampleRate / t60 ));
+ r->combCoeff = powf(10.0f, (-3.0f * tDelay_getDelay(&r->combDelay) * leaf.invSampleRate / t60 ));
}
@@ -136,7 +136,7 @@
void tPRCReverbSampleRateChanged (tPRCReverb* const rev)
{
_tPRCReverb* r = *rev;
- r->combCoeff = pow(10.0f, (-3.0f * tDelay_getDelay(&r->combDelay) * leaf.invSampleRate / r->t60 ));
+ r->combCoeff = powf(10.0f, (-3.0f * tDelay_getDelay(&r->combDelay) * leaf.invSampleRate / r->t60 ));
}
/* ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ NReverb ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ */
@@ -172,14 +172,14 @@
for ( i=0; i<6; i++ )
{
- tLinearDelay_initToPool(&r->combDelays[i], lengths[i], lengths[i] * 2.0f, mp);
+ tLinearDelay_initToPool(&r->combDelays[i], lengths[i], lengths[i] * 2, mp);
tLinearDelay_clear(&r->combDelays[i]);
- r->combCoeffs[i] = pow(10.0, (-3 * lengths[i] * leaf.invSampleRate / t60));
+ r->combCoeffs[i] = powf(10.0f, (-3.0f * (float)lengths[i] * leaf.invSampleRate / t60));
}
for ( i=0; i<8; i++ )
{
- tLinearDelay_initToPool(&r->allpassDelays[i], lengths[i+6], lengths[i+6] * 2.0f, mp);
+ tLinearDelay_initToPool(&r->allpassDelays[i], lengths[i+6], lengths[i+6] * 2, mp);
tLinearDelay_clear(&r->allpassDelays[i]);
}
@@ -214,7 +214,7 @@
r->t60 = t60;
- for (int i=0; i<6; i++) r->combCoeffs[i] = pow(10.0, (-3.0 * tLinearDelay_getDelay(&r->combDelays[i]) * leaf.invSampleRate / t60 ));
+ for (int i=0; i<6; i++) r->combCoeffs[i] = powf(10.0f, (-3.0f * tLinearDelay_getDelay(&r->combDelays[i]) * leaf.invSampleRate / t60 ));
}
@@ -351,7 +351,7 @@
void tNReverbSampleRateChanged (tNReverb* const rev)
{
_tNReverb* r = *rev;
- for (int i=0; i<6; i++) r->combCoeffs[i] = pow(10.0, (-3.0 * tLinearDelay_getDelay(&r->combDelays[i]) * leaf.invSampleRate / r->t60 ));
+ for (int i=0; i<6; i++) r->combCoeffs[i] = powf(10.0f, (-3.0f * tLinearDelay_getDelay(&r->combDelays[i]) * leaf.invSampleRate / r->t60 ));
}
// ======================================DATTORRO=========================================
@@ -494,69 +494,69 @@
if (r->frozen)
{
- input = 0.0f;
- //r->f1_last = 0.0f;
- //r->f2_last = 0.0f;
- }
- // INPUT
- in_sample = tTapeDelay_tick(&r->in_delay, input);
+ input = 0.0f;
+ //r->f1_last = 0.0f;
+ //r->f2_last = 0.0f;
+ }
+ // INPUT
+ in_sample = tTapeDelay_tick(&r->in_delay, input);
- in_sample = tOnePole_tick(&r->in_filter, in_sample);
+ in_sample = tOnePole_tick(&r->in_filter, in_sample);
- for (int i = 0; i < 4; i++)
- {
- in_sample = tAllpass_tick(&r->in_allpass[i], in_sample);
- }
+ for (int i = 0; i < 4; i++)
+ {
+ in_sample = tAllpass_tick(&r->in_allpass[i], in_sample);
+ }
- // FEEDBACK 1
- f1_sample = in_sample + r->f2_last; // + f2_last_out;
+ // FEEDBACK 1
+ f1_sample = in_sample + r->f2_last; // + f2_last_out;
- tAllpass_setDelay(&r->f1_allpass, SAMP(30.51f) + tCycle_tick(&r->f1_lfo) * SAMP(4.0f));
+ tAllpass_setDelay(&r->f1_allpass, SAMP(30.51f) + tCycle_tick(&r->f1_lfo) * SAMP(4.0f));
- f1_sample = tAllpass_tick(&r->f1_allpass, f1_sample);
+ f1_sample = tAllpass_tick(&r->f1_allpass, f1_sample);
- f1_sample = tTapeDelay_tick(&r->f1_delay_1, f1_sample);
+ f1_sample = tTapeDelay_tick(&r->f1_delay_1, f1_sample);
- f1_sample = tOnePole_tick(&r->f1_filter, f1_sample);
+ f1_sample = tOnePole_tick(&r->f1_filter, f1_sample);
- f1_sample = f1_sample + r->f1_delay_2_last * 0.5f;
+ f1_sample = f1_sample + r->f1_delay_2_last * 0.5f;
- f1_delay_2_sample = tTapeDelay_tick(&r->f1_delay_2, f1_sample * 0.5f);
+ f1_delay_2_sample = tTapeDelay_tick(&r->f1_delay_2, f1_sample * 0.5f);
- r->f1_delay_2_last = f1_delay_2_sample;
+ r->f1_delay_2_last = f1_delay_2_sample;
- f1_sample = r->f1_delay_2_last + f1_sample;
+ f1_sample = r->f1_delay_2_last + f1_sample;
- f1_sample = tHighpass_tick(&r->f1_hp, f1_sample);
+ f1_sample = tHighpass_tick(&r->f1_hp, f1_sample);
- f1_sample *= r->feedback_gain;
+ f1_sample *= r->feedback_gain;
- r->f1_last = tTapeDelay_tick(&r->f1_delay_3, f1_sample);
+ r->f1_last = tTapeDelay_tick(&r->f1_delay_3, f1_sample);
- // FEEDBACK 2
- f2_sample = in_sample + r->f1_last;
+ // FEEDBACK 2
+ f2_sample = in_sample + r->f1_last;
- tAllpass_setDelay(&r->f2_allpass, SAMP(22.58f) + tCycle_tick(&r->f2_lfo) * SAMP(4.0f));
+ tAllpass_setDelay(&r->f2_allpass, SAMP(22.58f) + tCycle_tick(&r->f2_lfo) * SAMP(4.0f));
- f2_sample = tAllpass_tick(&r->f2_allpass, f2_sample);
+ f2_sample = tAllpass_tick(&r->f2_allpass, f2_sample);
- f2_sample = tTapeDelay_tick(&r->f2_delay_1, f2_sample);
+ f2_sample = tTapeDelay_tick(&r->f2_delay_1, f2_sample);
- f2_sample = tOnePole_tick(&r->f2_filter, f2_sample);
+ f2_sample = tOnePole_tick(&r->f2_filter, f2_sample);
- f2_sample = f2_sample + r->f2_delay_2_last * 0.5f;
+ f2_sample = f2_sample + r->f2_delay_2_last * 0.5f;
- f2_delay_2_sample = tTapeDelay_tick(&r->f2_delay_2, f2_sample * 0.5f);
+ f2_delay_2_sample = tTapeDelay_tick(&r->f2_delay_2, f2_sample * 0.5f);
- r->f2_delay_2_last = f2_delay_2_sample;
+ r->f2_delay_2_last = f2_delay_2_sample;
- f2_sample = r->f2_delay_2_last + f2_sample;
+ f2_sample = r->f2_delay_2_last + f2_sample;
- f2_sample = tHighpass_tick(&r->f2_hp, f2_sample);
+ f2_sample = tHighpass_tick(&r->f2_hp, f2_sample);
- f2_sample *= r->feedback_gain;
+ f2_sample *= r->feedback_gain;
- r->f2_last = tTapeDelay_tick(&r->f2_delay_3, f2_sample);
+ r->f2_last = tTapeDelay_tick(&r->f2_delay_3, f2_sample);
// TAP OUT 1
f1_sample = tTapeDelay_tapOut(&r->f1_delay_1, SAMP(8.9f)) +
@@ -602,79 +602,79 @@
if (r->frozen)
{
- input = 0.0f;
- //r->f1_last = 0.0f;
- //r->f2_last = 0.0f;
+ input = 0.0f;
+ //r->f1_last = 0.0f;
+ //r->f2_last = 0.0f;
}
- // INPUT
- in_sample = tTapeDelay_tick(&r->in_delay, input);
+ // INPUT
+ in_sample = tTapeDelay_tick(&r->in_delay, input);
- in_sample = tOnePole_tick(&r->in_filter, in_sample);
+ in_sample = tOnePole_tick(&r->in_filter, in_sample);
- for (int i = 0; i < 4; i++)
- {
- in_sample = tAllpass_tick(&r->in_allpass[i], in_sample);
- }
+ for (int i = 0; i < 4; i++)
+ {
+ in_sample = tAllpass_tick(&r->in_allpass[i], in_sample);
+ }
- // FEEDBACK 1
- f1_sample = in_sample + r->f2_last; // + f2_last_out;
+ // FEEDBACK 1
+ f1_sample = in_sample + r->f2_last; // + f2_last_out;
- tAllpass_setDelay(&r->f1_allpass, SAMP(30.51f) + tCycle_tick(&r->f1_lfo) * SAMP(4.0f));
+ tAllpass_setDelay(&r->f1_allpass, SAMP(30.51f) + tCycle_tick(&r->f1_lfo) * SAMP(4.0f));
- f1_sample = tAllpass_tick(&r->f1_allpass, f1_sample);
+ f1_sample = tAllpass_tick(&r->f1_allpass, f1_sample);
- f1_sample = tTapeDelay_tick(&r->f1_delay_1, f1_sample);
+ f1_sample = tTapeDelay_tick(&r->f1_delay_1, f1_sample);
- f1_sample = tOnePole_tick(&r->f1_filter, f1_sample);
+ f1_sample = tOnePole_tick(&r->f1_filter, f1_sample);
- f1_sample = f1_sample + r->f1_delay_2_last * 0.5f;
+ f1_sample = f1_sample + r->f1_delay_2_last * 0.5f;
- f1_delay_2_sample = tTapeDelay_tick(&r->f1_delay_2, f1_sample * 0.5f);
+ f1_delay_2_sample = tTapeDelay_tick(&r->f1_delay_2, f1_sample * 0.5f);
- r->f1_delay_2_last = f1_delay_2_sample;
+ r->f1_delay_2_last = f1_delay_2_sample;
- f1_sample = r->f1_delay_2_last + f1_sample;
+ f1_sample = r->f1_delay_2_last + f1_sample;
- f1_sample = tHighpass_tick(&r->f1_hp, f1_sample);
+ f1_sample = tHighpass_tick(&r->f1_hp, f1_sample);
- f1_sample *= r->feedback_gain;
+ f1_sample *= r->feedback_gain;
- if (r->frozen)
- {
- f1_sample = 0.0f;
- }
+ if (r->frozen)
+ {
+ f1_sample = 0.0f;
+ }
- r->f1_last = tTapeDelay_tick(&r->f1_delay_3, f1_sample);
+ r->f1_last = tTapeDelay_tick(&r->f1_delay_3, f1_sample);
- // FEEDBACK 2
- f2_sample = in_sample + r->f1_last;
+ // FEEDBACK 2
+ f2_sample = in_sample + r->f1_last;
- tAllpass_setDelay(&r->f2_allpass, SAMP(22.58f) + tCycle_tick(&r->f2_lfo) * SAMP(4.0f));
+ tAllpass_setDelay(&r->f2_allpass, SAMP(22.58f) + tCycle_tick(&r->f2_lfo) * SAMP(4.0f));
- f2_sample = tAllpass_tick(&r->f2_allpass, f2_sample);
+ f2_sample = tAllpass_tick(&r->f2_allpass, f2_sample);
- f2_sample = tTapeDelay_tick(&r->f2_delay_1, f2_sample);
+ f2_sample = tTapeDelay_tick(&r->f2_delay_1, f2_sample);
- f2_sample = tOnePole_tick(&r->f2_filter, f2_sample);
+ f2_sample = tOnePole_tick(&r->f2_filter, f2_sample);
- f2_sample = f2_sample + r->f2_delay_2_last * 0.5f;
+ f2_sample = f2_sample + r->f2_delay_2_last * 0.5f;
- f2_delay_2_sample = tTapeDelay_tick(&r->f2_delay_2, f2_sample * 0.5f);
+ f2_delay_2_sample = tTapeDelay_tick(&r->f2_delay_2, f2_sample * 0.5f);
- r->f2_delay_2_last = f2_delay_2_sample;
+ r->f2_delay_2_last = f2_delay_2_sample;
- f2_sample = r->f2_delay_2_last + f2_sample;
+ f2_sample = r->f2_delay_2_last + f2_sample;
- f2_sample = tHighpass_tick(&r->f2_hp, f2_sample);
+ f2_sample = tHighpass_tick(&r->f2_hp, f2_sample);
- f2_sample *= r->feedback_gain;
+ f2_sample *= r->feedback_gain;
- if (r->frozen)
- {
- f2_sample = 0.0f;
- }
- r->f2_last = tTapeDelay_tick(&r->f2_delay_3, f2_sample);
+ if (r->frozen)
+ {
+ f2_sample = 0.0f;
+ }
+ r->f2_last = tTapeDelay_tick(&r->f2_delay_3, f2_sample);
@@ -727,26 +727,26 @@
r->frozen = freeze;
if (freeze)
{
- tAllpass_setGain(&r->f2_allpass, 1.0f);
- tAllpass_setGain(&r->f1_allpass, 1.0f);
- for (int i = 0; i < 4; i++)
- {
+ tAllpass_setGain(&r->f2_allpass, 1.0f);
+ tAllpass_setGain(&r->f1_allpass, 1.0f);
+ for (int i = 0; i < 4; i++)
+ {
- //tAllpass_setGain(&r->in_allpass[i], 1.0f);
- }
- tCycle_setFreq(&r->f1_lfo, 0.0f);
- tCycle_setFreq(&r->f2_lfo, 0.0f);
+ //tAllpass_setGain(&r->in_allpass[i], 1.0f);
+ }
+ tCycle_setFreq(&r->f1_lfo, 0.0f);
+ tCycle_setFreq(&r->f2_lfo, 0.0f);
}
else
{
- tAllpass_setGain(&r->f2_allpass, 0.7f);
- tAllpass_setGain(&r->f1_allpass, 0.7f);
- for (int i = 0; i < 4; i++)
- {
- //tAllpass_setGain(&r->in_allpass[i], in_allpass_gains[i]);
- }
- tCycle_setFreq(&r->f1_lfo, 0.1f);
- tCycle_setFreq(&r->f2_lfo, 0.07f);
+ tAllpass_setGain(&r->f2_allpass, 0.7f);
+ tAllpass_setGain(&r->f1_allpass, 0.7f);
+ for (int i = 0; i < 4; i++)
+ {
+ //tAllpass_setGain(&r->in_allpass[i], in_allpass_gains[i]);
+ }
+ tCycle_setFreq(&r->f1_lfo, 0.1f);
+ tCycle_setFreq(&r->f2_lfo, 0.07f);
}
}
--- a/leaf/Src/leaf-sampling.c
+++ b/leaf/Src/leaf-sampling.c
@@ -80,7 +80,7 @@
void tBuffer_read(tBuffer* const sb, float* buff, uint32_t len)
{
_tBuffer* s = *sb;
- for (int i = 0; i < s->bufferLength; i++)
+ for (uint i = 0; i < s->bufferLength; i++)
{
if (i < len) s->buff[i] = buff[i];
else s->buff[i] = 0.f;
@@ -91,7 +91,7 @@
float tBuffer_get (tBuffer* const sb, int idx)
{
_tBuffer* s = *sb;
- if ((idx < 0) || (idx >= s->bufferLength)) return 0.f;
+ if ((idx < 0) || (idx >= (int) s->bufferLength)) return 0.f;
return s->buff[idx];
}
@@ -129,7 +129,7 @@
void tBuffer_clear (tBuffer* const sb)
{
_tBuffer* s = *sb;
- for (int i = 0; i < s->bufferLength; i++)
+ for (uint i = 0; i < s->bufferLength; i++)
{
s->buff[i] = 0.f;
}
@@ -263,8 +263,8 @@
int myEnd = p->end;
if (p->flip < 0)
{
- myStart = p->end;
- myEnd = p->start;
+ myStart = p->end;
+ myEnd = p->start;
}
// Get the direction and a reverse flag for some calcs
@@ -442,16 +442,16 @@
if (p->mode == PlayNormal)
{
- 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))
+ 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);
p->active = -1;