History

got rid of extra divide in ramp

spiricom committed 6 years ago

Commit fe679cd1 parent f257cc43 files · +24 −19Browse files

Unified · Split

3 files
  1. LEAF/.DS_Store +0 −0
  2. LEAF/Inc/leaf-envelopes.h +1 −0
  3. LEAF/Src/leaf-envelopes.c +24 −20
LEAF/.DS_Store+0−0

Binary file not shown.

LEAF/Inc/leaf-envelopes.h+1−0
@@ -144,6 +144,7 @@ extern "C" { · 143 unmodified lines
144 float minimum_time;144 float minimum_time;
145 float curr,dest;145 float curr,dest;
146 float time;146 float time;
147 float factor;
147 int samples_per_tick;148 int samples_per_tick;
148 149
149 } _tRamp;150 } _tRamp;
LEAF/Src/leaf-envelopes.c+24−20
@@ -533,7 +533,7 @@ void tRamp_init(tRamp* const r, float time, int samples_per_tick) · 532 unmodified lines
533 _tRamp* ramp = *r = (_tRamp*) leaf_alloc(sizeof(_tRamp));533 _tRamp* ramp = *r = (_tRamp*) leaf_alloc(sizeof(_tRamp));
534 534
535 ramp->inv_sr_ms = 1.0f/(leaf.sampleRate*0.001f);535 ramp->inv_sr_ms = 1.0f/(leaf.sampleRate*0.001f);
536 ramp->minimum_time = ramp->inv_sr_ms * samples_per_tick;536 ramp->minimum_time = ramp->inv_sr_ms * samples_per_tick;
537 ramp->curr = 0.0f;537 ramp->curr = 0.0f;
538 ramp->dest = 0.0f;538 ramp->dest = 0.0f;
539 539
@@ -545,7 +545,7 @@ void tRamp_init(tRamp* const r, float time, int samples_per_tick) · 5 unmodified lines
545 {545 {
546 ramp->time = time;546 ramp->time = time;
547 }547 }
548 548 ramp->factor = (1.0f / ramp->time) * ramp->inv_sr_ms;
549 ramp->samples_per_tick = samples_per_tick;549 ramp->samples_per_tick = samples_per_tick;
550 ramp->inc = ((ramp->dest - ramp->curr) / ramp->time * ramp->inv_sr_ms) * (float)ramp->samples_per_tick;550 ramp->inc = ((ramp->dest - ramp->curr) / ramp->time * ramp->inv_sr_ms) * (float)ramp->samples_per_tick;
551}551}
@@ -575,9 +575,9 @@ void tRamp_initToPool (tRamp* const r, float time, int samples_per_tick, t · 23 unmodified lines
575 {575 {
576 ramp->time = time;576 ramp->time = time;
577 }577 }
578
579 ramp->samples_per_tick = samples_per_tick;578 ramp->samples_per_tick = samples_per_tick;
580 ramp->inc = ((ramp->dest - ramp->curr) / ramp->time * ramp->inv_sr_ms) * (float)ramp->samples_per_tick;579 ramp->factor = (1.0f / ramp->time) * ramp->inv_sr_ms * (float)ramp->samples_per_tick;
580 ramp->inc = (ramp->dest - ramp->curr) * ramp->factor;
581}581}
582 582
583void tRamp_freeFromPool (tRamp* const r, tMempool* const mp)583void tRamp_freeFromPool (tRamp* const r, tMempool* const mp)
@@ -592,29 +592,31 @@ void tRamp_setTime(tRamp* const ramp, float time) · 8 unmodified lines
592{592{
593 _tRamp* r = *ramp;593 _tRamp* r = *ramp;
594 594
595 if (time < r->minimum_time)595 if (time < r->minimum_time)
596 {596 {
597 r->time = r->minimum_time;597 r->time = r->minimum_time;
598 }598 }
599 else599 else
600 {600 {
601 r->time = time;601 r->time = time;
602 }602 }
603 r->inc = ((r->dest-r->curr)/r->time * r->inv_sr_ms) * ((float)r->samples_per_tick);603 r->factor = (1.0f / r->time) * r->inv_sr_ms * (float)r->samples_per_tick;
604 r->inc = (r->dest - r->curr) * r->factor;
605
604}606}
605 607
606void tRamp_setDest(tRamp* const ramp, float dest)608void tRamp_setDest(tRamp* const ramp, float dest)
607{609{
608 _tRamp* r = *ramp;610 _tRamp* r = *ramp;
609 r->dest = dest;611 r->dest = dest;
610 r->inc = ((r->dest-r->curr)/r->time * r->inv_sr_ms) * ((float)r->samples_per_tick);612 r->inc = (r->dest - r->curr) * r->factor;
611}613}
612 614
613void tRamp_setVal(tRamp* const ramp, float val)615void tRamp_setVal(tRamp* const ramp, float val)
614{616{
615 _tRamp* r = *ramp;617 _tRamp* r = *ramp;
616 r->curr = val;618 r->curr = val;
617 r->inc = ((r->dest-r->curr)/r->time * r->inv_sr_ms) * ((float)r->samples_per_tick);619 r->inc = (r->dest - r->curr) * r->factor;
618}620}
619 621
620float tRamp_tick(tRamp* const ramp)622float tRamp_tick(tRamp* const ramp)
@@ -624,10 +626,10 @@ float tRamp_tick(tRamp* const ramp) · 3 unmodified lines
624 r->curr += r->inc;626 r->curr += r->inc;
625 627
626 if (((r->curr >= r->dest) && (r->inc > 0.0f)) || ((r->curr <= r->dest) && (r->inc < 0.0f)))628 if (((r->curr >= r->dest) && (r->inc > 0.0f)) || ((r->curr <= r->dest) && (r->inc < 0.0f)))
627 {629 {
628 r->inc = 0.0f;630 r->inc = 0.0f;
629 r->curr=r->dest;631 r->curr=r->dest;
630 }632 }
631 633
632 return r->curr;634 return r->curr;
633}635}
@@ -642,11 +644,13 @@ void tRampSampleRateChanged(tRamp* const ramp) · 8 unmodified lines
642{644{
643 _tRamp* r = *ramp;645 _tRamp* r = *ramp;
644 r->inv_sr_ms = 1.0f / (leaf.sampleRate * 0.001f);646 r->inv_sr_ms = 1.0f / (leaf.sampleRate * 0.001f);
645 r->inc = ((r->dest-r->curr)/r->time * r->inv_sr_ms)*((float)r->samples_per_tick);647 r->factor = (1.0f / r->time) * r->inv_sr_ms * (float)r->samples_per_tick;
648 r->inc = (r->dest - r->curr) * r->factor;
646}649}
647 650
648 651
649 652
653
650/* RampUpDown */654/* RampUpDown */
651void tRampUpDown_init(tRampUpDown* const r, float upTime, float downTime, int samples_per_tick)655void tRampUpDown_init(tRampUpDown* const r, float upTime, float downTime, int samples_per_tick)
652{656{

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t