PDA

Click to See Complete Forum and Search --> : Frequency Generator


pskyboy
Mar 16th, 2002, 04:20 PM
Hey guys

I want to create a simple program to generate a sound frequency to play through my speakers. I would ideally like to be able to be able to generate a different frequency in each speaker ie 3Khz in right speaker and 3Khz in left speaker. So my question is what is teh easiest and fastest way of doign this.

Peter

parksie
Mar 16th, 2002, 04:24 PM
3khz and 3khz are the same, just thought I'd mention that ;)

First, you need to decide what waveform you're going to use - you can have sine (i.e. use sin() to calculate the amplitude), square (jump between the maximum and minimum values after waiting a certain period, for example 10ms, at each value.

Then there's sawtooth where you cycle from minimum to maximum then drop, and triangle which is linear up/down (like sine, but sharp at each end and always straight lines).

Right, that's the waveforms out of the way...

If you look up the wave* functions in MSDN you'll find how to create and play a sound buffer. From there it's a simple matter of generating the contents (note, once you've created the waveform buffer it's easy because you just keep cycling the same buffer :D).

pskyboy
Mar 16th, 2002, 04:27 PM
Cheers

I ment 3Khz and 5khz, something dirrerent to each speaker basically is this possible in teh same way.

Peter

parksie
Mar 16th, 2002, 04:28 PM
Yes. You just need to calculate different values for each channel, but it's still the same functions to play it.