PCM as a reference for audio compression
Digital audio can be copied without a change in quality, but an uncompressed signal requires a high data rate. The amount of data depends on sampling rate, bit depth, and channel count. These parameters provide a reference for evaluating MP3 compression. MPEG-1 Audio Layer III is one of the formats covered by ISO/IEC 11172-3, which defines audio coding and decoding. The standard defines several coding layers, and MP3 denotes Layer III.
CD audio uses a digital representation called . The analog signal is sampled at fixed intervals, and each sample is assigned a value from a defined range. A CD uses the following parameters:
- Sampling rate: The audio wave is sampled times per second ( kHz). The resulting Nyquist frequency is 22.05 kHz, covering the typical audible band.
- Bit depth: Each sample is recorded with 16 bits of precision. This gives , or 65,536 quantization levels per sample and determines its dynamic range.
- Channels: A stereo recording contains two independent audio channels, left and right. With the other parameters fixed, channel count changes the uncompressed data rate linearly.
The data rate of uncompressed CD audio is:
This is often expressed as kilobits per second (kbps).
Three minutes of this uncompressed audio occupies about 32 MB, and an album can exceed 650 MB. For an example MP3 at 128 kbps, the data ratio relative to CD audio is about 11:1, so a 32 MB track can be about 3 MB. The resulting quality depends on the psychoacoustic model, bitrate, and audio material. MPEG-1 supports sampling rates of 32, 44.1, and 48 kHz, and the encoder selects the frame format and usable band together with that rate.
Psychoacoustic foundations of MP3
uses , the study of the relationship between an acoustic signal and its perception. A determines masking thresholds and controls the precision assigned to signal components. This perceptual coding uses several properties of human hearing. The model considers the threshold in quiet, masking between bands, and temporal masking. It approximates perception, so model parameters and encoder quality affect artifacts. Short transform windows reduce pre-echo around transients, while long windows provide finer frequency resolution for steady passages.
Auditory masking
Auditory masking occurs when a loud sound, the masker, raises the hearing threshold for a quieter masked signal. The encoder uses this threshold to allocate bits and control quantization noise. Two primary types of masking are relevant here. The threshold is estimated for a particular time and frequency region, so encoder decisions can change between frames.
Frequency Masking
A loud component can mask quieter components at nearby frequencies occurring at the same time. The encoder analyzes the spectrum, estimates a masking curve, and uses it to set an allowed quantization-noise level. Components below the threshold may receive fewer bits or be omitted. Masking generally increases with masker level and decreases with frequency distance. The calculation considers critical bands, where hearing has similar sensitivity, and the spread of masking into neighboring frequencies.
Temporal Masking
Masking also occurs over time. A loud sound can reduce the audibility of quieter sounds shortly before or after it.
- Post-masking: After a loud, short sound, hearing sensitivity recovers gradually. Quieter sounds occurring for roughly 100 to 200 milliseconds afterward may be masked and encoded with lower precision.
- Pre-masking: A loud sound can also reduce the audibility of a faint sound occurring about 20 milliseconds before it. This effect is related to the temporal processing of auditory stimuli.
MP3 encoding stages
An MP3 encoder divides the signal into frames, analyzes its spectrum, sets an allowed noise level, quantizes coefficients, and writes the result as a sequence of frames. A frame contains a header describing values such as bitrate and sampling rate, side information, and coded audio data. In MPEG-1 Layer III, one frame represents 1152 samples per channel, usually arranged as two granules of 576 samples.
- Frequency analysis and filter bank:
The polyphase filter bank divides the signal into 32 sub-bands. In MPEG-1 Layer III, each sub-band is further processed by a hybrid bank using MDCT. With long windows this produces 576 spectral coefficients per granule, or 1152 coefficients in an MPEG-1 frame, while short windows limit the effects of abrupt signal changes. The psychoacoustic model may use a separate spectral analysis, including a , to estimate signal properties.
- Psychoacoustic model:
The model analyzes the same frame, detects masking components, and calculates a Signal-to-Mask Ratio (SMR) for the bands. SMR describes the relation between signal level and masking level and helps set the allowed quantization noise. Its output controls subsequent bit allocation. The model may use a different analysis window from the main filter bank to respond more accurately to transients.
- Quantization and bit allocation:
This is where information is lost. reduces coefficient precision. The encoder shapes quantization noise to keep it below the estimated masking threshold when possible. Allocation depends on a target bitrate, such as 128 kbps, and on the bit budget for each audio frame. MPEG-1 Layer III uses non-uniform quantization, and scale information is stored for spectral bands.
- For sub-bands with a high masking threshold, the encoder may use coarse quantization and fewer bits.
- For sub-bands with a low masking threshold, it uses finer quantization and allocates more bits.
- For components below the absolute threshold of hearing, it may allocate zero bits when the encoder's decision permits it.
An encoder may use a bit reservoir. If one frame needs fewer bits than its target allocation, part of the budget remains available for a later frame with greater complexity.
- Huffman entropy coding:
The quantized coefficients are coded losslessly at the final stage. MP3 selects from defined Huffman tables for coefficient values and zero runs in spectral regions. MPEG-1 Layer III provides 32 tables, and the result is placed in a frame containing a header, side information, and audio data. Table and region selection affects the number of bits, but it does not change the quantized values. Stereo coding can use intensity stereo or mid/side stereo, depending on the encoder decision. A decoder reverses Huffman coding, inverse quantization, the inverse MDCT, and the synthesis filter bank before producing PCM samples. Side information carries scale and region parameters required for that reconstruction.
Bitrate, size, and quality
is the number of bits assigned per second of the stream. It affects file size and the precision available to the encoder, while quality also depends on the source material and implementation. At the same bitrate, different encoders can distribute bits across bands differently and can respond differently to transients.
The following values illustrate common trade-offs. MPEG-1 Layer III supports mono and stereo channel modes, so the same nominal bitrate can be distributed differently between channels:
- 32-64 kbps: A low bitrate often used for speech. It usually requires a restricted band or greater tolerance for coding artifacts. Music at this rate is especially sensitive to the chosen encoder and input complexity.
- 128 kbps: Gives about an 11:1 ratio relative to uncompressed CD audio. The result depends on the encoder and content, and difficult passages may show high-frequency artifacts.
- 192 kbps: Often described as near-CD bitrate. More bits can reduce coding artifacts, but the value does not guarantee that they will be inaudible.
- 256-320 kbps: A high range for MP3. 320 kbps is the highest bitrate in MPEG-1 Layer III, while the audible difference from PCM depends on content and listening conditions. The standard defines discrete bitrate values, so an encoder cannot select every number in this interval.
CBR and VBR
The selected bitrate can be applied in two basic modes:
- Constant Bitrate (CBR): The encoder uses the same nominal number of bits for each frame, regardless of complexity. A second of silence has a similar size to a second of complex audio, making the stream size predictable. Small frame-size differences can result from padding required by the format.
- Variable Bitrate (VBR): The encoder assigns more bits to complex passages and fewer bits to simple or quiet passages. The average bitrate can then meet a target size while the number of bits per frame varies. VBR use depends on the encoder settings. In both modes, frames contain their own headers and side information needed by the decoder. A bit reservoir can move part of the available budget between neighboring frames within the limits defined by the format.