Spectrum Audio
The original 48K Spectrum makes sound with a single-bit beeper driven straight by the CPU. The 128K models add an AY-3-8912 sound chip with three tone channels, a noise source and hardware envelopes, the same chip family used across many home computers of the era.
Overview
Two sound systems exist depending on the model. The beeper is present on every Spectrum and is driven entirely in software. The AY chip is present on the 128K, +2 and +3, and plays on its own once its registers are set, freeing the CPU. Music for the machine targets one or the other.
The beeper
The beeper is one output bit of the ULA, toggled through port 254 (0xFE). Bit 4 of a byte written to that port is the speaker level. There is no timer and no waveform generator: the program flips the bit in a tight loop, and the delay between flips sets the pitch while the number of flips sets the length. Volume is fixed at one level. Advanced routines interleave several toggle streams to fake polyphony, at the cost of all the CPU's time.
| Port | Bit | Meaning |
|---|---|---|
| 254 (0xFE) | 4 | Speaker level, toggled to make a tone. |
| 254 (0xFE) | 3 | Cassette MIC and border, often driven together. |
The AY sound chip
The AY-3-8912 on the 128K has three independent channels, A, B and C. Each has a square-wave tone generator; the three can be mixed with a single noise generator; and a shared envelope generator can shape volume over time. Once written, the chip sustains the sound without the CPU, so music can play under a game. Fourteen registers control it.
AY registers
Each channel's pitch is a 12-bit period split across two registers, a lower one being finer. Volume is four bits, or a flag that hands the channel to the envelope. The mixer register enables tone and noise per channel with active-low bits.
| Register | Contents |
|---|---|
| 0, 1 | Channel A tone period (12 bits: 8 fine + 4 coarse) |
| 2, 3 | Channel B tone period |
| 4, 5 | Channel C tone period |
| 6 | Noise period (5 bits) |
| 7 | Mixer: tone and noise enables per channel (active low) |
| 8, 9, 10 | Channel A, B, C volume (4 bits, or bit 4 = use envelope) |
| 11, 12 | Envelope period (16 bits) |
| 13 | Envelope shape |
Ports
The AY is reached through two I/O ports. First select a register by writing its number to the address port, then read or write its value through the data port.
| Port | Role |
|---|---|
| 65533 (0xFFFD) | Register select, and data read. |
| 49149 (0xBFFD) | Data write to the selected register. |
Sequencer commands
The native operations a sequence drives on the Spectrum, and whether each runs on its own once set or must be updated every tick. The 48K has only the beeper, which is driven for everything; the 128K adds the AY, which latches its tone, volume and noise and runs a single shared envelope on its own.
| Command | What it does | Automatic or driven |
|---|---|---|
| Beeper tone (48K) | Pitch from a CPU toggle loop | Driven |
| AY tone (128K) | 12-bit period per channel | Automatic |
| AY volume | 4-bit level per channel | Automatic |
| AY noise | Shared period, mixed per channel | Automatic |
| AY envelope | One shape and period, shared by all channels | Automatic (shared) |
| Vibrato, slides | No hardware; done in code | Driven |
Sampled audio
The Spectrum has no sample hardware, so digitised sound is squeezed through the 1-bit beeper by the CPU. To play a recorded waveform the program runs a tight, cycle-counted loop that holds the speaker bit high for part of each short period and low for the rest; varying that ratio (pulse-width modulation) or the spacing of the pulses (pulse-density modulation) makes the average level track the sample, so an 8-bit waveform is approximated a few effective bits deep. The loop must run at a fixed rate, so the whole CPU is spent on playback and the display usually freezes while it runs.
On the 128K the AY offers a gentler route: its 4-bit volume registers act as a crude DAC, so writing a stream of volume values from a fast, timer-driven interrupt plays samples (often called digidrums) while the chip's tone and noise are muted, leaving the screen alone at the cost of only about 4 bits of depth.
| Method | How it works | Depth | Max sample rate |
|---|---|---|---|
| Beeper PWM / PDM | Cycle-counted loop toggling port 254 bit 4 | 1 bit, dithered to a few effective bits | ~15 kHz |
| AY volume DAC (128K) | Fast interrupt streams values to a channel's 4-bit volume register | 4 bits | ~11 kHz |