I’m playing around with Direct digital synthesis wavetables on an Atmega328.
Given an 8-bit fractional value F, and two 8-bit values A, B, what would be the most efficient way to calculate the linear interpolated value between A and B? I can think of two methods:
Alternative 1:
Interpolated value = ((A << 8) + (B - A) * F) >> 8
(Will only work when B >= A, but I could wrap it in an if/else and swap A and B if A > B)
Alternative 2:
Interpolated value = A + (B - A) * (F / 256)
Does it even matter which one I choose or would the compiler optimize them identically anyway?
Is there an even better method that involves no multiplication or division?
EDIT: Changed denominator in alternative 2
from 255
to 256