Futurebasic/Language/Reference/sound frequency

SOUND <frequency> edit

Syntax edit

SOUND pitch,duration [,[volume][,async]]

Description edit

This statement plays a tone of the given pitch, duration and volume.

The pitch is expressed as a frequency in cycles per second. The frequency that you specify is converted to the nearest "MIDI note value," which determines the actual note that's played. Middle "C" corresponds to a frequency of 261.625.

The duration is expressed in ticks, and can range from 0 to 32,767. However, the toolbox sound commands require FB to translate the ticks into an integer to represent half-milliseconds. This means you can play a note that is no longer than 32.8 seconds.

The volume can range from 0 through 127. Specifying 0 will result in silence, and 127 will play the sound at the maximum volume specified in the "Sound" control panel. If you omit this parameter, it is treated as 127.

If async is _zTrue, the sound will play asynchronously. If async is _false, or you omit the parameter, the sound plays synchronously. When you play asynchronously, your program starts executing the next statement immediately while the sound is playing in the background. When you play synchronously, the next statement in your program does not execute until the sound has finished playing.

If you are playing notes asynchronously, and your execute a second SOUND statement while another sound is still playing in the background, the new sound won't start playing until the first sound finishes. Note that on some machines, this technique can result in lost sounds. When playing asynchronously it's better to use the SOUND% function to determine when one sound has ended, before attempting to play the next sound.

One way to play sound frequencies is to use negative numbers (from -1 through -127) to represent the note that you wish to play. The table below shows how to use these values.

Image was here

Using the midi table for a guideline, we can create a version of "pop goes the weasel" as follows:

<code><b>PRINT</b> "Pop! "; : <b>SOUND</b> -70, 45 ,,_false<br>
<b>PRINT</b> "Goes "; : <b>SOUND</b> -64, 30 ,,_false<br>
<b>PRINT</b> "the "; : <b>SOUND</b> -67, 15 ,,_false<br>
<b>PRINT</b> "wea"; : <b>SOUND</b> -66, 40 ,,_false<br>
<b>PRINT</b> "sel "; : <b>SOUND</b> -62, 45 ,,_false</code>

See Also edit

SOUND%; SOUND END; SOUND<snd>