PC Audio

Every PC has a built-in speaker driven by a timer chip, good for simple square-wave tones. Sound cards added far more: the AdLib brought FM synthesis with the OPL2 chip, and the Sound Blaster added digital sample playback over DMA, becoming the DOS standard for game sound.

PC Audio

Overview

PC sound came in layers. The speaker is on every machine but makes only rough tones. The AdLib card gave real music through FM synthesis, and the Sound Blaster added the ability to play back recorded samples, so speech and sound effects joined the music. A DOS game usually detected which cards were present and used the best it found, falling back to the speaker.

SourceKind of soundVoices
PC speaker1-bit square-wave tones1
AdLib / OPL22-operator FM synthesis9
Sound BlasterOPL FM plus digital samples9 + sampled

The PC speaker

The built-in speaker is driven by channel 2 of the 8253 programmable interval timer. The timer counts down at a fixed rate and flips its output each time it reaches zero, producing a square wave; the count loaded sets how often it flips, and so the pitch. The output is one bit, on or off, so the speaker plays a single square-wave tone at a time with no volume control, effectively a 1-bit source like the Spectrum beeper.

A program sets the timer's mode, writes the count to the timer, then connects the timer to the speaker through the keyboard-controller port 61h. To play a sample stream instead of a tone, some programs drive the speaker bit directly at high speed in software, coaxing rough digital audio out of the 1-bit output.

PortRole
42hTimer channel 2 count (pitch), low byte then high.
43hTimer control word, sets channel 2 mode.
61hBits 0–1 gate the timer and connect it to the speaker.

AdLib and the OPL2

The AdLib card is built around the Yamaha OPL2 (YM3812) FM synthesis chip. FM, frequency modulation, makes a sound by using one oscillator, the modulator, to bend the frequency of a second, the carrier; the resulting tone is far richer than a plain square wave, and shaping the two operators gives everything from bells to brass. The OPL2 has 18 operators arranged as nine 2-operator voices, so up to nine notes sound at once.

The chip plays on its own once set, freeing the CPU, and needs no external circuitry beyond the card. Music for it is a stream of register writes over time, which is why AdLib music files are essentially logged register changes.

OPL registers

The OPL2 is programmed through two I/O ports. Write a register number to the address port 388h, wait briefly, then write its value to the data port 389h. The registers set each operator's waveform, attack and decay envelope, level and multiplier, and each voice's frequency and key-on. Setting a note means writing the frequency number and octave, then setting the key-on bit to start it.

Port / registerRole
388hAddress port: select the register to write.
389hData port: value for the selected register.
20h–35hOperator: tremolo, vibrato, sustain, multiplier.
40h–55hOperator: output level (volume).
60h–75hOperator: attack and decay rates.
A0h–A8hVoice: frequency number, low bits.
B0h–B8hVoice: octave, high frequency bits, key-on.

The Sound Blaster

The Sound Blaster keeps an OPL FM chip for music, compatible with AdLib, and adds a digital sound processor that plays back recorded samples. Sample playback uses DMA, direct memory access: the program hands the card a block of sample bytes in memory and a playback rate, and a DMA channel feeds those bytes to the card without the CPU copying each one, so speech and sound effects can play while the game runs.

The card is controlled through a small block of ports at a base address, commonly 220h. The program writes a command to the DSP to set the sample rate and start a transfer, points the DMA controller at the sample buffer, and the card signals an interrupt when the block finishes so the next can be queued. This mix of FM music and sampled effects made the Sound Blaster the sound standard for DOS games.

ElementRole
Base port (e.g. 220h)DSP command, data and OPL registers.
DMA channelFeeds sample bytes from memory to the card.
IRQSignals the CPU when a sample block ends.
OPL chipFM music, AdLib-compatible.