Classic Computer Magazine Archive ANTIC VOL. 1, NO. 4 / OCTOBER 1982

Some Sound Advice

by Dave Plotkin

The SOUND statement in Atari BASIC is very powerful. Its ability to modify tone, distortion, and volume for each of four voices has been put to good use elsewhere in this issue. One of the problems with the SOUND statement is that using it extensively slows down program execution. While this is true of BASIC statements in general, with the SOUND statement there is an easy alternativeÑSOUND registers. SOUND registers are memory locations which control properties (tone, distortion and volume) of the ATARI's sound.

Memory Location      Function
53760                Tone of Voice 1 (SOUND 0)
53761                Distortion and Volume of Voice 1
53762                Tone of Voice 2 (SOUND 1)
53763                Distortion and Volume of Voice 2
53764                Tone of Voice 3 (SOUND 2)
53765                Distortion and Volume of Voice 3
53766                Tone of Voice 4 (SOUND 3)
53767                Distortion and Volume of Voice 4
53768                Tone "clock" control
The even-numbered memory locations (53760, 62, 64, 66) control the TONE; or which note the ATARI will play. This is identical to the second number in a SOUND statement. For example, to get the same tone as SOUND 0,100, 10, 8 you would POKE 53760,100. This specifies Voice 0, note 100. But what about distortion and volume? The oddnumbered memory locations (53761, 63, 65, 67) take care of these two characteristics for each voice via the following relation:

16 * DISTORTION + VOLUME

where DISTORTION is the third number in the SOUND statement (10 in our example) and VOLUME is the fourth number (8 in our example).

The equivalent POKE in our example is 16'F (10) + 8 = 168, and you would specify POKE 53761,168. Try it. Type in: POKE 53760,100:POKE 53761,168 [RET]. The other pairs of registers work the same way. You can turn off the note by specifying zero in either TONE or DISTORTIONand-VOLUME registers.

Memory location 53768 is an interesting one. The ATARI maintains two internal "clocks" which it uses to measure the frequency of the sound wave it generates. The two clocks run at different speeds. Switching clocks changes the frequency (and thus the tone) of the sound. Bit 1 of memory location 53768 controls which "clock" the ATARI uses to produce its sound. Normally Bit 1 is off, and the ATARI's sounds correspond to the tables in the reference manual. Turning Bit 1 on (POKE 53768,1) selects the slower clock, and alters the tone produced upward. Toggling Bit 1 off and on will switch all four voices up and down for a pretty good "alarm" effect. Note that the loop:

FOR N = 0 TO 255:POKE 53768, N: NEXT N turns the Bit 1 off and on very nicely without having to worry about setting and resetting the bit. The reason this works is that the values jump back and forth from odd to even, turning the Bit 1 on and off.)

How much faster is POKE than SOUND? Well, let's try an example. The following program downloads the ROM character set into RAM so it can be modified. With no sound (leave out the SOUND statements in line 30), this process takes 15.7 seconds. There are much faster ways to do this, but you can use this method until you feel confident. Fifteen seconds is a long time to sit looking at a computer doing nothing visible. Most people start getting nervous and wondering if "Atari Lockup" has struck again. Let's add some sound to assure the user that something is happening.

10 POKE 106,PEEK(106)-4:POKE 53761,168:POKE 53763,168:GRAPHICS 0
20 CHBASE = PEEK(106):0LDCH = 57344:NWCH = CHBASE *256
30 FOR X = 0 TO 1024:C = PEEK (OLDCH + X):POKE NWCH + X,C:SOUND 0,C,10,4:SOUND 1,X,10,4
40 NEXT X
Downloading the character set now takes some 25 seconds. If we try the following instead, substituting POKEs, the character set loads in about 20 seconds.
10 POKE 106,PEEK(106)-4:POKE 53761,168:POKE 53763,168:GRAPHICS 0
20 CHBASE = PEEK( 106):0LDCH = 57344:NWCH =CHBASE *256
30 FOR X = 0 to 1024:C = PEEK(OLDCH + X):POKE NWCH+X,C:POKE 53760,C:POKE 53762,140
40 NEXT X
Note that X, which varies from 0 to 1024, can be used as an input to the SOUND statementÑeach time it rolls over a multiple of 255, it starts over at 0 (thus 256 is 0, as is 513 and 769). This is not true of the POKE statement, so a constant was used. Doing a calculation to keep everything in range (such as POKE 53762, X/4) slows things down still further (about 28 seconds) and isn't a good idea.

Finally, various sources give the equations that relate tone to the internal docks and note frequency. While these equations are beyond the scope of this article, they can be useful to music computer enthusiasts.