Using the Play Command and Sound Command
Sound:
If you just need a beep in your program, you can use BEEP:
CLS
INPUT "Press Enter to hear a beep", A$
BEEP
SOUND lets you play a beep and tell it how high or low the beep will be, and how long it will last. This program makes a 1000Hz beep for about 1 second:
SOUND 1000, 18
SOUND is good for making sound effects. Here's a bomb dropping:
FOR I = 4000 TO 1000 STEP -5
SOUND I, .1
NEXT I
____________________________________________________________________________
Play:
If you want to play a song, PLAY is exactly what you need. Try this:
PLAY "e8 d8 c8 d8 e8 e8 e4"
PLAY is like a little programming language inside of QBASIC. "e8" means play an eighth note "e". If you are familiar with sheet music, this will make sense. Here's a scale:
PLAY "c8 d8 e8 f8 g8 a8 b8 > c4"
The ">" greater than sign means "go up one octave".
Type this into QBASIC. It will play the first part of "Frere Jacques."
PLAY "c4 d4 e4 c4"
PLAY "c4 d4 e4 c4"
PLAY "e4 f4 g2"
PLAY "e4 f4 g2"
To make a note sharp use "+" and to make a note flat use "-".
To create periods of silence use P(amount).
For different kinds of music style, you can put one of these statements before the note statement:
PLAY "MB" Puts music in the background to use in a screen crossover.
PLAY "MS" Makes the notes light and separated.
PLAY "ML" Makes the note long and drawn out.
You may put an L(amount) at the front of your PLAY statement to save time if you will be using one note more of the time.
PLAY "C4 C4 D4 C2 F2 E1 C4 C4 D2 C2 G2 F1"
PLAY "C4 C4> C2> A2< F4 F4 E2 D1"
PLAY "+A4 A4> A2< F2 G2 F1"