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.

Sequencer commands

The native operations a sequence drives on the PC, and whether each runs on its own once set or must be updated every tick. The speaker's pitch comes from the timer once loaded, but it has no envelope or volume, so anything expressive on it is driven. The OPL2 is fully latched: set a voice's FM patch and key it on, and the hardware runs the envelopes, vibrato and tremolo itself.

CommandWhat it doesAutomatic or driven
Speaker toneSquare from the PIT timerAutomatic (pitch only)
Speaker effectsVolume and timbre in softwareDriven
OPL noteFM voice frequency and octaveAutomatic
OPL key-onTrigger the operator ADSR envelopesAutomatic
OPL patchOperator waveforms, levels, feedback, connectionAutomatic
OPL vibrato / tremoloHardware modulation depthAutomatic

Sampled audio

Sampled sound on the PC ranges from a proper hardware DAC down to abusing the 1-bit speaker. The cheapest and most heroic route is the speaker itself: a fast timer interrupt reprograms channel 2 of the PIT hundreds or thousands of times a second so that each interrupt emits a pulse whose width encodes the next sample value, and the speaker's inertia averages those pulses into an analogue level. Done carefully this pulls roughly 6-bit PCM out of a 1-bit output, the technique Access Software sold as RealSound; it consumes the CPU and the timer while it plays.

The parallel port offers a simple external option. A Covox Speech Thing, or any resistor-ladder LPT DAC, is an 8-bit converter on the printer port, and the CPU or a timer writes sample bytes straight to it; the Disney Sound Source is the same idea with a small FIFO so the timing is looser. The proper answer is the Sound Blaster, whose DSP plays 8-bit PCM (16-bit on the SB16) from a memory buffer over DMA at rates up to 44.1 kHz, freeing the CPU and raising an interrupt at the end of each block. AdLib and bare OPL cards are FM only and cannot play samples at all.

MethodHow it worksDepthMax sample rate
Speaker PWM (RealSound)Fast PIT interrupt sets pulse widths on the 1-bit speaker~6 bits~22 kHz (CPU-bound)
LPT DAC (Covox / Sound Source)CPU or timer writes bytes to a parallel-port DAC8 bits~7 kHz Sound Source, up to ~44 kHz Covox
Sound Blaster DMADSP plays a PCM buffer over DMA, up to 44.1 kHz8 bits, 16 on SB16up to 44.1 kHz