Tone generation

  • Thread starter Thread starter Jan Kowalski
  • Start date Start date
Jan Kowalski said:
Does someon know how to generate a sinusoidal tone?

Use Platform/Invoke to call Beep():

[DllImport("kernel32.dll")]
public static extern bool Beep(int frequency, int duration);

Regards,
Will
 
Jan Kowalski said:
Does someon know how to generate a sinusoidal tone?

Use Platform/Invoke to call Beep():

[DllImport("kernel32.dll")]
public static extern bool Beep(int frequency, int duration);

Regards,
Will

Will, this won't!

1) This method only plays through the PC's speaker,
and
2) It is NOT a sine wave. It is a distorted square wave.

There are several ways to generate a pure sine wave, none of them use
the framework directly.

The 'easiest' is to record the sine wave that you want to a file, then
play that file.
Look in VS Help under "play sound" for an example.
Or you could use DirectX, or even Midi.
None of these are simple.

Do you need to be able to select the exact frequency and duration on
an extempore basis?
 
Michael Gray said:
2) It is NOT a sine wave. It is a distorted square wave.

I didn't know that, thanks for the correction.
The 'easiest' is to record the sine wave that you want to a file, then
play that file.

The wave file format is pretty simple and the mmio... functions are easy to
use so with a little math it shouldn't be hard to create a file on the fly
and loop the playback, no?

Regards,
Will
 
I didn't know that, thanks for the correction.


The wave file format is pretty simple and the mmio... functions are easy to
use so with a little math it shouldn't be hard to create a file on the fly
and loop the playback, no?

Regards,
Will

For a programmer with a math and computing degree it would be a
peice-of-cake.
Otherwise, I'm not so sure.
In any case, if you are going to the trouble of creating a file, with
the attendant problems of getting the headers etc right, it is much
easier to directly put those numbers into a DirectSound PCM buffer,
and output using DirectSound.
Even this is not simple.

If the frequency of the sound is set to one or two, then generate a
wav file or two using say Cooledit, then play with mmio, or
directsound.

If the frequency needs to be extempore, then you will need to do
something else.

As an example that may be used as a basis for experimentation:
http://www.codeproject.com/audio/SoundGenerator.asp

Michael Gray, BSc, (Math Sci, Computing Sci) MACS, MRSA
 
Michael Gray said:
For a programmer with a math and computing degree it would be a
peice-of-cake.

Well, the OP did use the word "sinusoidal" which means he most likely made
it through basic trigonometry at least. :-)

Regards,
Will
 
Well, the OP did use the word "sinusoidal" which means he most likely made
it through basic trigonometry at least. :-)

Regards,
Will

Quite!
Perhap the OP misread the label on a bottle of nasal decongestant?
;-)
 
Back
Top