Music, Sounds, ON PLAY and Using the Soundcard |
This tutorial is about statements used to play music, create sounds
and the ON PLAY statement.
|
BEEP ON PLAY... GOSUB PLAY SOUND Using the Microphone Using the Soundcard to Produce Sound
Use the BEEP statement to make
the computer beep once.
Use the ON PLAY statement to make a program
call a subroutine each time there are less
than the specified amount of notes left
to play. For example: if a program
has to play the notes A, B, A and B it
has to play 4 notes and if the following
lines are used in the program:
ON PLAY(2) GOSUB 1, the program will
go to line number 1 as soon as it
has played "ABA" because only the
last note (B) is left to play because
there were less than 2 notes left.Use the RETURN statement to return
to the point in the program when
the subroutine was called.Use PLAY OFF to turn ON PLAY off.
Use PLAY ON to turn ON PLAY on.
Use PLAY STOP to pause ON PLAY.
Example:
|
Use the PLAY statement to play music.
Here are the commands for the PLAY statement:C, D, E, F, G, A and B are the notes.
Ooctave = Set the octave.
< = Down one octave.
> = Up one octave
Nnote = Play a note (range: 0-84, 0 = pause.)Llength = Set the length of a note (range: 1-64, 1 = A whole note.)
Tnumber of quarter notes per minute (range: 32-255.)ML = Play the full length set by L (legato.)
MN = Play 7/8 of the length set by L (normal.)
MS = Play 3/4 of the length set by L (staccato.)Pnumber of quarter notes, range: 1-64.
MB = Play music in background, this will let the computer play
music while the program continues with other things.
MF = Play music in foreground, the program will be paused
until the music is done playing.
Example 1:
|
Example 2:
|
Use the SOUND statement to make sounds.
The frequency can range from 37 to 32767
and the duration from 0 to 65535.
This how SOUND is used:
SOUND frequency, duration
Example:
|
Using the Microphone: |
Use OUT to tell the soundcard to return one
sample of input from the microphone like this:
OUT base address + 12, 32To read the sample returned use INP like this:
INP base address + 10The volume for the microphone is set like this:
OUT base address + 4, 10
OUT base address + 5, volume
The range for the volume is 0 to 7.To get the volume for the microphone, use INP like this:
OUT base address + 4, 10
INP base address + 5Base address + number refers to the address
of an I/O port which is the base address plus number.
Example:
|
Use OUT to tell the soundcard that a sample
has to be sent to the speakers like this:
OUT base address + 12, 16Use OUT base address + 12, sample to
send one sample to the speakers.On computers which run above a certain speed it is possible
that new instructions are sent while producing sound while the
soundcard is still processing earlier instructions.
Use WAIT base address + 12, 128, 128 to wait until
the soundcard is ready for new instructions.Before producing sound, the soundcard has to be reset like this:
OUT base address + 6, 1
OUT base address + 6, 0The volume for both speakers is set separatly but has
to be sent as one value and is returned as one value.
The range for the volume is 0 to 15.
The value that has to be sent to set the volume is calculated like this:
volume = (left speaker volume * 16) + right speaker volumeThis is how the volume for both speakers is set:
OUT base address + 4, 34
OUT base address + 5, volumeTo get the volume for both speakers, use INP like this:
OUT base address + 4, 36
INP base address + 5The value for the volume that is returned is converted to two
separate volumes for both speakers like this:
left speaker volume = volume \ 16
right speaker volume = volume - (left speaker volume * 16)
Example:
|
If you click on the link below you will find some QBasic books we have selected from amazon.com
Recommended QBasic BooksQBasic For All!
Copyright 1999 - 2002. All rights reserved
Anastasios Yalanopoulos