Unified · Split
Binary file not shown.
| @@ -144,6 +144,7 @@ extern "C" { · 143 unmodified lines | ||
| 144 | 144 | float minimum_time; |
| 145 | 145 | float curr,dest; |
| 146 | 146 | float time; |
| 147 | + float factor; | |
| 147 | 148 | int samples_per_tick; |
| 148 | 149 | |
| 149 | 150 | } _tRamp; |
| @@ -533,7 +533,7 @@ void tRamp_init(tRamp* const r, float time, int samples_per_tick) · 532 unmodified lines | ||
| 533 | 533 | _tRamp* ramp = *r = (_tRamp*) leaf_alloc(sizeof(_tRamp)); |
| 534 | 534 | |
| 535 | 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 | 537 | ramp->curr = 0.0f; |
| 538 | 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 | 546 | ramp->time = time; |
| 547 | 547 | } |
| 548 | − | |
| 548 | + ramp->factor = (1.0f / ramp->time) * ramp->inv_sr_ms; | |
| 549 | 549 | ramp->samples_per_tick = samples_per_tick; |
| 550 | 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 | 576 | ramp->time = time; |
| 577 | 577 | } |
| 578 | − | |
| 579 | 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 | |
| 583 | 583 | void 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 | 593 | _tRamp* r = *ramp; |
| 594 | 594 | |
| 595 | − if (time < r->minimum_time) | |
| 596 | − { | |
| 597 | − r->time = r->minimum_time; | |
| 598 | − } | |
| 599 | − else | |
| 600 | − { | |
| 601 | − r->time = time; | |
| 602 | − } | |
| 603 | − r->inc = ((r->dest-r->curr)/r->time * r->inv_sr_ms) * ((float)r->samples_per_tick); | |
| 595 | + if (time < r->minimum_time) | |
| 596 | + { | |
| 597 | + r->time = r->minimum_time; | |
| 598 | + } | |
| 599 | + else | |
| 600 | + { | |
| 601 | + r->time = time; | |
| 602 | + } | |
| 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 | |
| 606 | 608 | void tRamp_setDest(tRamp* const ramp, float dest) |
| 607 | 609 | { |
| 608 | 610 | _tRamp* r = *ramp; |
| 609 | 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 | |
| 613 | 615 | void tRamp_setVal(tRamp* const ramp, float val) |
| 614 | 616 | { |
| 615 | 617 | _tRamp* r = *ramp; |
| 616 | 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 | |
| 620 | 622 | float tRamp_tick(tRamp* const ramp) |
| @@ -624,10 +626,10 @@ float tRamp_tick(tRamp* const ramp) · 3 unmodified lines | ||
| 624 | 626 | r->curr += r->inc; |
| 625 | 627 | |
| 626 | 628 | if (((r->curr >= r->dest) && (r->inc > 0.0f)) || ((r->curr <= r->dest) && (r->inc < 0.0f))) |
| 627 | − { | |
| 628 | − r->inc = 0.0f; | |
| 629 | − r->curr=r->dest; | |
| 630 | − } | |
| 629 | + { | |
| 630 | + r->inc = 0.0f; | |
| 631 | + r->curr=r->dest; | |
| 632 | + } | |
| 631 | 633 | |
| 632 | 634 | return r->curr; |
| 633 | 635 | } |
| @@ -642,11 +644,13 @@ void tRampSampleRateChanged(tRamp* const ramp) · 8 unmodified lines | ||
| 642 | 644 | { |
| 643 | 645 | _tRamp* r = *ramp; |
| 644 | 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 | 654 | /* RampUpDown */ |
| 651 | 655 | void tRampUpDown_init(tRampUpDown* const r, float upTime, float downTime, int samples_per_tick) |
| 652 | 656 | { |