ref: fe679cd98d991aa2a306a4147d8e41c97e909702
parent: f257cc4a97aa54f74305cc2ff3115134a0294318
author: spiricom <jeff@snyderphonics.com>
date: Sat May 9 18:25:31 EDT 2020
got rid of extra divide in ramp
binary files a/LEAF/.DS_Store b/LEAF/.DS_Store differ
--- a/LEAF/Inc/leaf-envelopes.h
+++ b/LEAF/Inc/leaf-envelopes.h
@@ -144,6 +144,7 @@
float minimum_time;
float curr,dest;
float time;
+ float factor;
int samples_per_tick;
} _tRamp;
--- a/LEAF/Src/leaf-envelopes.c
+++ b/LEAF/Src/leaf-envelopes.c
@@ -533,7 +533,7 @@
_tRamp* ramp = *r = (_tRamp*) leaf_alloc(sizeof(_tRamp));
ramp->inv_sr_ms = 1.0f/(leaf.sampleRate*0.001f);
- ramp->minimum_time = ramp->inv_sr_ms * samples_per_tick;
+ ramp->minimum_time = ramp->inv_sr_ms * samples_per_tick;
ramp->curr = 0.0f;
ramp->dest = 0.0f;
@@ -545,7 +545,7 @@
{
ramp->time = time;
}
-
+ ramp->factor = (1.0f / ramp->time) * ramp->inv_sr_ms;
ramp->samples_per_tick = samples_per_tick;
ramp->inc = ((ramp->dest - ramp->curr) / ramp->time * ramp->inv_sr_ms) * (float)ramp->samples_per_tick;
}
@@ -575,9 +575,9 @@
{
ramp->time = time;
}
-
ramp->samples_per_tick = samples_per_tick;
- ramp->inc = ((ramp->dest - ramp->curr) / ramp->time * ramp->inv_sr_ms) * (float)ramp->samples_per_tick;
+ ramp->factor = (1.0f / ramp->time) * ramp->inv_sr_ms * (float)ramp->samples_per_tick;
+ ramp->inc = (ramp->dest - ramp->curr) * ramp->factor;
}
void tRamp_freeFromPool (tRamp* const r, tMempool* const mp)
@@ -592,15 +592,17 @@
{
_tRamp* r = *ramp;
- if (time < r->minimum_time)
- {
- r->time = r->minimum_time;
- }
- else
- {
- r->time = time;
- }
- r->inc = ((r->dest-r->curr)/r->time * r->inv_sr_ms) * ((float)r->samples_per_tick);
+ 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;
+
}
void tRamp_setDest(tRamp* const ramp, float dest)
@@ -607,7 +609,7 @@
{
_tRamp* r = *ramp;
r->dest = dest;
- r->inc = ((r->dest-r->curr)/r->time * r->inv_sr_ms) * ((float)r->samples_per_tick);
+ r->inc = (r->dest - r->curr) * r->factor;
}
void tRamp_setVal(tRamp* const ramp, float val)
@@ -614,7 +616,7 @@
{
_tRamp* r = *ramp;
r->curr = val;
- r->inc = ((r->dest-r->curr)/r->time * r->inv_sr_ms) * ((float)r->samples_per_tick);
+ r->inc = (r->dest - r->curr) * r->factor;
}
float tRamp_tick(tRamp* const ramp)
@@ -624,10 +626,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;
}
@@ -642,8 +644,10 @@
{
_tRamp* r = *ramp;
r->inv_sr_ms = 1.0f / (leaf.sampleRate * 0.001f);
- r->inc = ((r->dest-r->curr)/r->time * r->inv_sr_ms)*((float)r->samples_per_tick);
+ r->factor = (1.0f / r->time) * r->inv_sr_ms * (float)r->samples_per_tick;
+ r->inc = (r->dest - r->curr) * r->factor;
}
+