[sdiy] OT - Linear interpolation in C

Tom Wiltshire tom at electricdruid.net
Sun Jan 30 19:36:18 CET 2011


On 30 Jan 2011, at 18:18, Olivier Gillet wrote:

>> /* arranged to have only one multiply and two adds */
>> interp = this + index * ((next - this) >> 8);
> 
> Does this trick works well on the dspic?

No, not really. At least, not in assembly.

The dsPIC has a one-cycle multiply, so there's no advantage to the 1-multiply-2-adds form of interpolation over the 2-multiplies-1-add form. I prefer the second form since there is also a one-cycle MAC (Multiply and ACcumulate) so you get the add for free.

I have occasionally used the first form, but only if I've precomputed the (next-this) values and stored them in the table too. Having the Delta value precomputed can sometimes save you a few cycles.
Mostly I've only found it worthwhile when trying to do interpolation between 32-bit values. In that case, you can sometimes get away with using a (quick) 16-bit multiply if the (next-this) delta value doesn't go over 16-bit, or can be downshifted to fit into 16-bit without a painful loss of accuracy. I've done this sometimes on frequency increment tables.

T.





More information about the Synth-diy mailing list