Ch. 12 · Audio Codecs

한국어日本語
8 min

Perceptual Coding: Throw Away What the Ear Can't Hear

The core of lossy audio compression is the same idea as psychovisual coding in video. Move to the frequency domain, and use masking to avoid spending bits on the parts you can't hear.

In Chapter 1 we said "a codec is the technology of picking out what the human eye can't see and throwing it away." Audio codecs follow exactly the same philosophy. Exploiting the limits of the ear instead of the eye is called perceptual coding, and the field that studies those limits is called psychoacoustics.

PCM input MDCT Quantization +bit allocation Entropycoding Bitstream A psychoacoustic model directs bit allocation
The perceptual coding pipeline: the same skeleton as video's transform → quantization → entropy coding

Three limits of the ear

  • Absolute threshold of hearing: the quietest level at which a sound becomes audible differs by frequency. A sound below that level may be there but can't be heard, so there is no reason to spend bits on it.
  • Frequency masking (simultaneous masking): when a loud sound is present, quieter sounds at nearby frequencies are drowned out and can't be heard. A masked component can be quantized coarsely without anyone noticing.
  • Temporal masking: quiet sounds in the brief moments just before and just after a loud sound are also hard to hear.

Why move to the frequency domain

Masking is a per-frequency-band concept, so it is hard to apply to the raw time-domain waveform. That is why audio codecs group samples into short blocks and turn them into frequency components with a transform such as the MDCT (modified discrete cosine transform). It plays the same role as the DCT-family transforms applied to video blocks in Chapter 3. After the transform, the codec decides for each band how many bits to spend on it (bit allocation), and finally squeezes the result once more with entropy coding.

An analogy

In a noisy café, you don't need to record the whispering of the person next to you in crisp detail, because nobody will be able to hear it anyway. Perceptual coding is like a ledger that moves the bits you would have spent on sounds that won't be heard anyway over to the sounds that will be.

What it sounds like when bits run short: pre-echo and band limiting

A transform block has a width in time, so when a sudden burst such as a clap or castanets lands inside one block, the quantization noise spreads to just before the burst. This is called pre-echo. Codecs counter it with window switching, which shortens the block length in such passages. At very low bitrates, you may also hear the high-frequency band cut out entirely (band limiting), or a wavy, "underwater" artifact.

The difference from lossless

Perceptual coding is lossy compression: information thrown away can never be recovered. If you "convert an MP3 to FLAC," only the file format is lossless; the information that was already discarded does not come back. Conversely, re-encoding through a lossy codec several times (generation loss) accumulates artifacts, so keeping your editing source in a lossless format is the baseline.

Perceptual codingPerceptual coding

Compression that discards information the human ear can't hear. The common principle behind lossy audio codecs.

PsychoacousticsPsychoacoustics

The field that studies how people perceive sound. The basis for masking models.

MaskingMasking

The phenomenon where a loud sound covers quieter sounds nearby in frequency or time so they can't be heard.

MDCTModified discrete cosine transform

A transform that turns an audio block into frequency components. Its blocks overlap.

Pre-echoPre-echo

An artifact where quantization noise spreads to just before a sudden sound and becomes audible.

Check yourself

Which best describes how perceptual coding saves bits?