Web POKEY Brings the Atari Sound Chip to the Browser

In September 2021 mrk released Web POKEY, an emulation of the Atari 8-bit POKEY sound chip that runs inside a web browser. He wrote it as part of a larger project, an Atari emulator for the browser, and asked the AtariAge community to compare its output with real hardware and Altirra. Over the following weeks musicians tested it heavily, and it gained stereo support and a player for Raster Music Tracker (RMT) songs.

How it works

Web POKEY is a WebAudio AudioWorkletProcessor, so it runs in the browser's audio thread in current Chrome or Firefox. A page talks to it by sending lists of (register, value, timestamp) triplets. The timestamps let writes be scheduled exactly on the audio clock, and the scheme can carry any POKEY register (including SKCTL and STIMER) and more than one chip. The emulation covers:

  • all four channels with the 15 kHz, 64 kHz and machine-rate (1.77 MHz on PAL) clocks
  • 16-bit linked channels
  • the 4-, 5-, 9- and 17-bit polynomial noise generators
  • high-pass filters
  • volume-only mode
  • a second POKEY for stereo (registers $10–$1F)

POKEY's output is generated at the chip's own clock rate and then resampled to the audio device's rate, which requires low-pass filtering. mrk said this post-processing step was the hardest part to get right. When the project was announced, two-tone mode and POKEY reset through SKCTL were still missing.

The demos

  • Pokey Regs: type in register values and hear the result. The settings are kept in the URL, so a sound can be shared as a link.
  • SAP player: plays SAP type R files, which are frame-by-frame dumps of POKEY register writes. Add a file's URL after # in the player's address, drag a file onto the page, or use the file selector. The header is shown, FASTPLAY is honoured, and stereo type-R files play since 25 September 2021. Other SAP types (B, C, D) contain 6502 player code and would need CPU emulation, so they are not supported.
  • RMT player (from October 2021): a JavaScript player for Raster Music Tracker modules that already handled many of the RMT 1.28 example songs, including stereo ones.

Community testing

Tracker musicians compared tunes with recordings from real machines. Their reports led to fixes in the 5-bit poly ("distortion 2") sound, and mrk added a sample-rate selector so testers could compare filter settings. The thread also discussed a successor to the SAP-R format with an extra channel to record SKCTL/STIMER writes, since type R stores only the nine audio registers per POKEY. VinsCool contributed fixes to the RMT player through his own fork. By December 2021 the thread was linking to bevy-atari, mrk's browser-based Atari emulator, which is the larger project that Web POKEY was written for.

Getting it

The source is at github.com/mrk-its/web-pokey, and the README links the live examples hosted at mrk.sed.pl/web-pokey/. The RMT player is in the companion repository github.com/mrk-its/web-rmt. Web developers can embed the worklet in their own pages. Everyone else can paste a SAP-R link into the player and listen.

Credits