POKEY Sound Basics: SOUND, Registers and Your First Effects
Every Atari 400, 800, XL and XE has the same sound hardware: four voices inside POKEY, the custom chip that also scans the keyboard, reads the paddles and runs the serial bus. This guide starts at the BASIC SOUND statement and works down to the hardware registers. By the end you will know where the numbers come from, how to play notes that are in tune, and how to make the usual game noises.
What you need: any Atari 8-bit with Atari BASIC (built into XL/XE machines, a cartridge on the 400/800), or an emulator such as Altirra. Make sure the TV or monitor volume is turned up. In Altirra, sound works out of the box.
1. The SOUND statement
Atari BASIC has a single sound command:
SOUND voice, pitch, distortion, volume
| Parameter | Range | Meaning |
|---|---|---|
| voice | 0–3 | Which of POKEY's four channels to use |
| pitch | 0–255 | A divider: bigger numbers give lower notes |
| distortion | 0–14, even numbers | The noise/waveform type; 10 (or 14) is a pure tone |
| volume | 0–15 | 0 is silent, 15 is loudest |
Type this directly, without a line number:
SOUND 0,121,10,8
That is middle C on voice 0. The note keeps playing until you change it. SOUND 0,0,0,0 silences voice 0, and END silences all four voices. One surprise for newcomers: in BASIC the BREAK key does not stop sound, although SYSTEM RESET does. Abbreviate the command as SO. to save typing.
Now try a chord by putting a note on each of three voices:
SOUND 0,121,10,8
SOUND 1,96,10,8
SOUND 2,81,10,8
That gives C, E and G. Keep each volume at about 8 when several voices play at once. The four volumes together should not exceed 32: above that the output overmodulates, loses volume and starts to buzz.
2. What the numbers really do
SOUND is a friendly front end to eight POKEY registers. Each voice has a frequency register (AUDF) and a control register (AUDC):
| Voice | AUDF (pitch) | AUDC (distortion + volume) |
|---|---|---|
| 0 | 53760 ($D200) | 53761 ($D201) |
| 1 | 53762 ($D202) | 53763 ($D203) |
| 2 | 53764 ($D204) | 53765 ($D205) |
| 3 | 53766 ($D206) | 53767 ($D207) |
The control byte packs both settings together: the upper four bits hold the distortion and the lower four hold the volume. Chris Chabris spelled out the formula in Antic (November 1983):
CONTROL = 16 * DISTORTION + VOLUME
So SOUND 0,121,10,8 does the same job as:
POKE 53760,121:POKE 53761,168
Here 168 = 16×10 + 8. These registers are write-only. Reading the same addresses returns something else entirely (the paddle values), so you cannot PEEK them to find out what is playing.
Two more registers matter even at this level. AUDCTL at 53768 ($D208) holds options shared by all four voices, and SKCTL at 53775 ($D20F) controls the serial port. Every SOUND statement resets AUDCTL to 0, which is why the advanced tricks in the companion guide use POKEs rather than SOUND. POKEY also needs reinitialising after any serial I/O (disk, cassette, printer). In BASIC, SOUND 0,0,0,0 does it. In machine language, store 0 in AUDCTL and 3 in SKCTL (De Re Atari, Chapter 7).
3. Why higher numbers mean lower notes
The AUDF value is not a frequency. It is the N in a divide-by-N counter. POKEY counts pulses from a fixed clock and emits one output pulse for every N+1 input pulses. With distortion 10 the output flips on each of those pulses, so a full square wave takes two of them. For the default "64 kHz" clock, the timer period is (N+1)×28 machine cycles. On an NTSC machine (1.79 MHz CPU clock) that works out to:
frequency (Hz) = 63920 / (2 * (AUDF + 1))
Check it: AUDF = 121 gives 63920 / 244 ≈ 262 Hz, which is middle C. AUDF = 72 gives about 437.8 Hz, the closest you can get to concert A (440 Hz).
That formula produces the note table below. The values for octave 4 match the table Jim Capparell printed in Best of Antic (E 193, F 182, G 162, A 144, B 128, C 121, D 108, E 96, F 91).
| Note | Low octave | Middle octave | High octave |
|---|---|---|---|
| C | 243 | 121 | 60 |
| C# | 230 | 114 | 57 |
| D | 217 | 108 | 53 |
| D# | 204 | 102 | 50 |
| E | 193 | 96 | 47 |
| F | 182 | 91 | 45 |
| F# | 172 | 85 | 42 |
| G | 162 | 81 | 40 |
| G# | 153 | 76 | 37 |
| A | 144 | 72 | 35 |
| A# | 136 | 68 | 33 |
| B | 128 | 64 | 31 |
Notice that the gaps between numbers shrink as the pitch rises. Near the top of the range, one step of AUDF jumps by a large fraction of a semitone, so high notes are noticeably out of tune: the high-octave values above are already up to about 20 cents off. Jerry White's "16 Bit Sound Power" (Antic, September 1985) fixes this by pairing two voices, which the advanced guide covers. PAL machines run from a slightly slower clock, so they play every note about 1% flat.
4. Distortion: from pure tones to white noise
The distortion number selects how POKEY's three polynomial counters (pseudo-random bit generators 4, 5 and 17 bits long) delete pulses from the square wave. Short polys repeat often and give droning, motor-like buzzes. The 17-bit poly hardly repeats at all and gives hiss and explosions. The distortion values:
| Distortion | What POKEY does | Typical use |
|---|---|---|
| 0 | 5-bit poly gating the 17-bit poly | Rumbles, engines |
| 2 (and 6) | 5-bit poly gating the square wave | Rough, uneven tones |
| 4 | 5-bit poly gating the 4-bit poly | Rattles, buzzes |
| 8 | 17-bit poly | Explosions, steam, white noise |
| 10 (and 14) | No poly: pure square wave | Music |
| 12 | 4-bit poly | Buzzing, droning tones |
Distortion sounds change character with pitch, so experiment. De Re Atari's advice is that some trial and error is unavoidable.
5. Your first sound effects
Explosion: white noise with a falling volume.
10 FOR V=15 TO 0 STEP -1
20 SOUND 0,40,8,V
30 FOR W=1 TO 15:NEXT W
40 NEXT V
Laser zap: a fast pitch sweep with a pure tone.
10 FOR P=10 TO 100 STEP 6
20 SOUND 0,P,10,10
30 NEXT P
40 SOUND 0,0,0,0
Two-tone siren: this is Capparell's "European siren" from Best of Antic, written out without its comments.
10 LO=57:HI=45:PITCH=HI
20 FOR TIME=1 TO 10
30 SOUND 0,PITCH,10,14
40 FOR WAIT=1 TO 180:NEXT WAIT
50 PITCH=LO:LO=HI:HI=PITCH
60 NEXT TIME
70 SOUND 0,0,0,0
Beating tones: two voices a single step apart interfere with each other and produce a slow "wah". Try:
SOUND 0,255,10,8
SOUND 1,254,10,8
Then change voice 1 to 253 and then 252. The beat gets faster as the gap widens.
6. Timing notes properly
SOUND has no duration parameter, and empty FOR/NEXT loops make poor timers: Chabris noted that their speed depends on where they sit in the program. Use one of the operating system's 1/60-second countdown timers instead. Location 540 ($21C, system timer 3) counts down once per vertical blank until it reaches zero:
100 SOUND 0,121,10,8
110 POKE 540,60
120 IF PEEK(540)>0 THEN 120
130 SOUND 0,0,0,0
That plays exactly one second of middle C on NTSC. A PAL machine counts at 50 Hz instead. The OS also uses timer 3 when it opens the cassette recorder, so do not rely on it during tape I/O. The realtime clock guide covers the alternatives.
Troubleshooting
- Sound keeps playing after BREAK. Expected behaviour. Type
END, or addSOUND 0,0,0,0(and the same for voices 1–3) to your exit routine. - Odd whistles or no sound after disk or cassette access. POKEY is still in serial mode. Execute
SOUND 0,0,0,0, orPOKE 53775,3andPOKE 53768,0. - Annoying beeps during disk I/O. The "noisy I/O" flag is location 65 ($41):
POKE 65,0silences those beeps andPOKE 65,3restores them. - Chords sound thin or distorted. Lower the individual volumes so their total stays under 32.
- My AUDCTL POKE stopped working. A later
SOUNDstatement reset it. Use POKEs for every voice when AUDCTL is in use.
Further reading
- De Re Atari (Atari, Inc., 1982), Chapter 7: the classic deep explanation of POKEY sound.
- Mapping the Atari by Ian Chadwick (Small System Services, 1983), locations 53760–53775.
- Atari Sound and Graphics by Herb Moore, Judy Lower and Bob Albrecht (Wiley, 1982): a gentle self-teaching book.
- The Musical Atari by Hal Glicksman and Laura Goodfriend (Datamost, 1984): music theory and BASIC song programs.
- Next steps on this site: Advanced POKEY sound and Programming music.
Credits
- De Re Atari, Chapter 7: Sound — Bob Fraser (Section 7 of De Re Atari)
- Mapping the Atari (Ian Chadwick) — POKEY, locations 53760–53775 — AtariArchives.org
- Altirra Hardware Reference Manual — Chapter 5, POKEY — Avery Lee (Altirra)
- A Sound Introduction (Jim Capparell), Best of Antic Volume 1 — Jim Capparell
- Sound Beyond Sound (Chris Chabris), Antic Vol. 2 No. 8, November 1983 — Sound Beyond Sound (Chris Chabris); AtariMagazines.com (Kevin Savetz), 1983
- 16 Bit Sound Power (Jerry White), Antic Vol. 4 No. 5, September 1985 — Jerry White, 1985
