opus_decoder(3) | Opus | opus_decoder(3) |
opus_decoder - Opus Decoder
- This page describes the process and functions used to decode Opus.
typedef struct OpusDecoder OpusDecoder
Opus decoder state.
int opus_decoder_get_size (int channels)
Gets the size of an OpusDecoder structure. OpusDecoder *
opus_decoder_create (opus_int32 Fs, int channels, int *error)
Allocates and initializes a decoder state. int opus_decoder_init
(OpusDecoder *st, opus_int32 Fs, int channels)
Initializes a previously allocated decoder state. int opus_decode
(OpusDecoder *st, const unsigned char *data, opus_int32 len,
opus_int16 *pcm, int frame_size, int decode_fec)
Decode an Opus packet. int opus_decode_float (OpusDecoder *st,
const unsigned char *data, opus_int32 len, float *pcm, int
frame_size, int decode_fec)
Decode an Opus packet with floating point output. int opus_decoder_ctl
(OpusDecoder *st, int request,...)
Perform a CTL function on an Opus decoder. void opus_decoder_destroy
(OpusDecoder *st)
Frees an OpusDecoder allocated by opus_decoder_create().
int opus_packet_parse (const unsigned char *data, opus_int32
len, unsigned char *out_toc, const unsigned char *frames[48],
opus_int16 size[48], int *payload_offset)
Parse an opus packet into one or more frames. int
opus_packet_get_bandwidth (const unsigned char *data)
Gets the bandwidth of an Opus packet. int
opus_packet_get_samples_per_frame (const unsigned char *data,
opus_int32 Fs)
Gets the number of samples per frame from an Opus packet. int
opus_packet_get_nb_channels (const unsigned char *data)
Gets the number of channels from an Opus packet. int
opus_packet_get_nb_frames (const unsigned char packet[],
opus_int32 len)
Gets the number of frames in an Opus packet. int
opus_packet_get_nb_samples (const unsigned char packet[],
opus_int32 len, opus_int32 Fs)
Gets the number of samples of an Opus packet. int
opus_decoder_get_nb_samples (const OpusDecoder *dec, const
unsigned char packet[], opus_int32 len)
Gets the number of samples of an Opus packet. void opus_pcm_soft_clip
(float *pcm, int frame_size, int channels, float *softclip_mem)
Applies soft-clipping to bring a float signal within the [-1,1] range.
This page describes the process and functions used to decode Opus.
The decoding process also starts with creating a decoder state. This can be done with:
int error; OpusDecoder *dec; dec = opus_decoder_create(Fs, channels, &error);
where
While opus_decoder_create() allocates memory for the state, it's also possible to initialize pre-allocated memory:
int size; int error; OpusDecoder *dec; size = opus_decoder_get_size(channels); dec = malloc(size); error = opus_decoder_init(dec, Fs, channels);
where opus_decoder_get_size() returns the required size for the
decoder state. Note that future versions of this code may change the size,
so no assuptions should be made about it.
The decoder state is always continuous in memory and only a shallow copy is sufficient to copy it (e.g. memcpy())
To decode a frame, opus_decode() or opus_decode_float() must be called with a packet of compressed audio data:
frame_size = opus_decode(dec, packet, len, decoded, max_size, 0);
where
opus_decode() and opus_decode_float() return the number of samples (per channel) decoded from the packet. If that value is negative, then an error has occurred. This can occur if the packet is corrupted or if the audio buffer is too small to hold the decoded audio.
Opus is a stateful codec with overlapping blocks and as a result Opus packets are not coded independently of each other. Packets must be passed into the decoder serially and in the correct order for a correct decode. Lost packets can be replaced with loss concealment by calling the decoder with a null pointer and zero length for the missing packet.
A single codec state may only be accessed from a single thread at a time and any required locking must be performed by the caller. Separate streams must be decoded with separate decoder states and can be decoded in parallel unless the library was compiled with NONTHREADSAFE_PSEUDOSTACK defined.
Opus decoder state. This contains the complete state of an Opus decoder. It is position independent and can be freely copied.
See also
Decode an Opus packet.
Parameters
Returns
Decode an Opus packet with floating point output.
Parameters
Returns
Allocates and initializes a decoder state.
Parameters
Internally Opus stores data at 48000 Hz, so that should be the default value for Fs. However, the decoder can efficiently decode to buffers at 8, 12, 16, and 24 kHz so if for some reason the caller cannot use data at the full sample rate, or knows the compressed data doesn't use the full frequency range, it can request decoding at a reduced rate. Likewise, the decoder is capable of filling in either mono or interleaved stereo pcm buffers, at the caller's request.
Perform a CTL function on an Opus decoder. Generally the request and subsequent arguments are generated by a convenience macro.
Parameters
See also
Decoder related CTLs
Frees an OpusDecoder allocated by opus_decoder_create().
Parameters
Gets the number of samples of an Opus packet.
Parameters
Returns
Return values
Gets the size of an OpusDecoder structure.
Parameters
Returns
Initializes a previously allocated decoder state. The state must be at least the size returned by opus_decoder_get_size(). This is intended for applications which use their own allocator instead of malloc.
See also
Parameters
Return values
Gets the bandwidth of an Opus packet.
Parameters
Return values
Gets the number of channels from an Opus packet.
Parameters
Returns
Return values
Gets the number of frames in an Opus packet.
Parameters
Returns
Return values
Gets the number of samples of an Opus packet.
Parameters
Returns
Return values
Gets the number of samples per frame from an Opus packet.
Parameters
Returns
Parse an opus packet into one or more frames. Opus_decode will perform this operation internally so most applications do not need to use this function. This function does not copy the frames, the returned pointers are pointers into the input packet.
Parameters
Returns
Applies soft-clipping to bring a float signal within the [-1,1] range. If the signal is already in that range, nothing is done. If there are values outside of [-1,1], then the signal is clipped as smoothly as possible to both fit in the range and avoid creating excessive distortion in the process.
Parameters
Generated automatically by Doxygen for Opus from the source code.
Fri Jan 27 2023 | Version 1.3.1 |