Skip to content

Commit

Permalink
some issue with leaf_clip being inline
Browse files Browse the repository at this point in the history
  • Loading branch information
spiricom committed Aug 17, 2024
1 parent 8d86c4e commit e8ee875
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 32 deletions.
50 changes: 25 additions & 25 deletions leaf/Inc/leaf-math.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,9 @@ extern "C" {
#define log10f_fast(x) (log2f_approx(x)*0.3010299956639812f)
#define twelfthRootOf2 1.0594630943592952646f

#ifdef ITCMRAM
Lfloat __attribute__ ((section(".itcmram"))) __attribute__ ((aligned (32))) LEAF_clip(Lfloat min, Lfloat val, Lfloat max)
#else
inline Lfloat LEAF_clip(Lfloat min, Lfloat val, Lfloat max)
#endif
{

inline Lfloat LEAF_clip(Lfloat min, Lfloat val, Lfloat max)
{
if (val < min)
{
return min;
Expand Down Expand Up @@ -640,10 +636,17 @@ inline Lfloat fast_tanh4 (Lfloat x)

inline float InvSqrt(float x)
{
//should change the type-punned pointers to use unions, but I tried it and didn't get it working-JS
Lfloat xhalf = 0.5f*x;

int i = *(int*)&x; // get bits for floating value
i = 0x5f3759df - (i>>1); // gives initial guess y0
x = *(Lfloat*)&i; // convert bits back to float
//union unholy_t unholy;
//unholy.i = x;
//unholy.i = 0x5f3759df - (unholy.i>>1); // gives initial guess y0

x = *(Lfloat*)&i; // convert bits back to float
// x = unholy.f;

x = x*(1.5f-xhalf*x*x); // Newton step, repeating increases accuracy
return x;
}
Expand Down Expand Up @@ -699,23 +702,20 @@ inline Lfloat fastSine(Lfloat x)
inline Lfloat LEAF_poly_blep(Lfloat t, Lfloat dt)
{
dt = fabsf(dt);
if (dt >= 0.0f)
{
// 0 <= t < 1
if (t < dt)
{
t /= dt;
return t+t - t*t - 1.0f;
}
// -1 < t < 0
else if (t > 1.0f - dt)
{
t = (t - 1.0f) / dt;
return t*t + t+t + 1.0f;
}
// 0 otherwise
else return 0.0f;
}
// 0 <= t < 1
if (t < dt)
{
t /= dt;
return t+t - t*t - 1.0f;
}
// -1 < t < 0
else if (t > 1.0f - dt)
{
t = (t - 1.0f) / dt;
return t*t + t+t + 1.0f;
}
// 0 otherwise
else return 0.0f;

//this version is from this discussion: https://dsp.stackexchange.com/questions/54790/polyblamp-anti-aliasing-in-c
// dt = -1.0f*dt;
Expand Down
8 changes: 3 additions & 5 deletions leaf/Src/leaf-dynamics.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ void tCompressor_free (tCompressor* const comp)
mpool_free((char*)c, c->mempool);
}

Lfloat tCompressor_tick(tCompressor* const comp, Lfloat in)
Lfloat tCompressor_tick(tCompressor* const comp, Lfloat in)
{
_tCompressor* c = *comp;

Expand Down Expand Up @@ -144,8 +144,7 @@ Lfloat tCompressor_tickWithTable(tCompressor* const comp, Lfloat in)

Lfloat slope, overshoot;

in = fastabsf(in);
int inAmpIndex = LEAF_clip (0, (in * c->atodbScalar) - c->atodbOffset, c->atodbTableSizeMinus1);
int inAmpIndex = LEAF_clip (0, (fastabsf(in) * c->atodbScalar) - c->atodbOffset, c->atodbTableSizeMinus1);
Lfloat in_db = c->atodbTable[inAmpIndex];
Lfloat out_db = 0.0f;

Expand Down Expand Up @@ -192,8 +191,7 @@ Lfloat tCompressor_tickWithTableHardKnee(tCompressor* const comp, Lfloat in)

Lfloat slope, overshoot;

in = fastabsf(in);
int inAmpIndex = LEAF_clip (0, (in * c->atodbScalar) - c->atodbOffset, c->atodbTableSizeMinus1);
int inAmpIndex = LEAF_clip (0, (fastabsf(in) * c->atodbScalar) - c->atodbOffset, c->atodbTableSizeMinus1);
Lfloat in_db = c->atodbTable[inAmpIndex];
Lfloat out_db = 0.0f;

Expand Down
2 changes: 0 additions & 2 deletions leaf/Src/leaf-instruments.c
Original file line number Diff line number Diff line change
Expand Up @@ -459,8 +459,6 @@ void t808Snare_setNoiseFilterQ(t808Snare* const snareInst, Lfloat noiseFilterQ)
tSVF_setQ(&snare->noiseLowpass, noiseFilterQ);
}

static Lfloat tone[2];

Lfloat t808Snare_tick(t808Snare* const snareInst)
{
_t808Snare* snare = *snareInst;
Expand Down

0 comments on commit e8ee875

Please sign in to comment.