USING THE KEYBOARD SPEAKER
By BOB COCKROFT
By BOB COCKROFT
For those of you who want to expand the sound usage in your games beyond the four-voice audio output, the keyboard speaker provides an interesting alternative. Located in the computer console the keyboard speaker creates sound by providing waves of alternating low and high pressure of air. A vibrating diaphragm pushes pressure waves through a speaker thus producing sound. Storing an 8 in memory location 53279 (CONSOL) pushes the diaphragm in one way and storing a 0 in CONSOL pushes the diaphragm the other way. The period of time between switching CONSOL from 8 to 0 determines the pitch of the sound waves. The longer the period of time between switching the values in CONSOL the lower will be the pitch. In addition to any changes of the values in CONSOL a user may make, the computer automatically resets this location to 8 every 1/60 of a second.
Program one is a simple application of what has been explained so far. To push the diaphragm in one direction, line 20 stores a 0 in CONSOL. As mentioned earlier the computer will automatically reset CONSOL to 8, thus pushing the diaphragm in the other direction. Line 10 and 30 contain the loop that repeats this process.
Because CONSOL is only being reset every 1/60 of a second in program 1, the pitch created is limited to 60 hertz. However, by disabling part of the Vertical Blank Interrupt (VBI), different pitches can be produced. The VBI being a method which the computer updates itself, can be divided into two different sections. The first section updates the ATTRACT mode and the real time clock. The second section updates game controllers, shadow registers, system countdown timers and resets the 8 in CONSOL. By setting the location 66 (CRITIC flag) to a number between 1 and 255, the second stage of the VBI can be defered. It is important to note the functions of the second section of the VBI are not performed when the CRITIC flag is set.
Because the Atari computer has Direct Memory Access (DMA), it has some pitch distortion. The ANTIC chip uses machine cycles to form the 6502 in order to create the television display and to update memory. Because of this the accuracy of the pitch is reduced when a screen is displayed. Therefore to create a purer tone the display must be turned off. This can be done by storing a 0 in memory location(54272) (DMACTL) after the CRITIC flag has been set to a non-zero number.
Program 2 has been designed both to be a means to experiment with different speaker pitches and to give a practical example of what has been explained. This program will first turn off the screen to minimize distortion. Soon after the keyboard speaker will begin to buzz. Press 'H' to increase the frequency or 'L' to lower the it.
Program Listing 1.
5 REM * PROGRAM 1 *
8 REM * START LOOP *
10 FOR X=1 TO 10000
15 REM * RESET DIAPHRAGM *
20 POKE 53279,0
30 NEXT X
Program Listing 2.
1 REM * PROGRAM 2 *
2 REM * keyboard sound lab *
10 CONSOL=53279
20 CRITIC=66
30 DMACTL=54272
40 REM * SET CRITIC FLAG *
45 POKE CRITIC,1
48 REM * TURN OFF SCREEN (DMA) *
50 POKE DMACTL,0
55 X=60
60 REM * MAIN LOOP *
70 FOR Y=1 TO X
80 NEXT Y
85 REM * PUSH DIAPHRAGM IN ONE DIRECTION *
90 POKE CONSOL,0
100 FOR Y1=1 TO X
110 NEXT Y1
115 REM * PUSH DIAPHRAGM IN OTHER DIRECTION *
120 POKE CONSOL,8
122 REM * PRESS 'L' TO LOWER PITCH *
125 IF PEEK(764)=0 THEN X=X+1
127 REM * PRESS 'H' FOR HIGHER PITCH *
128 IF PEEK(764)=57 THEN X=X-1
130 IF X<1 THEN X=1
140 GOTO 70