[sdiy] Approximating sine with plain integer math

Andrew Simper andy at cytomic.com
Thu Apr 7 11:19:39 CEST 2016


On 7 April 2016 at 15:47, Olivier Gillet <ol.gillet at gmail.com> wrote:
>> I dug up the following code, but it's not from a shipping product, and I'm
>> not sure I remember how it works.
>
>
> This is the "modified coupled form" algorithm, sometimes called "magic
> circle algorithm":
>
> https://ccrma.stanford.edu/~jos/pdf/GordonAndSmith86.pdf
>
> It works fairly well in fixed point too - the rounding errors manifest
> themselves as a small DC offset, rather than as a loss of amplitude.
>
> Unlike a direct form, second order filter (the recurrence y = 2 * coeff * y_
> - y__), this algorithm handles coefficient changes pretty well - actually,
> any value of the sinZ and cosZ variable correspond to a valid state of the
> filter.
>
> And you can get away with the sinf in the constructor (or in your buffer
> filling routine if you allow FM) because an appropriate polynomial
> approximation of degree 3 of sinf would introduce only a few cents of tuning
> error in the high frequencies.
>
> _______________________________________________
> Synth-diy mailing list
> Synth-diy at dropmix.xs4all.nl
> http://dropmix.xs4all.nl/mailman/listinfo/synth-diy
>

The most numerically stable form of the SVF I know of is this one:

http://www.cytomic.com/files/dsp/SvfLinearTrapezoidalSin.pdf

Which works well in fixed point. You can initialise the state
variables ic1eq and ic2eq to sin and cos (or possibly cos and sin - I
can't remember which!) of the starting phase you want, then not feed
any input to the system for the quadrature oscillator. It's not so
good if you want to update the rate of the oscillator since it
requires a sin(x) and sin(2*x), so for FM you may as well just have a
good sin approximation to begin with, but it is good if you want a set
and forget LFO / oscillator.

Cheers,

Andrew



More information about the Synth-diy mailing list