DSPRelated.com
Forums

Sinewave generation (and log, triangle, etc.)

Started by jcarlosmor May 24, 2005
Hi to everybody in this forum.
I am programming some audio effects algorithms on the 21065L. Some of
them like chorus and flanger require a LFO with variable amplitude and
frequency. I was planning to use the most simple way to generate a
waveform -a wavetable as a circular buffer- but since I want to vary
the frequency from 0.1 Hz to 16 Hz in 0.1 Hz increments, it would be
impractical to assing all those individual wavetables for each possible
frequency with a decent resolution. So I would like to know of some
other method to generate waveforms (maybe based in the math properties
of the waveform). I will be using assembler only, so it should not use
math.c functions or libraries. Thank you very much for any information.


Look up DDS on the internet. You will wind up with one sine table
and step through it at different intervals. You can also have a
fractional step size if you want to get real fancy.

At 09:27 AM 5/24/2005, jcarlosmor wrote:
>Hi to everybody in this forum.
>I am programming some audio effects algorithms on the 21065L. Some of
>them like chorus and flanger require a LFO with variable amplitude and
>frequency. I was planning to use the most simple way to generate a
>waveform -a wavetable as a circular buffer- but since I want to vary
>the frequency from 0.1 Hz to 16 Hz in 0.1 Hz increments, it would be
>impractical to assing all those individual wavetables for each possible
>frequency with a decent resolution. So I would like to know of some
>other method to generate waveforms (maybe based in the math properties
>of the waveform). I will be using assembler only, so it should not use
>math.c functions or libraries. Thank you very much for any information.

Steve Holle
Link Communications, Inc.
1035 Cerise Rd.
Billings, MT 59101
sholle@shol...


On Tue, 24 May 2005, Steve Holle wrote:

> Look up DDS on the internet. You will wind up with one sine table
> and step through it at different intervals. You can also have a
> fractional step size if you want to get real fancy.
>
> At 09:27 AM 5/24/2005, jcarlosmor wrote:
> >Hi to everybody in this forum.
> >I am programming some audio effects algorithms on the 21065L. Some of
> >them like chorus and flanger require a LFO with variable amplitude and
> >frequency. I was planning to use the most simple way to generate a
> >waveform -a wavetable as a circular buffer- but since I want to vary
> >the frequency from 0.1 Hz to 16 Hz in 0.1 Hz increments, it would be
> >impractical to assing all those individual wavetables for each possible
> >frequency with a decent resolution. So I would like to know of some
> >other method to generate waveforms (maybe based in the math properties
> >of the waveform). I will be using assembler only, so it should not use
> >math.c functions or libraries. Thank you very much for any information.


It's pretty easy. You set up a table with sin(2pi/N * j) for j=0 to N-1
and then compute a look up into the table based on some phase increment.
If N is a power of 2 life is easy, you can have N bits ahead of the binary
point and 32-N or 48-N bits after the binary point to track your phase.
That's the fractional step size. Your algorithm is just

new phase = old phase + phase increment

output = lookup sine (phase >> 32-N) (assuming 32 bit accumulator for
phase, it can be anything you like).

Patience, persistence, truth,
Dr. mike


Others have already addressed how to do a variable frequency sine wave with a
single table. For an LFO application where you are just using the sine to
modulate some other parameter, the spectral purity of the sinewave isn't very
important, i.e. it doesn't have to be perfect. This means you can get away
with a smaller look-up table.

For a triangle wave, they are easy to make with a simple formula. Just think
about what the waveform looks like: it increases linearly until it hits the
maximum value, then decreases linearly. So you just add a constant value to an
accumulator, and when it hits maximum or minimum, invert the value the value
you are adding. If you really need to be efficient, you can create a sawtooth
waveform (which is simpler because it just increments until it wraps again),
then take the sawtooth to get a triangle. Then if necessary shift the triangle
so it is centered around zero and scale to whatever ampltitude you need.

--- jcarlosmor <jcarlosmor@jcar...> wrote:
> Hi to everybody in this forum.
> I am programming some audio effects algorithms on the 21065L. Some of
> them like chorus and flanger require a LFO with variable amplitude and
> frequency. I was planning to use the most simple way to generate a
> waveform -a wavetable as a circular buffer- but since I want to vary
> the frequency from 0.1 Hz to 16 Hz in 0.1 Hz increments, it would be
> impractical to assing all those individual wavetables for each possible
> frequency with a decent resolution. So I would like to know of some
> other method to generate waveforms (maybe based in the math properties
> of the waveform). I will be using assembler only, so it should not use
> math.c functions or libraries. Thank you very much for any information.
__________________________________