Supported Audio Sample Rates in Libopus

This article provides a clear overview of the audio sample rates natively supported for input and output operations in the libopus library. It outlines the specific sampling frequencies accepted by the Opus encoder and decoder APIs, explains how these rates map to internal bandwidths, and describes how non-native rates are handled.

Natively Supported Sample Rates

The libopus API natively supports exactly five sampling rates for both input (encoding) and output (decoding) operations:

When initializing an encoder or decoder using functions like opus_encoder_init or opus_decoder_init, you must specify one of these five values. Passing any other sample rate will result in an OPUS_BAD_ARG error.

Mapping to Internal Bandwidths

These native sample rates correspond directly to the five transmission bandwidths defined in the Opus standard:

Regardless of the input sample rate chosen, the Opus encoder can dynamically scale its internal coding bandwidth down to save bitrate, or up to maximize quality, based on your configuration and network conditions.

Handling Non-Native Rates (e.g., 44.1 kHz)

Common consumer audio sample rates like 44.1 kHz (CD quality) are not natively supported by the libopus API.

To process 44.1 kHz audio or any other non-supported frequency: 1. Resampling: You must use an external resampling library (such as speexdsp or soxr) to convert the audio to a supported native rate—ideally 48 kHz to preserve maximum fidelity—before passing it to the Opus encoder. 2. Decoding: Similarly, the decoder will output audio at one of the five native rates (usually 48 kHz). If your playback hardware requires 44.1 kHz, you must resample the decoded output from 48 kHz to 44.1 kHz in your application layer.