How Libopus Handles Stereo Acoustic Coupling
This article explains how the libopus audio codec optimizes bit allocation by exploiting the acoustic coupling between stereo channels. By using advanced techniques like Mid-Side (M/S) joint stereo coding, intensity stereo, and psychoacoustic masking, Opus discards redundant spatial data, allowing it to deliver high-quality stereo audio at exceptionally low bitrates.
Mid-Side Joint Stereo Coding
At the heart of libopus’s stereo optimization is Mid-Side (M/S) joint stereo coding. Instead of encoding the left and right channels independently, the encoder converts them into a “Mid” channel (the sum of left and right) and a “Side” channel (the difference between left and right).
When the audio in both channels is highly correlated—meaning the sound source is centered in the stereo image—the Side channel contains very little energy. Libopus detects this correlation and dynamically allocates the vast majority of the bitrate to the Mid channel. Only a tiny fraction of the bit budget is used to encode the sparse residual data in the Side channel, preventing the redundant encoding of identical waveforms.
Dynamic Band-by-Band Allocation
Rather than applying a blanket stereo setting to an entire audio frame, the CELT (Constrained Energy Lapped Transform) layer of libopus splits the frequency spectrum into multiple critical bands. For each individual band, the encoder determines the optimal stereo representation.
If a specific frequency band is highly correlated across both channels, the encoder couples them tightly using M/S coding. If a band contains highly independent signals—such as a wide stereo reverb or panning effects—the encoder decouples them to preserve the stereo width. This granular, band-by-band decision process ensures that bits are spent only where spatial separation is perceptually necessary, saving bandwidth on highly coupled frequencies.
Intensity Stereo at Low Bitrates
At lower bitrates, libopus leverages intensity stereo coding for high-frequency bands. The human auditory system cannot easily perceive fine phase differences in high frequencies; instead, it relies primarily on volume (intensity) differences between the ears to localize sound.
To exploit this, libopus merges the high frequencies of both channels into a single, shared channel. It then transmits only the relative energy (intensity) envelopes for the left and right channels, alongside the shared spectral data. This drastically reduces the data footprint of the high-frequency spectrum while maintaining a convincing spatial image for the listener.
Binaural Masking and Psychoacoustics
Libopus also utilizes the principles of binaural masking. The human ear is less sensitive to quantization noise in the stereo side channel when there is a strong, dominant mono signal in the mid channel.
The encoder’s psychoacoustic model calculates how much the louder Mid channel masks the quieter Side channel. If the Mid channel is dominant, the encoder allows for higher quantization noise in the Side channel. By reducing the precision of the Side channel in these scenarios, libopus frees up significant bit allocation for other critical parts of the audio spectrum without introducing audible distortion.