opus_custom(3)

🌸 opus_custom 🌸

okay bestie, welcome to opus_custom(3) β€” the Opus manual page that's giving very special edition, limited run, iykyk. ✨


πŸ’– NAME πŸ’–

opus_custom β€” Opus Custom

  • Opus Custom is an optional part of the Opus specification and reference implementation which uses a distinct API from the regular API and supports frame sizes that are not normally supported.
Use of Opus Custom is discouraged for all but very special applications for which a frame size different from 2.5, 5, 10, or 20 ms is needed (for either complexity or latency reasons) and where interoperability is less important. Not me being dramatic, that's literally what it says. πŸ’€

✨ SYNOPSIS ✨

πŸŽ€ Typedefs πŸŽ€

  • typedef struct OpusCustomEncoder OpusCustomEncoder β€” contains the state of an encoder. main character of the encode side fr.
  • typedef struct OpusCustomDecoder OpusCustomDecoder β€” state of the decoder. yes she's separate, she's her own thing.
  • typedef struct OpusCustomMode OpusCustomMode β€” the mode contains all the information necessary to create an encoder. lowkey the blueprint for everything.

πŸ¦‹ Functions πŸ¦‹

  • OpusCustomMode * opus_custom_mode_create (opus_int32 Fs, int frame_size, int *error) β€” creates a new mode struct. the whole vibe starts here.
  • void opus_custom_mode_destroy (OpusCustomMode *mode) β€” destroys a mode struct. say bye πŸ‘‹
  • int opus_custom_encoder_get_size (const OpusCustomMode *mode, int channels) β€” gets the size of an OpusCustomEncoder structure. you need this number before you malloc, bestie.
  • OpusCustomEncoder * opus_custom_encoder_create (const OpusCustomMode *mode, int channels, int *error) β€” creates a new encoder state.
  • void opus_custom_encoder_destroy (OpusCustomEncoder *st) β€” destroys an encoder state.
  • int opus_custom_encode_float (OpusCustomEncoder *st, const float *pcm, int frame_size, unsigned char *compressed, int maxCompressedBytes) β€” encodes a frame of audio.
  • int opus_custom_encode (OpusCustomEncoder *st, const opus_int16 *pcm, int frame_size, unsigned char *compressed, int maxCompressedBytes) β€” encodes a frame of audio.
  • int opus_custom_encode24 (OpusCustomEncoder *st, const opus_int32 *pcm, int frame_size, unsigned char *compressed, int maxCompressedBytes) β€” encodes a frame of audio.
  • int opus_custom_encoder_ctl (OpusCustomEncoder *OPUS_RESTRICT st, int request,...) β€” perform a CTL function on an Opus custom encoder.
  • int opus_custom_decoder_get_size (const OpusCustomMode *mode, int channels) β€” gets the size of an OpusCustomDecoder structure.
  • int opus_custom_decoder_init (OpusCustomDecoder *st, const OpusCustomMode *mode, int channels) β€” initializes a previously allocated decoder state. the memory pointed to by st must be the size returned by opus_custom_decoder_get_size.
  • OpusCustomDecoder * opus_custom_decoder_create (const OpusCustomMode *mode, int channels, int *error) β€” creates a new decoder state.
  • void opus_custom_decoder_destroy (OpusCustomDecoder *st) β€” destroys a decoder state.
  • int opus_custom_decode_float (OpusCustomDecoder *st, const unsigned char *data, int len, float *pcm, int frame_size) β€” decode an opus custom frame with floating point output.
  • int opus_custom_decode (OpusCustomDecoder *st, const unsigned char *data, int len, opus_int16 *pcm, int frame_size) β€” decode an opus custom frame.
  • int opus_custom_decode24 (OpusCustomDecoder *st, const unsigned char *data, int len, opus_int32 *pcm, int frame_size) β€” decode an opus custom frame.
  • int opus_custom_decoder_ctl (OpusCustomDecoder *OPUS_RESTRICT st, int request,...) β€” perform a CTL function on an Opus custom decoder.

🌈 Detailed Description 🌈

okay so. Opus Custom is an optional part of the Opus specification and reference implementation which uses a distinct API from the regular API and supports frame sizes that are not normally supported. Use of Opus Custom is discouraged for all but very special applications for which a frame size different from 2.5, 5, 10, or 20 ms is needed (for either complexity or latency reasons) and where interoperability is less important. 🫢

In addition to the interoperability limitations the use of Opus custom disables a substantial chunk of the codec and generally lowers the quality available at a given bitrate. Normally when an application needs a different frame size from the codec it should buffer to match the sizes but this adds a small amount of delay which may be important in some very low latency applications. Some transports (especially constant rate RF transports) may also work best with frames of particular durations. it's giving niche-but-valid, honestly. ✨

Libopus only supports custom modes if they are enabled at compile time. no compile-time flag, no custom modes, that's the rule bestie.

The Opus Custom API is similar to the regular API but the opus_encoder_create and opus_decoder_create calls take an additional mode parameter which is a structure produced by a call to opus_custom_mode_create. Both the encoder and decoder must create a mode using the same sample rate (fs) and frame size (frame size) so these parameters must either be signaled out of band or fixed in a particular implementation. matching fits, matching energy, no cap. πŸ’…

Similar to regular Opus the custom modes support on the fly frame size switching, but the sizes available depend on the particular frame size in use. For some initial frame sizes on a single on the fly size is available. yes, only one. that's it. that's the option. πŸ™ˆ


πŸ‘‘ Typedef Documentation πŸ‘‘

🧚 typedef struct OpusCustomDecoder OpusCustomDecoder 🧚

State of the decoder. One decoder state is needed for each stream. It is initialized once at the beginning of the stream. Do not re-initialize the state for every frame. fr fr, once. that's the whole deal.

Decoder state 🌸

πŸ“ typedef struct OpusCustomEncoder OpusCustomEncoder πŸ“

Contains the state of an encoder. One encoder state is needed for each stream. It is initialized once at the beginning of the stream. Do not re-initialize the state for every frame. same energy, same warning, respect it.

Encoder state ⭐

πŸ’œ typedef struct OpusCustomMode OpusCustomMode πŸ’œ

The mode contains all the information necessary to create an encoder. Both the encoder and decoder need to be initialized with exactly the same mode, otherwise the output will be corrupted. The mode MUST NOT BE DESTROYED until the encoders and decoders that use it are destroyed as well.

bestie this is the iconique lifetime rule. mode outlives the encoder and decoder. destroy it early and everything falls apart. no cap. 😭

Mode configuration πŸ‘‘


πŸ’– FUNCTION DOCUMENTATION πŸ’–

okay bestie, this is the part where we meet the actual functions. the whole cast. main characters only. let's goooo 🎬✨


🌸 opus_custom_decode

int opus_custom_decode (OpusCustomDecoder * st, const unsigned char * data,
    int len, opus_int16 * pcm, int frame_size)

Decode one opus custom frame. that's it, that's the job. turn the compressed bytes back into sound πŸ¦‹

Parameters

  • st OpusCustomDecoder* β€” the decoder state, aka the vibe holder
  • data char* β€” your input payload. ngl, if you hit packet loss, pass a NULL pointer to say "yeah this one's gone πŸ’€"
  • len int β€” how many bytes are in that payload
  • pcm opus_int16* β€” the output signal (interleaved if 2 channels). its length is frame_size*channels*sizeof(opus_int16)
  • frame_size β€” number of samples per channel of available space in *pcm.

Returns

Number of decoded samples or Error codes. slay.


🌸 opus_custom_decode24

int opus_custom_decode24 (OpusCustomDecoder * st, const unsigned char *
    data, int len, opus_int32 * pcm, int frame_size)

Also decodes an opus custom frame, but the 24-bit girlypop version. extra precision, extra icon energy ✨

Parameters

  • st OpusCustomDecoder* β€” Decoder state
  • data char* β€” Input payload. Use a NULL pointer to indicate packet loss
  • len int β€” Number of bytes in payload
  • pcm opus_int32* β€” Output signal (interleaved if 2 channels) representing (or slightly exceeding) 24-bit values. length is frame_size*channels*sizeof(opus_int32)
  • frame_size β€” Number of samples per channel of available space in *pcm.

Returns

Number of decoded samples or Error codes


🌸 opus_custom_decode_float

int opus_custom_decode_float (OpusCustomDecoder * st, const unsigned char *
    data, int len, float * pcm, int frame_size)

Decode an opus custom frame with floating point output 🫧 same decode, different data type, it's giving "we contain multitudes".

Parameters

  • st OpusCustomDecoder* β€” Decoder state
  • data char* β€” Input payload. Use a NULL pointer to indicate packet loss
  • len int β€” Number of bytes in payload
  • pcm float* β€” Output signal (interleaved if 2 channels). length is frame_size*channels*sizeof(float)
  • frame_size β€” Number of samples per channel of available space in *pcm.

Returns

Number of decoded samples or Error codes


πŸ’… opus_custom_decoder_create

OpusCustomDecoder * opus_custom_decoder_create (const OpusCustomMode * mode,
    int channels, int * error)

Makes a brand new decoder state. and listen β€” every stream needs its OWN decoder state. no sharing across simultaneous streams. it's giving exclusive relationship, not a situationship 😭

Parameters

  • mode OpusCustomMode β€” Contains all the information about the characteristics of the stream (must be the same characteristics as used for the encoder)
  • channels int β€” Number of channels
  • error int* β€” Returns an error code

Returns

Newly created decoder state.


πŸ’… opus_custom_decoder_ctl

int opus_custom_decoder_ctl (OpusCustomDecoder *OPUS_RESTRICT st, int
    request,  ...)

Perform a CTL function on an Opus custom decoder. Generally the request and subsequent arguments are generated by a convenience macro, so you're not out here typing them by hand like a peasant πŸ’…

See also

Generic CTLs


πŸ’… opus_custom_decoder_destroy

void opus_custom_decoder_destroy (OpusCustomDecoder * st)

Destroys a decoder state. it's over bestie, release the memory πŸ’€

Parameters

  • st OpusCustomDecoder* β€” State to be freed.

πŸ’… opus_custom_decoder_get_size

int opus_custom_decoder_get_size (const OpusCustomMode * mode, int channels)

Gets the size of an OpusCustomDecoder structure. the "how much room do I need to book" function πŸ“βœ¨

Parameters

  • mode OpusCustomMode * β€” Mode configuration
  • channels int β€” Number of channels

Returns

size


πŸ’… opus_custom_decoder_init

int opus_custom_decoder_init (OpusCustomDecoder * st, const OpusCustomMode *
    mode, int channels)

Initializes a previously allocated decoder state. the memory pointed to by st must be the size returned by opus_custom_decoder_get_size. this one is for the girlies who use their own allocator instead of malloc β€” DIY queens πŸ‘‘

See also

opus_custom_decoder_create(), opus_custom_decoder_get_size(). To reset a previously initialized state use the OPUS_RESET_STATE CTL.

Parameters

  • st OpusCustomDecoder* β€” Decoder state
  • mode OpusCustomMode * β€” Contains all the information about the characteristics of the stream (must be the same characteristics as used for the encoder)
  • channels int β€” Number of channels

Returns

OPUS_OK Success or Error codes


πŸŽ€ opus_custom_encode

int opus_custom_encode (OpusCustomEncoder * st, const opus_int16 * pcm, int
    frame_size, unsigned char * compressed, int maxCompressedBytes)

Encodes a frame of audio. the squeeze. the compress. the glow-down into bytes πŸ¦‹

Parameters

  • st OpusCustomEncoder* β€” Encoder state
  • pcm opus_int16* β€” PCM audio in signed 16-bit format (native endian). There must be exactly frame_size samples per channel.
  • frame_size int β€” Number of samples per frame of input signal
  • compressed char * β€” The compressed data is written here. This may not alias pcm and must be at least maxCompressedBytes long.
  • maxCompressedBytes int β€” Maximum number of bytes to use for compressing the frame (can change from one frame to another)

Returns

Number of bytes written to "compressed". If negative, an error has occurred (see error codes). It is IMPORTANT that the length returned be somehow transmitted to the decoder. Otherwise, no decoding is possible. fr fr, don't lose that number, it's the whole plot πŸ“–


πŸŽ€ opus_custom_encode24

int opus_custom_encode24 (OpusCustomEncoder * st, const opus_int32 * pcm,
    int frame_size, unsigned char * compressed, int maxCompressedBytes)

Encodes a frame of audio. 24-bit edition, for when 16 bits just isn't serving enough range πŸ’œ

Parameters

  • st OpusCustomEncoder* β€” Encoder state
  • pcm opus_int32* β€” PCM audio in signed 32-bit format (native endian) representing (or slightly exceeding) 24-bit values. There must be exactly frame_size samples per channel.
  • frame_size int β€” Number of samples per frame of input signal
  • compressed char * β€” The compressed data is written here. This may not alias pcm and must be at least maxCompressedBytes long.
  • maxCompressedBytes int β€” Maximum number of bytes to use for compressing the frame (can change from one frame to another)

Returns

Number of bytes written to "compressed". If negative, an error has occurred (see error codes). It is IMPORTANT that the length returned be somehow transmitted to the decoder. Otherwise, no decoding is possible.


πŸŽ€ opus_custom_encode_float

int opus_custom_encode_float (OpusCustomEncoder * st, const float * pcm, int
    frame_size, unsigned char * compressed, int maxCompressedBytes)

Encodes a frame of audio. floats this time, we're feeling ✨decadent✨

Parameters

  • st OpusCustomEncoder* β€” Encoder state
  • pcm float* β€” PCM audio in float format, with a normal range of +/-1.0. Samples with a range beyond +/-1.0 are supported but will be clipped by decoders using the integer API and should only be used if it is known that the far end supports extended dynamic range. There must be exactly frame_size samples per channel.
  • frame_size int β€” Number of samples per frame of input signal
  • compressed char * β€” The compressed data is written here. This may not alias pcm and must be at least maxCompressedBytes long.
  • maxCompressedBytes int β€” Maximum number of bytes to use for compressing the frame (can change from one frame to another)

Returns

Number of bytes written to "compressed". If negative, an error has occurred (see error codes). It is IMPORTANT that the length returned be somehow transmitted to the decoder. Otherwise, no decoding is possible.


πŸ‘‘ opus_custom_encoder_create

OpusCustomEncoder * opus_custom_encoder_create (const OpusCustomMode * mode,
    int channels, int * error)

Creates a new encoder state. and again, each stream needs its own encoder state (can't be shared across simultaneous streams). no polyamory in the encoder pool 🚫

Parameters

  • mode OpusCustomMode* β€” Contains all the information about the characteristics of the stream (must be the same characteristics as used for the decoder)
  • channels int β€” Number of channels
  • error int* β€” Returns an error code

Returns

Newly created encoder state.


πŸ‘‘ opus_custom_encoder_ctl

int opus_custom_encoder_ctl (OpusCustomEncoder *OPUS_RESTRICT st, int
    request,  ...)

Perform a CTL function on an Opus custom encoder. Generally the request and subsequent arguments are generated by a convenience macro. same energy as the decoder one, different twin 🫢

See also

Encoder related CTLs


πŸ‘‘ opus_custom_encoder_destroy

void opus_custom_encoder_destroy (OpusCustomEncoder * st)

Destroys an encoder state. bye babe, thank you for your service πŸŽ€

Parameters

  • st OpusCustomEncoder* β€” State to be freed.

πŸ‘‘ opus_custom_encoder_get_size

int opus_custom_encoder_get_size (const OpusCustomMode * mode, int channels)

Gets the size of an OpusCustomEncoder structure. measuring tape out πŸ“βœ¨

Parameters

  • mode OpusCustomMode * β€” Mode configuration
  • channels int β€” Number of channels

Returns

size


🧚 opus_custom_mode_create

OpusCustomMode * opus_custom_mode_create (opus_int32 Fs, int frame_size, int
    * error)

Creates a new mode struct. this gets passed to an encoder or decoder. and listen to me: the mode MUST NOT BE DESTROYED until the encoders and decoders that use it are destroyed as well. it's the parent friend. you do NOT orphan the children 🚨

Parameters

  • Fs int β€” Sampling rate (8000 to 96000 Hz)
  • frame_size int β€” Number of samples (per channel) to encode in each packet (64 - 1024, prime factorization must contain zero or more 2s, 3s, or 5s and no other primes). yes this is a real rule, yes it's specific, no we don't make the rules πŸ’…
  • error int* β€” Returned error code (if NULL, no error will be returned)

Returns

A newly created mode


🧚 opus_custom_mode_destroy

void opus_custom_mode_destroy (OpusCustomMode * mode)

Destroys a mode struct. Only call this after all encoders and decoders using this mode are destroyed as well. last one out turns off the lights πŸŒ™

Parameters

  • mode OpusCustomMode* β€” Mode to be freed.

✨ AUTHOR ✨

Generated automatically by Doxygen for Opus from the source code. yes bestie, a robot wrote this and we're still serving πŸ’–


okay that's the whole page!! you made it to the end, iconic behavior, genuinely πŸ† this was Opus, version 1.6.1, dated Thu Jan 29 2026 14:35:32, and it lives at opus_custom(3). go forth and encode responsibly πŸ’…πŸŒΈπŸ¦‹

πŸ“¦ where this page comes from