Ch. 12 · Audio Codecs

한국어日本語
7 min

Turning Sound into Numbers: Sampling and Bit Depth

Sound becomes a pile of numbers depending on how many times per second you measure it (sampling rate) and how many bits you use for each measurement (bit depth). We start by calculating the size of uncompressed PCM.

Video has frames; sound has samples. Digital audio is what you get when you read the continuous voltage change from a microphone at very short intervals and write each reading down as a number. It is the same idea as pixels and bit depth in Chapter 1, except you slice once along the time axis and once along the amplitude axis.

Each dashed vertical line is one sample. The tighter the spacing, the better it tracks the waveform.
Sampling = reading the signal at regular time intervals; quantization = snapping each value to a fixed set of levels

Sampling rate and the Nyquist limit

The sampling rate is the number of samples per second (Hz). According to the sampling theorem (Nyquist–Shannon), you can reconstruct frequencies up to half the sampling rate. Human hearing is usually taken to span 20 Hz to 20 kHz, so to capture 20 kHz you have to sample at more than 40 kHz. That is the background to music CDs using 44.1 kHz and video and broadcast using 48 kHz as a de facto standard.

Sampling rateHighest reconstructable frequency (= half)Where you typically see it
44.1 kHz22.05 kHzMusic CDs, music distribution
48 kHz24 kHzVideo, broadcast, and the audio in most video files
96 kHz48 kHzHigh-resolution formats in recording and production

"Where you typically see it" reflects common practice. There are plenty of exceptions.

Why you shouldn't change the sampling rate carelessly

Video work is normally set to 48 kHz. If you drop 44.1 kHz audio onto a video as is, some editors and players resample it internally, and depending on the equipment the sound can drift out of sync or pick up noise. It is safer to convert only once, right before final output.

Bit depth: how many levels per sample

Bit depth is the number of bits used to record one sample. Each extra bit doubles the number of levels you can represent and widens the ratio between the quietest and loudest sound (the dynamic range) by about 6 dB. That is why 16-bit works out to roughly 96 dB and 24-bit to roughly 144 dB (number of bits × about 6.02 dB). The missing precision shows up as quantization noise, and in production, a faint noise called dither is sometimes mixed in to make that noise less objectionable.

Uncompressed size = rate × bits × channels

The bitrate of uncompressed audio (PCM) is sampling rate × bit depth × number of channels. The values below come from that multiplication alone.

ConfigurationCalculationBitrate
CD (44.1 kHz, 16-bit, stereo)44,100 × 16 × 21,411,200 bps ≈ 1,411 kbps
48 kHz, 16-bit, stereo48,000 × 16 × 21,536,000 bps = 1,536 kbps
48 kHz, 24-bit, stereo48,000 × 24 × 22,304,000 bps = 2,304 kbps
48 kHz, 16-bit, 5.1 (6 channels)48,000 × 16 × 64,608,000 bps = 4,608 kbps

One minute of CD-quality audio is 1,411,200 ÷ 8 × 60 = 10,584,000 bytes, about 10.6 MB.

Compared with video

The uncompressed 4K video we calculated in Chapter 1 came to about 6 Gbps (5,970 Mbps). Even uncompressed, stereo audio is around 1.5 Mbps, which is nearly three orders of magnitude smaller than video. So the goal of an audio codec is less about "getting over a file-size cliff" and more about how clean the sound is at a given size, and how little delay it adds. The cost structure is different from the video codecs in Chapters 8–10.

Check a file's sampling rate, channels, codec, and bitrate
ffprobe -v error -select_streams a:0 \
  -show_entries stream=codec_name,sample_rate,channels,channel_layout,bit_rate \
  -of default=noprint_wrappers=1 input.mp4
Sampling rateSampling rate

Samples per second (Hz). The highest frequency you can reconstruct is half this value.

Nyquist frequencyNyquist frequency

Half the sampling rate. Frequencies above it cannot be captured correctly.

Bit depthBit depth

The number of bits used to record one sample. The larger it is, the wider the dynamic range (about 6 dB per bit).

PCMPulse-code modulation

Recording sample values as they are, with no compression. WAV and similar formats are in this form.

Quantization noiseQuantization noise

Noise produced by the error from snapping continuous values to a fixed set of levels.

Check yourself

What is the bitrate of 48 kHz, 16-bit, stereo PCM audio?