[sdiy] Approximating sine with plain integer math
Richie Burnett
rburnett at richieburnett.co.uk
Thu Apr 7 21:29:09 CEST 2016
Tom wrote:
> Could someone tell me what's the advantage of these numerical approaches
> over a simple table look-up?
Numerical sinewave calculation can be faster on a lot of platforms. For
instance, on a dsPIC there are wait-states when you access ROM via Program
Space Visibility or table read instructions. The same thing can happen on
other platforms where external memory has wait states. Sure you can copy
LUTs into RAM for faster access during interpolation but "fast memory" is a
limited resource.
Routines like the magic circle algorithm (state-variable filter) also
produce a *very* pure sinewave for only a couple of instructions. You still
need quite a large sinewave LUT to get comparable performance using linear
interpolation, or else go to higher order interpolation to get comparable
THD.
> About the waveshaping approach suggested by John: doesn't it introduce
> aliasing at high frequencies?
No. This is an instance of wave-shaping removing harmonics from a waveform
rather than adding them.
> What happens to the shape of the output if the input sawtooth is
> band-limited?
You get a messed up sinewave with ripples in it! You have to start with the
naive ramp straight out of the phase accumulator and then manipulate it to
approximate your sinewave.
Olivier, have you read about the DPW differentiated-parabolic-wave method of
synthesising analogue waveforms with reduced aliasing? The sine-like
waveform that the OP is generating has a 18dB spectral tilt so can play
quite high in pitch before you get much energy aliasing. You can then
differentiate this to get a "reduced-aliasing" triangle wave, and
differentiate again to get a nice reduced-aliasing square wave. His
waveform is really just the first step of the DPW method.
I hope that explanation helps,
-Richie,
More information about the Synth-diy
mailing list