Re: DirectSound example sought
From: Bob Masta (NoSpam_at_daqarta.com)
Date: 09/20/04
- Next message: Ehsan Sadeghi: "Re: Reading a Text"
- Previous message: Chris P. [MVP]: "Re: Reading a Text"
- In reply to: Joseph M. Newcomer: "Re: DirectSound example sought"
- Messages sorted by: [ date ] [ thread ]
Date: Mon, 20 Sep 2004 13:10:57 GMT
On Tue, 14 Sep 2004 21:35:35 -0400, Joseph M. Newcomer
<newcomer@flounder.com> wrote:
<SNIP>
>There was a reference to using
>complex arithmetic to avoid doing sin/cos on each waveform, but I'm too far out from my
>complex analysis course (1966-1967) to remember how this is done. Any good pointers?
An even easier and faster way to generate sine waves is via table
look-up. You generate a full-cycle circular sine wave table once when
your program starts, maybe 8K or 16K values. Then to generate a sine
wave of any frequency, you step around the table with a step size
proportional to the frequency and inversely to sample rate. (Steps
will always be less than half the table size to avoid aliasing.) You
basically just compute the step size whenever the frequency changes
and then add that amount to an index to get the table entry for each
sample. Make the table a power-of-2 size so you can mask the index
to keep it in the table.
Same method works for FM by adding an extra modulation step size
onto the carrier step size as above.
The table look-up is very fast. If you want more precision than
provided by the basic table size, you can do a linear interpolation
on the table. This is still very fast compared to complex math.
Linear interpolation works well at these 8-16K table sizes, and you
can easily get decent 16-bit resolution.
This basic scheme is what is used in commerical DDS (Direct
Digital Synthesis) signal generators. You are not confined to
sine tables, and in fact you can use an arbitrary waveform. This
gives variable frequency on any waveform, at no extra cost.
Hope this helps!
Bob Masta
dqatechATdaqartaDOTcom
D A Q A R T A
Data AcQuisition And Real-Time Analysis
www.daqarta.com
- Next message: Ehsan Sadeghi: "Re: Reading a Text"
- Previous message: Chris P. [MVP]: "Re: Reading a Text"
- In reply to: Joseph M. Newcomer: "Re: DirectSound example sought"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|