Lines 10 and 20 PRINT parameter column headings and the
underline. Lines 30 through 100 calculate each SOUND
parameter within its specific range. For example, line 30
calculates the voice number as follows:
30 V = INT(RND(1)*3)+1
The notation RND(1) specifies the seed value of the random
number. The seed is the base number generated by the
computer. The 1 tells the computer to generate a new seed each
time the command is encountered. Since the Commodore 128
has 3 voices, the notation * 3 tells the computer to generate a
random number within the range 0 through 3. Notice however
that there is no voice 0, so the +1 in line 30 tells the computer to
generate a random number such that 1 < = Number < 4. The
procedure for generating a random number in a specific range is
to multiply the given random number times the maximum value of
the parameter (in this case, 3). If the minimum value of the
parameter is greater than zero, add to the random number a
value that will specify the minimum value of the range of numbers
you want to generate (in this case, 1). For instance, line 40
generates a random number such that 0 < = Number < 65535.
Since the minimum value is zero in this case, you do not need to
add a value to the generated random number.
Line 110 PRINTs the values of the parameters. Line 120 plays the
SOUND specified by the random numbers generated in lines 30
through 100. Lines 130 delays the program for 4 seconds while
the sound is playing. Line 140 turns off the SOUND after the 4
second delay. All sounds generated by this program play for 4
seconds or less, since they are all turned off after 4 seconds with
line 140. Finally, line 150 returns control to line 10, and the
process is repeated until you press the RUN/STOP and
RESTORE keys at the same time.
So far you have experimented with sample programs using only
the SOUND statement. Although you can use the SOUND
statement to play musical scores, it is best suited for quick and
easy sound effects like the ones in the dogfight program. The
Commodore 128 has other statements designed specifically for
song playing. The following paragraphs describe the advanced
sound and music statements that enable you to play complex
musical scores and arrangements with your Commodore 128
synthesizer.
7-10