Home All Groups Group Topic Archive Search About

How to create a sound at specific frequency?

Author
20 Jul 2006 7:17 PM
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

Author
20 Jul 2006 9:27 PM
AMercer
> 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
Author
21 Jul 2006 1:26 PM
Chris Dunaway
AMercer wrote:

>     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)
Author
21 Jul 2006 4:34 PM
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



johnb41 wrote:
Show quoteHide quote
> 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
Author
21 Jul 2006 8:21 PM
Chris Dunaway
johnb41 wrote:

> 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.
Author
21 Jul 2006 9:51 PM
AMercer
> 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.