Cheap pseudo-sinusoidal lfo

notes
Although the code is written in standard C++, this algorithm is really better suited for
dsps where one can take advantage of multiply-accumulate instructions and where the
required phase accumulator can be easily implemented by masking a counter.

It provides a pretty cheap roughly sinusoidal waveform that is good enough for an lfo.
code
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
// x should be between -1.0 and 1.0
inline
double pseudo_sine(double x)
{
    // Compute 2*(x^2-1.0)^2-1.0
    x *= x;
    x -= 1.0;
    x *= x;
    // The following lines modify the range to lie between -1.0 and 1.0.
   // If a range of between 0.0 and 1.0 is acceptable or preferable
   // (as in a modulated delay line) then you can save some cycles.
    x *= 2.0;
    x -= 1.0;
}

Comments

You forgot a

return x;
Doh! You're right.

-Frederick