How to create a sound at specific frequency?

J

johnb41

Does anyone know how can i create a sound in vb.net that will be a
specific frequency? I can't find anything online that helps.

Thanks very much for your help!

John
 
G

Guest

Does anyone know how can i create a sound in vb.net that will be a
specific frequency? I can't find anything online that helps.

' Beep (winbase.h) plays a sound in hertz for a duration in milliseconds
' This function is named BeepApi because Beep is a vb reserved word
Public Declare Function BeepApi Lib "kernel32" Alias "Beep" ( _
ByVal dwFreq As Integer, _
ByVal dwDuration As Integer) _
As Integer
 
C

Chris Dunaway

AMercer said:
Public Declare Function BeepApi Lib "kernel32" Alias "Beep" ( _
ByVal dwFreq As Integer, _
ByVal dwDuration As Integer) _
As Integer

And if you don't want to use p/invoke you can use:

System.Console.Beep(_frequency, _duration)
 
J

johnb41

Thank you for your replies. I tried that earlier. The problem with
this method is that the beep is sounded via the internal PC speaker,
not the external speakers, and the quality is very bad.

Does anyone know how to get the sound to come out of the external
speakers?

Thanks!
John
 
C

Chris Dunaway

johnb41 said:
Does anyone know how to get the sound to come out of the external
speakers?

You mean through the sound card?

If you're using .Net 2.0, you can import the System.Media namespace and
then call:

SystemSounds.Beep.Play()

What is played depends on the sound scheme setup in the control panel.
 
G

Guest

Thank you for your replies. I tried that earlier. The problem with
this method is that the beep is sounded via the internal PC speaker,
not the external speakers, and the quality is very bad.

Does anyone know how to get the sound to come out of the external
speakers?

At web site

http://ccrma.stanford.edu/CCRMA/Courses/422/projects/WaveFormat/

is a description of the layout of a .wav file. You could generate such a
structure with digitized sinusoid values in the 'data' area, and feed that
data to

Private Declare Function PlaySound Lib "winmm" Alias "PlaySoundA" ( _
ByVal pszSound() As Byte, _
ByVal hMod As Integer, _
ByVal fdwSound As Integer) _
As Integer

Use 0 for hMod, and use &h4 for fdwSound (constant SND_MEMORY). Pass the
wave array you build in pszSound.

Sounds like some effort, but it should work.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top