Advanced POKEY: AUDCTL, 16-Bit Voices, Filters and Volume-Only Sound
The BASIC SOUND statement uses only part of what POKEY can do. Behind it sits one more register, AUDCTL, which changes the clock that drives each voice, joins voices into 16-bit pairs and switches in high-pass filters. Each AUDC register also has a hidden "volume-only" bit that lets software move the speaker cone directly. This guide shows how to use all of them from BASIC and assembly.
You should already know: the AUDF/AUDC registers and the 16 × distortion + volume control byte from POKEY Sound Basics.
You need: Atari BASIC; an assembler (MAC/65, the Assembler Editor cartridge, or a cross-assembler such as MADS) for the volume-only section; Altirra or real hardware.
1. AUDCTL at a glance
AUDCTL lives at 53768 ($D208). It is write-only, and every Atari BASIC SOUND statement resets it to zero. If you use AUDCTL, drive all the voices with POKEs. The bit layout:
| Bit | Value | Effect |
|---|---|---|
| 7 | 128 | Shorten the 17-bit poly counter to 9 bits (noise becomes more repetitive) |
| 6 | 64 | Clock voice 1 from 1.79 MHz instead of the base clock |
| 5 | 32 | Clock voice 3 from 1.79 MHz |
| 4 | 16 | Join voices 1+2 into one 16-bit voice (voice 2 clocked by voice 1) |
| 3 | 8 | Join voices 3+4 into one 16-bit voice |
| 2 | 4 | High-pass filter on voice 1, clocked by voice 3 |
| 1 | 2 | High-pass filter on voice 2, clocked by voice 4 |
| 0 | 1 | Base clock is 15 kHz instead of 64 kHz |
Note on numbering: POKEY's hardware voices are 1–4, while BASIC calls them 0–3. The bit-2 filter is clocked by channel 3 (bits 2 and 1 filter channel 1 with channel 3 and channel 2 with channel 4); some period references wrongly say channel 2.
The base clock applies to all four voices at once: you cannot run some voices from 15 kHz and others from 64 kHz at the same time. Only voices 1 and 3 can be switched to 1.79 MHz.
2. The frequency formulas
The exact timer periods, measured in machine cycles of the 1.79 MHz clock:
| Clock | Period of one timer cycle |
|---|---|
| 64 kHz | (AUDF + 1) × 28 cycles |
| 15 kHz | (AUDF + 1) × 114 cycles |
| 1.79 MHz, single voice | AUDF + 4 cycles |
| 1.79 MHz, 16-bit pair | N + 7 cycles, where N = low + 256 × high |
A pure tone (distortion 10) needs two timer cycles per wave. So on NTSC, with a CPU clock of 1,789,773 Hz:
f = 1789773 / (2 * period)
The three clock rates are 63.9210 kHz, 15.6999 kHz and 1.78979 MHz. Try a single high voice clocked at 1.79 MHz, the demonstration from De Re Atari:
SOUND 0,255,10,8
POKE 53768,64
The low rumble becomes a high whine, because voice 1 now divides a clock roughly 28 times faster.
3. 16-bit voices: accurate music
Eight bits of divider are not enough for good tuning. Near the top of the range one step of AUDF jumps by a large fraction of a semitone. Joining two voices gives a 16-bit divider, at the cost of using two of your four voices. Jerry White's Antic article "16 Bit Sound Power" (September 1985) used this to give "a richly melodic seven octaves" from BASIC. His table puts middle C at a 16-bit value of 3414. Check it with the linked-timer formula: 1,789,773 / (2 × (3414 + 7)) ≈ 261.6 Hz, which is spot on.
Here is a complete BASIC program that calculates the divider for any frequency and plays a C-major scale in tune:
10 SOUND 0,0,0,0
20 POKE 53768,80:REM 64+16: VOICE 1 AT 1.79MHZ, JOIN 1+2
30 POKE 53761,160:REM VOICE 1 (LOW BYTE) SILENT
40 POKE 53763,168:REM VOICE 2 (HIGH BYTE) PURE TONE, VOL 8
50 FOR I=1 TO 8:READ F
60 N=INT(1789773/(2*F)-7+0.5)
70 HI=INT(N/256):LO=N-HI*256
80 POKE 53760,LO:POKE 53762,HI
90 POKE 540,20
100 IF PEEK(540) THEN 100
110 NEXT I
120 POKE 53763,0
130 DATA 261.63,293.66,329.63,349.23,392,440,493.88,523.25
How it works:
- Line 20 sets AUDCTL to 80 (bits 6 and 4). This is exactly the value De Re Atari uses in its two-paddle 16-bit demo.
- In a linked pair the low voice's AUDF holds the low byte (fine tuning), and the high voice's AUDF holds the high byte (coarse tuning). The high voice, voice 2, is the one you hear, so give it the volume. Mute voice 1.
- Line 90 uses system timer 3 (location 540) for a 1/3-second note on NTSC.
To hear the full range, try De Re Atari's paddle version: plug paddles into port 1 and run:
10 SOUND 0,0,0,0
20 POKE 53768,80
30 POKE 53761,160:POKE 53763,168
40 POKE 53760,PADDLE(0):POKE 53762,PADDLE(1)
50 GOTO 40
The same trick works for voices 3+4 with bit 3 (value 8). Add bit 5 (value 32) to clock voice 3 at 1.79 MHz, so POKE 53768,120 (64+32+16+8) gives two accurate 16-bit voices.
4. High-pass filters
A high-pass filter passes only sound "higher" than the filtering voice's frequency. In practice it is a flip-flop that XORs one voice's output against samples clocked by another. It does not behave like a conventional high-pass filter: it produces strong, complex harmonics, which is exactly why musicians like it for buzzy bass and lead sounds. De Re Atari's demonstration:
SOUND 0,0,10,0
POKE 53768,4
POKE 53761,168:POKE 53765,168
POKE 53760,254:POKE 53764,127
Bit 2 is on, so voice 1 is filtered by voice 3. Change the two frequencies while it plays. Changing 53764 sweeps the filter in real time. Normally you would set the filtering voice's volume to 0 and listen only to the filtered voice.
5. The 9-bit poly
Bit 7 shortens the 17-bit noise generator to 9 bits, so noise turns into a recognisable repeating texture. De Re Atari's comparison:
SOUND 0,80,8,8
POKE 53768,128
The 17-bit generator also feeds the RANDOM register at 53770 ($D20A), so setting bit 7 affects PEEK(53770) too.
6. Updating voices together
BASIC is slow enough that four consecutive POKEs or SOUND statements can audibly stagger a chord. De Re Atari's answer is a 16-byte USR routine, SIMUL$, that writes up to four frequency/control pairs in one call. It also leaves AUDCTL alone, because no SOUND statement runs:
10 SOUND 0,0,0,0:DIM SIMUL$(16)
20 RESTORE 9999:X=1
25 READ Q:IF Q<>-1 THEN SIMUL$(X)=CHR$(Q):X=X+1:GOTO 25
30 X=USR(ADR(SIMUL$),121,168,96,166,81,166)
40 FOR W=1 TO 300:NEXT W
50 SOUND 0,0,0,0:SOUND 1,0,0,0:SOUND 2,0,0,0
9999 DATA 104,133,203,162,0,104,104,157,0,210,232,228,203,208,246,96,-1
Disassembled, the routine pulls the argument count, stores it in $CB (location 203, one of the few page-zero bytes BASIC leaves free), then pulls each argument and stores its low byte at $D200+X. Arguments go in AUDF, AUDC order for voice 1, 2, 3, 4. Leave out trailing pairs to set fewer voices.
7. Volume-only mode: driving the speaker directly
Bit 4 of an AUDC register (value 16) bypasses the frequency divider and the noise generators. The 4-bit volume goes straight to the output. Writing a new level moves the speaker to that position and holds it there. De Re Atari demonstrates with two POKEs that "pop" the speaker out and back:
POKE 53761,31:POKE 53761,16
Change the level fast enough and you can draw any waveform you like. This 4-bit DAC is how samples and speech are played. BASIC is far too slow to do it (you get only a low buzz), so here is a minimal assembly loop in the spirit of Bob Fraser's VONLY listing from the same chapter. It plays a 16-step sine wave:
AUDCTL = $D208
AUDC1 = $D201
SKCTL = $D20F
IRQEN = $D20E
NMIEN = $D40E
DMACTL = $D400
*= $4000
START LDA #0
STA AUDCTL ; normal clocks
LDA #3
STA SKCTL ; re-init POKEY
LDA #0
STA IRQEN ; no IRQs (keyboard, timers)
STA NMIEN ; no VBI/DLI interruptions
STA DMACTL ; no screen DMA: steady timing
LOOP LDX #0
NEXT LDA WAVE,X
ORA #$10 ; set volume-only bit
STA AUDC1
LDY #8 ; delay sets the pitch
DLY DEY
BNE DLY
INX
CPX #16
BNE NEXT
BEQ LOOP ; always taken
WAVE .BYTE 8,11,13,14,15,14,13,11
.BYTE 8,5,3,2,1,2,3,5
Fraser's original turns off interrupts and DMA for the same reasons. Without that, the vertical-blank interrupt makes audible gaps, and ANTIC's DMA "steals cycles at odd intervals". The screen goes blank while the program runs, and the loop never returns, so cold-start the machine (or reset the emulator) to get out. Raise or lower the LDY #8 value to change the pitch. Real sample players use a POKEY timer interrupt instead of a delay loop (see Realtime clock and timers).
8. Stereo and extra POKEYs
The stock machine is mono, but stereo upgrades that piggyback a second POKEY have been around since Chuck Steinman's 1989 "Gumby" design. Many successors followed, including Candle's SimpleStereo and the C.P.U. STEREO by Bob!k and Raster. These use address line A4 to tell the chips apart, so the second POKEY appears at the odd 16-byte mirrors: $D210–$D21F instead of $D200–$D20F. The second chip has less functionality, because its interrupt and I/O connections are missing, so treat it as four extra sound voices.
Troubleshooting
- AUDCTL settings vanish. A
SOUNDstatement somewhere reset them. Use POKEs or the SIMUL$ routine. - 16-bit voice is silent. You put the volume on the low voice. In a linked pair only the high voice (2 or 4) produces the combined tone.
- Everything goes quiet after disk I/O. Reinitialise with
POKE 53768,0:POKE 53775,3, then set your AUDCTL value again. - Volume-only playback crackles. Interrupts or DMA are disturbing the timing. Disable them as shown, or drive playback from a timer IRQ.
Further reading
- De Re Atari (Atari, Inc., 1982), Chapter 7: AUDCTL, filters, 16-bit sound, the 60 Hz interrupt sound method and volume-only waveforms.
- Altirra Hardware Reference Manual (Avery Lee), Chapter 5: cycle-exact timer periods, noise sampling artefacts and high-pass behaviour.
- Mapping the Atari by Ian Chadwick (Small System Services, 1983), location 53768.
- COMPUTE!'s Third Book of Atari (Small System Services, 1984): Mapping cites articles there by Mati Giwer and Fred Tedsen on POKEing sound and AUDCTL.
Credits
- De Re Atari, Chapter 7: Sound — Bob Fraser (Section 7 of De Re Atari)
- Altirra Hardware Reference Manual — Chapter 5 POKEY and AUDCTL register reference — Avery Lee (Altirra)
- Mapping the Atari (Ian Chadwick) — AUDCTL 53768 and Appendix — AtariArchives.org
- 16 Bit Sound Power (Jerry White), Antic Vol. 4 No. 5, September 1985 — Jerry White, 1985
- comp.sys.atari.8bit FAQ (Michael Current), 6.11 Sound upgrades — Michael Current (comp.sys.atari.8bit FAQ)
