Linear Interpolation method for hop steps
Posted: Thu Mar 10, 2022 9:45 pm
Here's something I devised sometime last year, it's probably not remotely original. I bumped ito it again the other day and had a "how on earth does this work / what on earth was I thinking??" moment! But I reckon it's quite neat so thought I'd pass it on, might be useful ...
It relates to interpolating DSP processess that have suffered from being hopped, for example envelope generators. Whenever you use 'hop' in DSP code it inevitably generates steps in your output shape - bigger the hop, bigger the steps. Sometimes this doesn't matter, but if it does you can use slewing or interpolating techniques, after the hopped setction, to smooth it out again.
Attached is a very low-cpu-cost method of producing a truly straight-line (linear) interpolation between the steps.
In the attached I've tagged on the more traditional slew-rate-limiter method as well, which you can switch to for comparison. The slew-rate-limiter method produces characteristic bumps between each step sample, whereas my linear method makes perfect straight lines.
To help you with unravelling it all ... The variable "diff" calculates the difference between consecutive steps (4096 samples between them in this case); divide this difference by the hop size (4096), and a perfect ramp is restored by simply accumulating the 4096 'diff' values, during the remaining 4095 samples between each hop. You can hopefully see that accumulating 4096 * (1/4096) = 1, thus generating an accurate linear ramp between between adjacent steps.
It's very efficient because all the calculations are done inside the 4096 hopped section, and the ramp restoration (back in real time) is achieved using a solitary 'add' : interpOut + diff.
Keeps me off the streets ...
H
It relates to interpolating DSP processess that have suffered from being hopped, for example envelope generators. Whenever you use 'hop' in DSP code it inevitably generates steps in your output shape - bigger the hop, bigger the steps. Sometimes this doesn't matter, but if it does you can use slewing or interpolating techniques, after the hopped setction, to smooth it out again.
Attached is a very low-cpu-cost method of producing a truly straight-line (linear) interpolation between the steps.
In the attached I've tagged on the more traditional slew-rate-limiter method as well, which you can switch to for comparison. The slew-rate-limiter method produces characteristic bumps between each step sample, whereas my linear method makes perfect straight lines.
To help you with unravelling it all ... The variable "diff" calculates the difference between consecutive steps (4096 samples between them in this case); divide this difference by the hop size (4096), and a perfect ramp is restored by simply accumulating the 4096 'diff' values, during the remaining 4095 samples between each hop. You can hopefully see that accumulating 4096 * (1/4096) = 1, thus generating an accurate linear ramp between between adjacent steps.
It's very efficient because all the calculations are done inside the 4096 hopped section, and the ramp restoration (back in real time) is achieved using a solitary 'add' : interpOut + diff.
Keeps me off the streets ...
H