HeadlinesBriefing favicon HeadlinesBriefing.com

ZX Spectrum 1-Bit Sound Experiment Chords PWM

Hacker News •
×

As part of the ZX Spectrum tour, I implemented routines to play simple tones out of the 1-bit beeper. Inspired by earlier work on the Apple II, these experiments pushed the limits of simple hardware. While replicating advanced PC speaker techniques proved difficult, significant progress was made in multichannel sound, specifically playing chords through the 1-bit speaker.

The author also recreated simple 1-bit PCM playback and experimented with Pulse Width Modulation (PWM) techniques. Both PCM and PWM work to inform the chord playback work. This week’s efforts included notable failures alongside successes, documenting the challenges of low-fidelity audio emulation.

Pulse Code Modulation (PCM) involves sampling a waveform as values between 0 and a maximum, with sample rate determining frequency control. The Spectrum can access memory at approximately 1MHz, allowing 16k Hz playback even under cycle-counted CPU control. However, because the speaker is only ever on or off, the audio quality resembles distortion from blowing a speaker out with amplification.

Using the 48K’s 3.5 MHz clock, dividing by 16,000 samples per second reveals 219 cycles between writes. Samples consume about 2KB per second, tight on a 48K system but manageable. PWM promises higher audio quality by varying pulse length to indicate signal strength, though physical speaker limitations introduce latency.

Different Spectrum models had slightly different CPU speeds; the 48K ran at a flat 3.5 MHz for cycle counting.