An Atari Library of Sound

Richard M. Kruse


Of the recognized human senses, it may easily be argued that the most important are those of sight and hearing. The movie industry was quick to realize the importance of adding sound to their visual productions. First there was simple background music, and later, when it became technically possible, sound was synchronized to the action. Few people today would pay to see a silent movie except under special circumstances.

Yet when most of us think of computers, we usually visualize someone sitting at a video console, typing, and staring silently into the screen. Hollywood generally adds some "bleeps" and "bloops", supposedly electronic, to the background. Real data processing centers are usually quite noisy with machinery running and several printers hanging away. These are all artificial sounds, however, far removed from what all of us experience in daily life.

Personal computing, of course, need not follow the same path. If it is technically feasible, why not add the dimension of sound to the already accepted versatility of a good color graphics system? Why not, indeed! Manufacturers of small computers are responding in varying degrees to this challenge. It is now up to programmers to use this new capability effectively.

One of the outstanding features of the Atari 400/800 personal computers is the built-in sound generation system. There is no need to jury-rig an external amplifier and speaker and then operate it with "PEEKs" and "POKEs". Atari's sophisticated sound channels are manipulated through special Basic commands, and the RF output carries the sound information properly formatted to be reproduced through the speaker of a standard television receiver. The television's sound system does not have to be of especially high quality to adequately handle the range of frequencies produced (although it certainly doesn't hurt). An added bonus of this system is that sound and video are presented side-by-side. Most people will probably find this preferable to listening to a disembodied sound source physically separated from the visual presentation.

The Ataris give you not just a single sound generator, but four identical "channels" which may be used separately or in any combination. Each channel has individually controllable pitch and volume, along with a third parameter which Atari calls "tone." The Basic statement which activates one of the sound channels has the following form:

100 SOUND P1,P2,P3,P4

Parameters P1 through P4 are integer values. P1 specifies which channel is to be activated, identified as zero through three. P2 may be any value from 0 to 255, and sets the relative pitch or frequency of the sound. In the pure tone mode, the pitch range is about two and one-half octaves, and by using a look-up table of conversion factors between musical notes and pitch values, playing a melody on the Atari becomes almost trivial. Playing four-part harmony can be done with some additional programming effort.

One of sixteen different volume levels (including off) is selected by the value of P4.

The tone parameter, P3, is a corker. There are eight possible values, two of which result in relatively pure musical tones. The remaining six, however, are not really "tones" at all, but special effects settings which produce strange and wonderful sounds that will be variously perceived as trucks, helicopters, heavy machinery, and warp drives. These effects, like the pure tones, may be varied in pitch and volume. And always, two or more sound channels may be active simultaneously. As you can see, the number of possible sounds and effects is staggering. Normal sounds can be imitated and new ones created, limited only by the imagination of the programmer.

To stimulate those imaginations, and to show the methods used to put these effects to work, one dozen varied and useful sound effects are presented here. Each effect is programmed as a subroutine which will run for a certain length of time and then terminate. Each subroutine makes use of one or more sound registers, and many of them accept one or more input parameters which modify the effect and/or its running time. A brief explanation is presented for each, so that you will be able to change the effects as desired.

1. Percussive Sound Generator-(See listing 1)

This is a "building block" subroutine which imitates the sound of struck or plucked musical instruments or, with different parameters, explosions or gunshots.

The percussive effect is achieved by executing a loop which initially sets a high volume level, then repeatedly reduces that level by a given percentage until it falls below a present minimum. The volume reduction factor is stored as the variable ICR, and it is easy to see that changing the value of ICR will change the rate of decay of the sound. Since ICR is calculated from the input parameter DUR, the decay rate can be modified at will each time the subroutine is called. The value 10 in statement 10020 is the tone parameter, and results in a pure tone output, so that this subroutine will imitate a chime or bell. Statement 10010 adds a brief burst of white noise at the start of the loop. (It is turned off at step 10025.) This enhances the initial "strike" effect and is heard in the sounds of many musical instruments. Statement 10040 turns the sound off altogether prior to returning to the calling program. While this percussive sound routine will run by itself, it can also be used in the generation of more complex sounds, as will be demonstrated.

2. Doorbell-(See listing 2)

...Now, who could that be?...

The familiar "Dinnng, donnng" of the doorbell is created by two sequential calls to a modified percussive routine. Two different pitches and two moderately long decays are used. What could be simpler?

3. Ringing Telephone-(See listing 3)

Mildred, would you get that?...

The telephone bell is actually just repeated invocations of the percussive sound, using a high pitch and a short decay. Notice that the two sound registers are set at slightly different pitches. This creates the strident nature of this effect. The final percussive call uses a longer decay time, resulting in a fairly natural "lingering" sound. The apparently meaningless statement at line 10045 simply wastes some time between "rings." You will see this same type of delay in some of the other routines.

4. Alarm Bell-(Seeing listing 4)

...Attention all hands! Secure for hyperwarp...

This is another application of the percussive effect, and is almost identical to the telephone bell. The main differences are that this effect uses a lower pitch and a slower repetition rate. One subtle modification to the percussion routine in both of these effects is the use of a larger value in testing for the end of the decay (notice the variable LM). This is another way to modify the decay time and may be preferable for fast action.

5. Explosion-(Seeing listing 5)

...Hah! Got the little #@*%!...

The explosion effect is also based on the percussive generator, using "white" (actually "pink") noise instead of a musical tone. For more volume we use three sound registers simultaneously, and to heighten the realism each is given a slightly different pitch. Finally, we use three different rates of decay, the slowest for the lowest pitch. This gives the "rolling" effect of a really "big bang." Entering this subroutine with DUR set to zero will give a pretty fair imitation of a gunshot, since it's basically the same kind of sound.

6. Siren 1-(See listing 6)

...Is he after me?...

This routine produces the rising and falling wail characteristic of electromechanical fire and police sirens. The inner loop in this subroutine (steps 10020 to 10035) generates either an increasing or decreasing pitch of constant amplitude. Each execution of the outer loop (steps 10015 to 10045) reverses the start, stop, and increment values. The delay is used again at step 10030 to waste a little time so that each execution of the loop takes about a second.

7. Siren #2-(See listing 7)

...Quickly, Henri! The Gendarmes...

This alternate siren effect, which I tend to think of as "European," is becoming more common in this country as well, as police and fire departments switch to purely electronic noisemakers. It is one of the simplest effects to create, requiring only alternating high and low pitches at constant volume. The wait loop is used again, at step 10025.

8. Ticking Clock-(See listing 8)

...You have ten seconds to guess the correct answer...

The ticking of a clock (or bomb, heaven forbid) can be nicely simulated by repeated short bursts of white noise. Tone value eight, at a high pitch, serves this purpose. To get a tick-tock effect, two alternating values are used for the pitch parameter.

9. Klaxon-(See listing 9)

...RED ALERT! RED ALERT! Enemy sighted at...

Here, sound registers zero and one operate at slightly different pitches to generate a loud and strident blast, with sound register two filling in a buzzing effect. To add to the realism, one sound register is used at the beginning and end to build up to and decay from the main tone.

10. Whistle and Bomb-(See listing 10)

...Hit the deck!...

For this effect, the percussive explosion of example five is preceded by a convincing anticipatory whistle. Steps 10010 through 10030 create the whistle, which decreases in pitch while increasing in volume.

11. Steam Whistle-(See listing 11)

...All aboarrrrrd! Next Stop Pottsville...

A small amount of white noise from sound register zero in step 10025 adds a realistic hiss to this whistle variation. As in the Klaxon effect, there is a brief build-up preceding the main sound, and a decay at the end.

12. Sawing Wood-(See listing 12)

...And now for something completely different...

This final effect, unrelated to the others, is an example of picking a sound at random and trying to imitate it on the Atari. For sawing wood, you need a buzzing sound... Subroutine 10065. You need to make it rise and fall in pitch as the blade moves ...subroutine 10030. For better realism, you need two different pitches as the blade is pushed forward on the cutting stroke and then returned...statements 10015 and 10020.

It is hoped that these relatively simple examples will provide the motivation for Atari owners to get the most out of one of the built-in features of their computers. Other possible effects might include animal imitations, automobile sounds, factory noises, and on and on....the list of possibilities is truly unbounded.

If you have been programming without sound, you will be amazed at the improvement to be gained by its use in games and audio-visual presentations. Once you grow accustomed to this added dimension, it is certain that you will no longer be satisfied with a dull, mute computer.

The secret to success of the small personal computer lies in your creativity and imagination. Put them to work with Atari sound and see what develops. You can't go wrong!

LISTING 1: PERCUSSIVE SOUND GENERATOR
10000 REM PERCUSSIVE SOUND GEN
10002 REM ENTER W/2 PARAMETERS
10004 REM NTE=PITCH, 0-255
10006 REM DUR=LNGTH OF EFFECT, 0-10
10010 SOUND 1,5,8,6
10015 VOL=15:ICR=0.79+DUR/50
10020 SOUND 0,NTE,10,VOL
10025 SOUND 1,0,0,0
10030 VOL=VOL*ICR
10035 IF VOL<1 THEN 10020
10040 SOUND 0,0,0,0:RETURN
LISTING 2: DOORBELL
10000 REM DOORBELL
10002 REM NO ENTRY PARAMETERS
10010 NTE=105:DUR=7.5:GOSUB 10025
10015 NTE=132:DUR=8.5:GOSUB 10025
10020 SOUND 0,0,0,0:RETURN
10025 VOL=15:ICR=0.79+DUR/50
10030 SOUND 0,NTE,10,VOL
10035 VOL=VOL*ICR
10040 IF VOL>U THEN 10030
10045 RETURN
LISTING 3: TELEPHONE BELL
10000 REM TELEPHONE BELL
10002 REM ONE ENTRY PARAMETER
10004 REM TMS=* RINGS
10010 FOR XX=1 TO 35
10015 IR=0.3:LM=2:GOSUB 10055
10020 NEXT XX
10025 IR=0.9:LM=1:GOSUB 10055
10030 SOUND 0,0,0,0:SOUND 1,0,0,0
10035 TMS=TMS-1
10040 IF TMS<1 THEN RETURN
10045 FOR WT=1 TO 300:NEXT WT
10050 GOTO 10010
10055 VL=15
10060 SOUND 0,40,10,VL
10065 SOUND 1,42,10,VL
10070 VL=VL*IR
10075 IF VL>LM THEN 10060
10080 RETURN
LISTING 4: ALARM BELL
10000 REM ALARM BELL
10002 REM ONE ENTRY PARAMETER
10004 REM DUR=APPROX SECONDS RUN
10010 FOR TMS=1 TO DUR*12
10015 VL=15:IR=0.5:LM=3:GOSUB 10040
10020 NEXT TMS
10025 VL=10:IR=0.95:LM=1:GOSUB 10040
10030 SOUND 0,0,0,0:SOUND 1,0,0,0
10035 RETURN
10040 SOUND 0,53,10,VL:SOUND 1,60,10,VL
10045 VL=VL*IR
10050 IF VL>LM THEN 10040
10060 RETURN
LISTING 5: EXPLOSION
10000 REM EXPLOSION
10002 REM ONE ENTRY PARAMETER
10004 REM DUR=LNGTH OF EFFECT, 0-10
10010 NTE=20:GOSUB 10025
10015 SOUND 1,0,0,0:SOUND 2,0,0,0
10020 RETURN
10025 SOUND 2,75,8,15
10030 ICR=0.79+DUR/100
10035 V1=15:V2=15:V3=15
10040 SOUND 0,NTE,8,V1
10045 SOUND 1,NTE+20,8,V2
10050 SOUND 2,NTE+50,8,V3
10055 V1=V1*ICR
10060 V2=V2*(ICR+0.05)
10065 V3=V3*(ICR+0.08)
10070 IF V3>1 THEN 10040
10075 SOUND 0,0,0,0:RETURN
LISTING 6: AMERICAN SIREN
10000 REM SIREN 1
10002 REM ONE ENTRY PARAMETER
10004 REM DUR=APPROX SECONDS RUN
10010 LO=50:HI=35:STP=-1
10015 FOR TIM=1 TO DUR
10020 FOR NTE=LO TO HI STEP STP
10025 SOUND 0,NTE,10,14
10030 FOR WT=1 TO 22:NEXT WT
10035 NEXT NTE
10040 XX=LO:LO=HI:HI=XX:STP=-STP
10045 NEXT TIM
10050 SOUND 0,0,0,0:RETURN
LISTING 7: EUROPEAN SIREN
10000 REM SIREN 2
10002 REM ONE ENTRY PARAMETER
10004 REM DUR=APPROX SECONDS RUN
10010 LO=57:HI=45:NT=HI
10015 FOR TIM=0 TO DUR*2
10022 SOUND 0,NT,10,14
10025 FOR WT=1 TO 180:NEXT WT
10030 NT=LO:LO=HI:HI=NT
10035 NEXT TIM
10040 SOUND 0,0,0,0:RETURN
LISTING 8: TICKING CLOCK
10000 REM TICKING CLOCK
10002 REM TWO ENTRY PARAMETERS
10004 REM SIZ=1(FST) TO 10(SLW)
10006 REM DUR=APPROX SECONDS AT SIZ 5
10010 TIC=SIZ+5:TOC=SIZ+10
10015 FOR TIM=1 TO DUR
10020 SOUND 0,TIC,8,12:GOSUB 10035
10025 SOUND 0,TOC,8,12:GOSUB 10035
10030 NEXT TIM:RETURN
10035 SOUND 0,0,0,0
10040 FOR WT=1 TO SIZ*34:NEXT WT
10045 RETURN
LISTING 9: KLAXON
10000 REM KLAXON
10002 REM ONE ENTRY PARAMETER
10004 REM DUR=APPROX SECONDS RUN
10010 FOR TIM=1 TO DUR
10015 FOR NT=1 TO 10
10020 SOUND 0,100-NT,10,10
10025 NEXT NT
10030 SOUND 0,90,10,14
10035 SOUND 1,95,80,12
10040 SOUND 2,20,2,4
10045 FOR WT=1 TO 200:NEXT WT
10050 SOUND 1,0,0,0:SOUND 2,0,0,0
10055 FOR NT=1 TO 5
10060 SOUND 0,90+NT,10,8
10065 NEXT NT:SOUND 0,0,0,0
10070 FOR WT=1 TO 100:NEXT WT
10075 NEXT TIM:RETURN
LISTING 10: WHISTLE AND BOMB
10000 REM WHISTLE & BOMB
10002 REM ONE ENTRY PARAMETER
10004 REM DUR=LNGTH OF EFFECT
10010 V1=4:FOR NT=30 TO 75
10015 SOUND 0,NT,10,V1
10020 SOUND 1,NT+3,10,V1*0.7
10025 FOR WT=1 TO DUR*3:NEXT WT
10030 V1=V1*1.03:NEXT NT
10035 SOUND 2,35,8,12
10040 V1=15:V2=15:V3=15
10045 NT=DUR+5:ICR=0.79+DUR/100
10050 SOUND 0,NT,8,V1
10055 SOUND 1,NT+20,8,V2
10060 SOUND 2,NT+50,8,V3
10065 V1=V1*ICR
10070 V2=V2*(ICR+0.05)
10075 V3=V3*(ICR+0.08)
10080 IF V3>1 THEN 10050
10085 SOUND 0,0,0,0:SOUND 1,0,0,0
10090 SOUND 2,0,0,0:RETURN
LISTING 11: STEAM WHISTLE
10000 REM STEAM WHISTLE
10002 REM ONE ENTRY PARAMETER
10004 REM DUR=APPROX SECONDS RUN
10010 FOR VL=2 TO 14
10015 SOUND 1,56,10,VL:SOUND 2,66,10,VL
10020 NEXT VL
10025 SOUND 1,55,10,14:SOUND 0,5,8,3
10030 FOR WT=1 TO DUR*400:NEXT WT
10035 SOUND 0,0,0,0
10040 FOR VL=14 TO 1 STEP -2
10045 SOUND 1,55,10,VL:SOUND 2,67,10,VL
10050 NEXT VL
10055 FOR WT=1 TO 25:NEXT WT
10060 SOUND 1,0,0,0:SOUND 2,0,0,0
10065 RETURN
LISTING 12: SAWING WOOD
10000 REM SAWING WOOD
10002 REM ONE ENTRY PARAMETER
10004 REM DUR=APPROX SECONDS RUN
10010 FOR TMS=1 TO DUR
10015 ST=6:VL=12:GOSUB 10030
10020 ST=8:VL=8:GOSUB 10030
10025 NEXT TMS:RETURN
10030 FOR NT=ST+5 TO ST STEP -1
10035 GOSUB 10065:NEXT NT
10040 FOR NT=ST TO ST+5
10045 GOSUB 10065:NEXT NT
10050 SOUND 0,0,0,0:SOUND 1,0,0,0
10055 FOR WT=1 TO 25:NEXT WT
10060 RETURN
10065 SOUND 0,NT,2,VL
10070 SOUND 1,NT,8,VL*0.7
10075 WT=(WT/5)*5:RETURN

Richard M. Kruse, Xentrix Engineering, Box 8253, Wichita, KS 67220.

Table of Contents
Previous Section: Atari Strings and Text Handling
Next Section: Original Adventure in 32K