Q(uick)BASIC Statement: SOUND
Quick View
SOUND
A device I/O statement that generates sound through the speaker
Worth knowing
Useful and cross-version information about the programming environments of QBasic and QuickBasic.
Syntax
- SOUND frequency, duration
Description/Parameter(s)
frequency | The frequency of the sound in hertz; a value in the range 37 through 32,767. |
duration | The number of system clock ticks the sound lasts; a value in the range 0 through 65,535. There are 18.2 clock ticks per second. |
Example
FOR i% = 440 TO 1000 STEP 5
SOUND i%, i% / 1000
NEXT i%
See also:
Syntax
- SOUND frequency,duration
Description/Parameter(s)
The frequency is the desired frequency in hertz (cycles/second). It must be a numeric expression returning an integer in the range 37-32,767.
The duration is the duration in clock ticks. (There are 18.2 clock ticks per second regardless of CPU speed.) The duration must be a numeric expression returning an unsigned integer in the range 0-65,535.
If the duration is zero, any current SOUND statement that is running is turned off. If no SOUND statement is running, a SOUND statement with a duration of zero has no effect.
Example
This program produces a rising and descending glissando:
CLS
FOR I = 440 TO 1000 STEP 5
SOUND I, I/1000
NEXT
FOR I = 1000 TO 440 STEP -5
SOUND I, I/1000
NEXT
See also:
Syntax
- SOUND frequency, duration%
Description/Parameter(s)
frequency | The frequency of the sound in cycles per second or hertz. It must be a numeric expression with a value between 37 and 32, 767, inclusive. |
duration% | The number of system clock ticks the sound lasts. It must be a numeric expression with an unsigned integer value between 0 and 65,535, inclusive. There are 18.2 clock ticks per second, regardless of CPU speed. |
The SOUND statement is not available in OS/2 protected mode. |
- If duration% is 0, any current SOUND statement that is running in the background is turned off. If no SOUND statement is running, a duration of 0 has no effect.
Example
This example uses the SOUND statement to produce rising and descending glissando.
CLS
FOR I = 440 TO 1000 STEP 5
SOUND I, I / 1000
NEXT
FOR I = 1000 TO 440 STEP -5
SOUND I, I / 1000
NEXT
See also: