pulse waveforms. Note the use of timing loops to create the
effect of the notes starting far apart, then getting closer j , 92
u
Sound Effects
n n
together. This gives the sensation of the sound beginning slowly, then picking up speed, just as a creaky door sounds as it opens and then closes. Figure 3-3 illustrates this method.
Figure 3-3, Timing Loops
Sound bursts
Shifted Timing
Time
n
n
n n
An alternate method of producing this kind of sound is by using pitch changes to create the effect. Program 3-9 used the same pitch value in the high control register throughout the routine. The clicking sounds of the door opening and closing were created by the short notes made when the gate bit and volume were turned on and off rapidly. Program 3-10 uses a different technique. The pitches change through the course of the routine, while the gate bit and volume remain on. There's usually more than one way to create a sound effect on the 64.
Program 3-10* Creaky Door, Revisited
For mistake-proof program entry, be sure to read "Automatic Proofreader," Appendix G 5 REM INITIALIZE REGISTERS :rem 43
7 REM :rem 27
10 FOR R=54272 TO 54296:POKE R,0:NEXT :rem 24
15 POKE 54296,15 :rem 49
16 POKE 54275,8:POKE 54277,0:POKE 54278,240 :rem 4 93
3 Sound Effects
17 POKE 54276,65 :rem 54
20 REM :rem 70
21 REM CREAK OPEN LOOP : rem 129 \~~\
23 REM :rem 73 U
25 FOR R=10 TO 195 :rem 128
30 POKE 54272,R:POKE 54273,0 :rem 222
35 FOR T=0 TO 10:NEXT :rem 141 I I
36 NEXT :rem 168
40 REM :rem 72
41 REM —'-- CREAK CLOSED LOOP :rem 11
42 REM :rem 74
50 FOR R=195 TO 10 STEP -1 :rem 24 55 POKE 54272,R:POKE 54273,0 :rem 229
65 FOR T=0 TO 10:NEXT :rem 144
70 NEXT :rem 166
71 REM :rem 76
72 REM TURN SOUND OFF : rem 98
73 REM :rem 78
80 POKE 54276,64:POKE 54296,0 :rem 4
The 64 can produce pitches (frequencies) so low that the waveform cycles are as much as one second apart (one cycle per second, or 1 Hz). This program takes advantage of this feature and simply increases and then decreases the frequency of the sound to produce the creaks instead of using a timing loop to place each sound the right distance from the last.
That's what makes it sound as if the clicks are coming slowly at first, then picking up speed. As the pitches climb in fre quency, they sound faster and faster.
Compare Figure 3-3 with the one below, which shows how the incrementing of pitches can cause this type of sound.
94
n
n n
Sound Effects
Figure 3^4. Incrementing Pitch
Individual Pulses
Increasing Pitch
Time
n
n
Crickets. This sound effect is essentially an exercise in timing. The cricket sounds are made up of bursts of fast clicks spaced in pairs, one making the rising sound, the other the falling sound.
Program 3*11. Crickets
For mistake-proof program entry, be sure to read "Automatic Proofreader," Appendix C.
5 REM INITIALIZE REGISTERS :rem 43
7 REM srem 27
10 FOR R=54272 TO 54296:POKE R,0:NEXT :rem 24
15 POKE 54296,15 :rem 49
16 POKE 54275f8:POKE 54277#0:POKE 54278,240 :rem 4 17 POKE 54272,0:POKE 54273,155 :rem 44
18 POKE 54276,65 :rem 55
21 REM :rem 71
22 REM MAIN CRICK LOOP :rem 123
23 REM :rem 73
95
3 Sound Effects
25 FOR K=0 TO 50 :rem 14
30 FOR 1=0 TO 1 :rem 212
40 FOR R=0 TO 15 STEP 5 :rem 132 , ~
41 REM :rem 73 Lj
42 REM SOUND A CRICK :rem 232
43 REM :rem 75
50 POKE 54296,R :rem 28 \ J
60 POKE 54296,0:NEXT :rem 116 ^
70 FOR M=0 TO 30:NEXT :rem 135
90 NEXT :rem 168
91 REM :rem 78
92 REM INTERVAL TIMING LOOP : rem 30
93 REM irem 80
100 FOR D=0 TO RND(0)*1000:NEXT :rem 149
120 NEXT:POKE 54276,64 :rem 217
The various FOR-NEXT loops in the program set the number of times the sound pairs are heard (line 25), pair the sounds together (line 30), set the volume to different levels (line 40), and produce the irregular intervals between sound pairs (line 100). This last loop, in line 100, uses the RND function once again to remove the mechanical sound that constant timing might have.
The sounds are actually created in lines 50-70 by turning the sound on and off quickly, with a very short pause in between.
Motor boat. This program uses a counter to modify both the speed of the sound and its volume. The counter keeps track of how many sounds are produced. By doing this, you're able to make a motor boat sound that first starts, revs up to maximum speed, and then putts away down the river. Program 3-12 creates this effect. Type it in and RUN it to hear the sound.
Program 3-12, Motor Boat
For mistake-proof program entry, be sure to read "Automatic Proofreader," Appendix C. } j
5 REM INITIALIZE REGISTERS : rem 43
7 REM :rem 27
10 FOR R=54272 TO 54296:POKE R,0:NEXT :rem 24 M 15 POKE 54275,8:POKE 54277,0:POKE 54278,240 :rem 3
16 POKE 54273,8:POKE 54272,0 :rem 200
17 POKE 54276,65 :rem 54 ["
41 REM :rem 73 lJ
42 REM BOAT GETTING CLOSER : rem 178
43 REM :rem 75
47 FOR K=0 TO 300 :rem 64 M
96
3 Sound Effects
\ \
I \
50 POKE 54296,(K/25)+3 :rem 90
55 POKE 54296,0 srem 255
57 FOR G=0 TO RND(0)*(150-K/2):NEXT :rem 114
60 NEXT srem 165
61 REM :rem 75
62 REM BOAT GETTING FARTHER AWAY — :rem 163
63 REM *rem 77
70 FOR F=0 TO 450 :rem 61
72 POKE 54296,15-F/30 :rem 57
75 POKE 54296,0 srem 1
77 FOR G=0 TO RND(0)*5:NEXT :rem 233
80 NEXT :rem 167
91 REM :rem 78
92 REM TURN SOUND OFF : rem 100
93 REM :rem 80
100 POKE 54276,64:POKE 54296,0 :rem 45 Line 50 looks at the counter value K (which is increased by the FOR-NEXT loop in line 47) and determines how loud the motor should be by varying the volume based on the value of K. The volume level is never less than 3, and slowly increases as K gets larger. Line 55 turns the sound off; it's this familiar on and off pattern that creates the actual hard sound.
In line 57, K is used to modify the RND function. At first, when K is a lower value, the delay loop is longer (maximum of 150), but as K increases, the delay loop becomes shorter, making the motor sound run faster and faster.
As the motor boat gets farther away, the value F in the second loop, found in line 70, becomes larger. As F increases, the volume level in line 72 becomes lower (15—F/30). Also, since the speed of the motor's sounds is already at maximum, a constant value is used with the RND function in line 77.