0.012% error ~= -78dB to put it in respect with other audio stuff, which in most cases should be more than low enough. For reference the dynamic range of 16bit audio is around 90dB
0.012% error ~= -78dB to put it in respect with other audio stuff, which in most cases should be more than low enough. For reference the dynamic range of 16bit audio is around 90dB
I did my error calculations by brute forcing the whole 16-bit range, basically:
for i in (i16::MIN..=i16::MAX) {
let a = (i as f32).sin() as i16;
let b = lut_sin(i);
let diff = abs_diff(a, b);
}
Which found the largest difference to be 4, and I got 0.012% from (4/32768).https://hackaday.io/project/28597-the-delta-flyer/log/145736...
If you use a lookup table then you're approximating a sine as a bunch of piecewise linear segments with surprisingly little error, and linear interpolation works well on those. You don't have any harmonics to worry about and the curve is incredibly smooth, so there are no odd effects to take into account.
A while ago I wrote some Python code to demonstrate this effect in calculating frequency from pitch in synthesizers by interpolating a table of semitone steps. The error was negligible up to around C6, which is the top key of most 5-octave keyboards, and only a handful of Hz at C8 which is higher than most folk need. I can't find the code now but when I do I'll post it.