sound pitch,duration [,[volume][,async]]
This statement plays a tone of the given pitch, duration and volume.
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.
duration is expressed in ticks, and can range from 0 to 32,767. However, the toolbox sound commands require FutureBasic 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.
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.
_zTrue, the sound will play asynchronously. If
_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.
Using the midi table for a guideline, we can create a version of "pop goes the weasel" as follows:
print "Pop! "; : sound -70, 45 ,,_false
print "Goes "; : sound -64, 30 ,,_false
print "the "; : sound -67, 15 ,,_false
print "wea"; : sound -66, 40 ,,_false
print "sel "; : sound -62, 45 ,,_false
sound%; sound end; sound <snd>