borderAndreaVB free resources for Visual Basic developersborder
borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2014 Andrea Tincaniborder

AndreaVB | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Previous Topic (Image Zoom problem)Next Topic (swf to avi) New Topic New Poll Post Reply
AndreaVB Forum : Multimedia : Sound Frequency Generation? HOW?
Poster Message
astro_girl_690
Level: Trainee

Registered: 04-11-2006
Posts: 3

icon Sound Frequency Generation? HOW?


Sound Frequency Generation? HOW?

Using  VB 4.0, I'd like to be able to create and generate simple musical
tone frequencies and play them in hertz.

Numerical values generated would be translated directly into sound, i.e.

A set of numerical values with decimals are created;

432.987
255.98
727.33

These numbers are used as hertzian values for playback as frequency tones;

432.987 Hertz
255.98 Hertz
727.33 Hertz

and are played over the speaker, or off the sound card, etc...

Trouble is VB 4.0 only allows for simple 'Beeps'. Nothing native to the package
allows for what Im after.

I did find a method for use with VB 3.0 using the 16bit version in the old VB Tips.hlp (shown at end of this email), tried to use it in VB 4.0 ( I'm using the 32 bit version)  and it just plain didn't work, lots of error messages saying something to the effect that it was missing this or that dll or something.

There MUST be away to generate simple, yet specific tone frequencies SOMEHOW in VB   (With out having to pay an arm or a leg for an expensive OCX or DLL )

Can someone point me in the right direction, offer any ideas or code snippets?

Much thanks!

Mwa!  

Astro_gurrrllll  

Here is the code I have tried already that did not work
======================

How to Emulate QuickBasic's SOUND Statement in Visual Basic

Article ID: Q140879

Copyright (c) Microsoft Corporation. All rights reserved.
=================================================================


The information in this article applies to:

- Professional and Enterprise Editions of Microsoft Visual Basic,
  16-bit only, for Windows, version 4.0
---------------------------------------------------------------------

SUMMARY
=======

The SOUND statement found in Microsoft QuickBasic is not implemented
within Microsoft Visual Basic. You can perform sound through a Windows
API call that is equivalent to the QuickBasic SOUND statement.

MORE INFORMATION
================

The QuickBasic version of the SOUND statement can be executed by
calling several Windows 3.0 API function calls. Within Windows, you
must open up a VoiceQueue with the OpenSound call routine. Using the
function SetVoiceSound, place all of the values corresponding to the
desired frequencies and durations. Once the VoiceQueue has the desired
frequencies and durations, you start the process by calling
StartSound. After the sounds have been played, you must free up the

VoiceQueue by calling CloseSound. If you plan on placing a large
amount of information into the VoiceQueue, you may need to resize the
VoiceQueue buffer by calling the SetVoiceQueueSize function.

After executing the StartSound function, you cannot place any more
sound into the VoiceQueue until the VoiceQueue is depleted. Placing
more sound into the queue will overwrite any information that was
previously in the VoiceQueue. If you are going to place sound into the

VoiceQueue after a StartSound statement, you will need to call
WaitSoundState with an argument of one. When WaitSoundState returns
NULL, the VoiceQueue is empty and processing can continue.

Below is an example of using the Windows API function calls, which will
imitate the QuickBasic SOUND statement:

In the general section place the following:

Public Declare Function OpenSound Lib "sound.drv" () As Integer
Public Declare Function VoiceQueueSize Lib "sound.drv"

            (ByVal nVoice%, ByVal nBytes%) As Integer
Public Declare Function SetVoiceSound Lib "sound.drv"
            (ByVal nSource%, ByVal Freq&, ByVal nDuration%) As Integer
Public Declare Function StartSound Lib "sound.drv" () As Integer
Public Declare Function CloseSound Lib "sound.drv" () As Integer
Public Declare Function WaitSoundState Lib "sound.drv" (ByVal State%)
As Integer

NOTE: All Declare statements above each must be placed on one line.

The SetVoiceSound takes two arguments. The first variable, Freq, is a

two WORD parameter. The HIGH WORD will hold the actual frequency in
hertz. The LOW WORD will hold the fractional frequency. The formula, X
* 2 ^ 16, will shift the variable "X" into the HIGH WORD location. The
second variable, Duration%, is the duration in clock ticks. There are
18.2 tick clicks per second on all Intel computers.

The following simplistic example shows how you can place several
frequencies and durations into the VoiceQueue before starting the
sound by calling the StartSound function:

Private Sub Form_Click ()
   Suc% = OpenSound()
   S% = SetVoiceSound(1, 100 * 2 ^ 16, 100)   ' Frequency = 100 hz
   S% = SetVoiceSound(1, 90 * 2 ^ 16, 90)     ' Frequency = 90 hz
   S% = SetVoiceSound(1, 80 * 2 ^ 16, 90)     ' Frequency = 80 hz
   S% = StartSound()
   While (WaitSoundState(1) <> 0): Wend       ' Wait for sound to play.
   Succ% = CloseSound()
End Sub

The following is another simple example, which creates a siren sound:

1. Within the general section, place the following Sound procedure:

Public Sub Sound (ByVal Freq as Long, ByVal Duration%)
   Freq = Freq * 2 ^ 16                 ' Shift frequency to high byte.
   S% = SetVoiceSound(1, Freq, Duration%)
   S% = StartSound()
   While (WaitSoundState(1) <> 0): Wend
End Sub

2. Place the code below into any event procedure. The example below
   uses the Form_Click event procedure. Clicking any position on the
   form will create a police siren.

Private Sub Form_Click ()
   Suc% = OpenSound()
   For j& = 440 To 1000 Step 5

      Call Sound(j&, j& / 100)
   Next j&
   For j& = 1000 To 440 Step -5
      Call Sound(j&, j& / 100)
   Next j&
   Succ% = CloseSound()
End Sub

REFERENCES
==========

"Programming Windows: the Microsoft Guide to Writing Applications for
Windows 3," Charles Petzold, Microsoft Press, 1990

"Microsoft Windows Software Development Kit: Reference Volume 1,"
version 3.0

WINSDK.HLP file shipped with Microsoft Windows 3.0 Software
Development Kit

All of these references are available in the MSDN/VB Starter Kit

provided with the Professional and Enterprise Editions of Visual
Basic 4.0.

Additional reference words: 1.00 2.00 3.00 4.00 vb4win vb416
KBCategory: kbprg kbcode
KBSubcategory: APrgOther

Copyright (c) Microsoft Corporation. All rights reserved.

08-03-2007 at 05:00 AM
View Profile Send Email to User Show All Posts | Quote Reply
gobnait
Level: Trainee

Registered: 13-12-2012
Posts: 1
icon Re: Sound Frequency Generation? HOW?

Can anyone came across of this situation before What are all the components to be included and the neccesary things for the above task.I would like to tell you more about my questions in precise way.



a+ training course a+ training course
comptia a+ study guide course comptia a+ study guide course
what is a+ certification course what is a+ certification course


[Edited by gobnait on 18-01-2013 at 06:12 AM GMT]

[Edited by gobnait on 18-01-2013 at 06:13 AM GMT]

13-12-2012 at 10:22 AM
View Profile Send Email to User Show All Posts | Quote Reply
AndreaVB Forum : Multimedia : Sound Frequency Generation? HOW?
Previous Topic (Image Zoom problem)Next Topic (swf to avi) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
borderAndreaVB free resources for Visual Basic developersborder
borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2014 Andrea Tincaniborder