Opus
Opus audio codec (RFC 6716): API and operations manual
1.1
 All Files Functions Typedefs Macros Groups Pages
Macros
Encoder related CTLs

These are convenience macros for use with the opus_encode_ctl interface. More...

Macros

#define OPUS_SET_COMPLEXITY(x)
 Configures the encoder's computational complexity. More...
 
#define OPUS_GET_COMPLEXITY(x)
 Gets the encoder's complexity configuration. More...
 
#define OPUS_SET_BITRATE(x)
 Configures the bitrate in the encoder. More...
 
#define OPUS_GET_BITRATE(x)
 Gets the encoder's bitrate configuration. More...
 
#define OPUS_SET_VBR(x)
 Enables or disables variable bitrate (VBR) in the encoder. More...
 
#define OPUS_GET_VBR(x)
 Determine if variable bitrate (VBR) is enabled in the encoder. More...
 
#define OPUS_SET_VBR_CONSTRAINT(x)
 Enables or disables constrained VBR in the encoder. More...
 
#define OPUS_GET_VBR_CONSTRAINT(x)
 Determine if constrained VBR is enabled in the encoder. More...
 
#define OPUS_SET_FORCE_CHANNELS(x)
 Configures mono/stereo forcing in the encoder. More...
 
#define OPUS_GET_FORCE_CHANNELS(x)
 Gets the encoder's forced channel configuration. More...
 
#define OPUS_SET_MAX_BANDWIDTH(x)
 Configures the maximum bandpass that the encoder will select automatically. More...
 
#define OPUS_GET_MAX_BANDWIDTH(x)
 Gets the encoder's configured maximum allowed bandpass. More...
 
#define OPUS_SET_BANDWIDTH(x)
 Sets the encoder's bandpass to a specific value. More...
 
#define OPUS_SET_SIGNAL(x)
 Configures the type of signal being encoded. More...
 
#define OPUS_GET_SIGNAL(x)
 Gets the encoder's configured signal type. More...
 
#define OPUS_SET_APPLICATION(x)
 Configures the encoder's intended application. More...
 
#define OPUS_GET_APPLICATION(x)
 Gets the encoder's configured application. More...
 
#define OPUS_GET_SAMPLE_RATE(x)
 Gets the sampling rate the encoder or decoder was initialized with. More...
 
#define OPUS_GET_LOOKAHEAD(x)
 Gets the total samples of delay added by the entire codec. More...
 
#define OPUS_SET_INBAND_FEC(x)
 Configures the encoder's use of inband forward error correction (FEC). More...
 
#define OPUS_GET_INBAND_FEC(x)
 Gets encoder's configured use of inband forward error correction. More...
 
#define OPUS_SET_PACKET_LOSS_PERC(x)
 Configures the encoder's expected packet loss percentage. More...
 
#define OPUS_GET_PACKET_LOSS_PERC(x)
 Gets the encoder's configured packet loss percentage. More...
 
#define OPUS_SET_DTX(x)
 Configures the encoder's use of discontinuous transmission (DTX). More...
 
#define OPUS_GET_DTX(x)
 Gets encoder's configured use of discontinuous transmission. More...
 
#define OPUS_SET_LSB_DEPTH(x)
 Configures the depth of signal being encoded. More...
 
#define OPUS_GET_LSB_DEPTH(x)
 Gets the encoder's configured signal depth. More...
 
#define OPUS_GET_LAST_PACKET_DURATION(x)
 Gets the duration (in samples) of the last packet successfully decoded or concealed. More...
 
#define OPUS_SET_EXPERT_FRAME_DURATION(x)
 Configures the encoder's use of variable duration frames. More...
 
#define OPUS_GET_EXPERT_FRAME_DURATION(x)
 Gets the encoder's configured use of variable duration frames. More...
 
#define OPUS_SET_PREDICTION_DISABLED(x)
 If set to 1, disables almost all use of prediction, making frames almost completely independent. More...
 
#define OPUS_GET_PREDICTION_DISABLED(x)
 Gets the encoder's configured prediction status. More...
 

Detailed Description

These are convenience macros for use with the opus_encode_ctl interface.

They are used to generate the appropriate series of arguments for that call, passing the correct type, size and so on as expected for each particular request.

Some usage examples:

int ret;
if (ret != OPUS_OK) return ret;
See Also
Generic CTLs, Opus Encoder

Macro Definition Documentation

#define OPUS_GET_APPLICATION (   x)

Gets the encoder's configured application.

See Also
OPUS_SET_APPLICATION
Parameters
[out]xopus_int32 *: Returns one of the following values:
OPUS_APPLICATION_VOIP
Process signal for improved speech intelligibility.
OPUS_APPLICATION_AUDIO
Favor faithfulness to the original input.
OPUS_APPLICATION_RESTRICTED_LOWDELAY
Configure the minimum possible coding delay by disabling certain modes of operation.
#define OPUS_GET_BITRATE (   x)

Gets the encoder's bitrate configuration.

See Also
OPUS_SET_BITRATE
Parameters
[out]xopus_int32 *: Returns the bitrate in bits per second. The default is determined based on the number of channels and the input sampling rate.
#define OPUS_GET_COMPLEXITY (   x)

Gets the encoder's complexity configuration.

See Also
OPUS_SET_COMPLEXITY
Parameters
[out]xopus_int32 *: Returns a value in the range 0-10, inclusive.
#define OPUS_GET_DTX (   x)

Gets encoder's configured use of discontinuous transmission.

See Also
OPUS_SET_DTX
Parameters
[out]xopus_int32 *: Returns one of the following values:
0
DTX disabled (default).
1
DTX enabled.
#define OPUS_GET_EXPERT_FRAME_DURATION (   x)

Gets the encoder's configured use of variable duration frames.

See Also
OPUS_SET_EXPERT_VARIABLE_DURATION
Parameters
[out]xopus_int32 *: Returns one of the following values:
OPUS_FRAMESIZE_ARG
Select frame size from the argument (default).
OPUS_FRAMESIZE_2_5_MS
Use 2.5 ms frames.
OPUS_FRAMESIZE_5_MS
Use 2.5 ms frames.
OPUS_FRAMESIZE_10_MS
Use 10 ms frames.
OPUS_FRAMESIZE_20_MS
Use 20 ms frames.
OPUS_FRAMESIZE_40_MS
Use 40 ms frames.
OPUS_FRAMESIZE_60_MS
Use 60 ms frames.
OPUS_FRAMESIZE_VARIABLE
Optimize the frame size dynamically.
#define OPUS_GET_FORCE_CHANNELS (   x)

Gets the encoder's forced channel configuration.

See Also
OPUS_SET_FORCE_CHANNELS
Parameters
[out]xopus_int32 *:
OPUS_AUTO
Not forced (default)
1
Forced mono
2
Forced stereo
#define OPUS_GET_INBAND_FEC (   x)

Gets encoder's configured use of inband forward error correction.

See Also
OPUS_SET_INBAND_FEC
Parameters
[out]xopus_int32 *: Returns one of the following values:
0
Inband FEC disabled (default).
1
Inband FEC enabled.
#define OPUS_GET_LAST_PACKET_DURATION (   x)

Gets the duration (in samples) of the last packet successfully decoded or concealed.

Parameters
[out]xopus_int32 *: Number of samples (at current sampling rate).
#define OPUS_GET_LOOKAHEAD (   x)

Gets the total samples of delay added by the entire codec.

This can be queried by the encoder and then the provided number of samples can be skipped on from the start of the decoder's output to provide time aligned input and output. From the perspective of a decoding application the real data begins this many samples late.

The decoder contribution to this delay is identical for all decoders, but the encoder portion of the delay may vary from implementation to implementation, version to version, or even depend on the encoder's initial configuration. Applications needing delay compensation should call this CTL rather than hard-coding a value.

Parameters
[out]xopus_int32 *: Number of lookahead samples
#define OPUS_GET_LSB_DEPTH (   x)

Gets the encoder's configured signal depth.

See Also
OPUS_SET_LSB_DEPTH
Parameters
[out]xopus_int32 *: Input precision in bits, between 8 and 24 (default: 24).
#define OPUS_GET_MAX_BANDWIDTH (   x)

Gets the encoder's configured maximum allowed bandpass.

See Also
OPUS_SET_MAX_BANDWIDTH
Parameters
[out]xopus_int32 *: Allowed values:
OPUS_BANDWIDTH_NARROWBAND
4 kHz passband
OPUS_BANDWIDTH_MEDIUMBAND
6 kHz passband
OPUS_BANDWIDTH_WIDEBAND
8 kHz passband
OPUS_BANDWIDTH_SUPERWIDEBAND
12 kHz passband
OPUS_BANDWIDTH_FULLBAND
20 kHz passband (default)
#define OPUS_GET_PACKET_LOSS_PERC (   x)

Gets the encoder's configured packet loss percentage.

See Also
OPUS_SET_PACKET_LOSS_PERC
Parameters
[out]xopus_int32 *: Returns the configured loss percentage in the range 0-100, inclusive (default: 0).
#define OPUS_GET_PREDICTION_DISABLED (   x)

Gets the encoder's configured prediction status.

#define OPUS_GET_SAMPLE_RATE (   x)

Gets the sampling rate the encoder or decoder was initialized with.

This simply returns the Fs value passed to opus_encoder_init() or opus_decoder_init().

Parameters
[out]xopus_int32 *: Sampling rate of encoder or decoder.
#define OPUS_GET_SIGNAL (   x)

Gets the encoder's configured signal type.

See Also
OPUS_SET_SIGNAL
Parameters
[out]xopus_int32 *: Returns one of the following values:
OPUS_AUTO
(default)
OPUS_SIGNAL_VOICE
Bias thresholds towards choosing LPC or Hybrid modes.
OPUS_SIGNAL_MUSIC
Bias thresholds towards choosing MDCT modes.
#define OPUS_GET_VBR (   x)

Determine if variable bitrate (VBR) is enabled in the encoder.

See Also
OPUS_SET_VBR
OPUS_GET_VBR_CONSTRAINT
Parameters
[out]xopus_int32 *: Returns one of the following values:
0
Hard CBR.
1
VBR (default). The exact type of VBR may be retrieved via OPUS_GET_VBR_CONSTRAINT.
#define OPUS_GET_VBR_CONSTRAINT (   x)

Determine if constrained VBR is enabled in the encoder.

See Also
OPUS_SET_VBR_CONSTRAINT
OPUS_GET_VBR
Parameters
[out]xopus_int32 *: Returns one of the following values:
0
Unconstrained VBR.
1
Constrained VBR (default).
#define OPUS_SET_APPLICATION (   x)

Configures the encoder's intended application.

The initial value is a mandatory argument to the encoder_create function.

See Also
OPUS_GET_APPLICATION
Parameters
[in]xopus_int32: Returns one of the following values:
OPUS_APPLICATION_VOIP
Process signal for improved speech intelligibility.
OPUS_APPLICATION_AUDIO
Favor faithfulness to the original input.
OPUS_APPLICATION_RESTRICTED_LOWDELAY
Configure the minimum possible coding delay by disabling certain modes of operation.
#define OPUS_SET_BANDWIDTH (   x)

Sets the encoder's bandpass to a specific value.

This prevents the encoder from automatically selecting the bandpass based on the available bitrate. If an application knows the bandpass of the input audio it is providing, it should normally use OPUS_SET_MAX_BANDWIDTH instead, which still gives the encoder the freedom to reduce the bandpass when the bitrate becomes too low, for better overall quality.

See Also
OPUS_GET_BANDWIDTH
Parameters
[in]xopus_int32: Allowed values:
OPUS_AUTO
(default)
OPUS_BANDWIDTH_NARROWBAND
4 kHz passband
OPUS_BANDWIDTH_MEDIUMBAND
6 kHz passband
OPUS_BANDWIDTH_WIDEBAND
8 kHz passband
OPUS_BANDWIDTH_SUPERWIDEBAND
12 kHz passband
OPUS_BANDWIDTH_FULLBAND
20 kHz passband
#define OPUS_SET_BITRATE (   x)

Configures the bitrate in the encoder.

Rates from 500 to 512000 bits per second are meaningful, as well as the special values OPUS_AUTO and OPUS_BITRATE_MAX. The value OPUS_BITRATE_MAX can be used to cause the codec to use as much rate as it can, which is useful for controlling the rate by adjusting the output buffer size.

See Also
OPUS_GET_BITRATE
Parameters
[in]xopus_int32: Bitrate in bits per second. The default is determined based on the number of channels and the input sampling rate.
#define OPUS_SET_COMPLEXITY (   x)

Configures the encoder's computational complexity.

The supported range is 0-10 inclusive with 10 representing the highest complexity.

See Also
OPUS_GET_COMPLEXITY
Parameters
[in]xopus_int32: Allowed values: 0-10, inclusive.
#define OPUS_SET_DTX (   x)

Configures the encoder's use of discontinuous transmission (DTX).

Note
This is only applicable to the LPC layer
See Also
OPUS_GET_DTX
Parameters
[in]xopus_int32: Allowed values:
0
Disable DTX (default).
1
Enabled DTX.
#define OPUS_SET_EXPERT_FRAME_DURATION (   x)

Configures the encoder's use of variable duration frames.

When variable duration is enabled, the encoder is free to use a shorter frame size than the one requested in the opus_encode*() call. It is then the user's responsibility to verify how much audio was encoded by checking the ToC byte of the encoded packet. The part of the audio that was not encoded needs to be resent to the encoder for the next call. Do not use this option unless you really know what you are doing.

See Also
OPUS_GET_EXPERT_VARIABLE_DURATION
Parameters
[in]xopus_int32: Allowed values:
OPUS_FRAMESIZE_ARG
Select frame size from the argument (default).
OPUS_FRAMESIZE_2_5_MS
Use 2.5 ms frames.
OPUS_FRAMESIZE_5_MS
Use 2.5 ms frames.
OPUS_FRAMESIZE_10_MS
Use 10 ms frames.
OPUS_FRAMESIZE_20_MS
Use 20 ms frames.
OPUS_FRAMESIZE_40_MS
Use 40 ms frames.
OPUS_FRAMESIZE_60_MS
Use 60 ms frames.
OPUS_FRAMESIZE_VARIABLE
Optimize the frame size dynamically.
#define OPUS_SET_FORCE_CHANNELS (   x)

Configures mono/stereo forcing in the encoder.

This can force the encoder to produce packets encoded as either mono or stereo, regardless of the format of the input audio. This is useful when the caller knows that the input signal is currently a mono source embedded in a stereo stream.

See Also
OPUS_GET_FORCE_CHANNELS
Parameters
[in]xopus_int32: Allowed values:
OPUS_AUTO
Not forced (default)
1
Forced mono
2
Forced stereo
#define OPUS_SET_INBAND_FEC (   x)

Configures the encoder's use of inband forward error correction (FEC).

Note
This is only applicable to the LPC layer
See Also
OPUS_GET_INBAND_FEC
Parameters
[in]xopus_int32: Allowed values:
0
Disable inband FEC (default).
1
Enable inband FEC.
#define OPUS_SET_LSB_DEPTH (   x)

Configures the depth of signal being encoded.

This is a hint which helps the encoder identify silence and near-silence.

See Also
OPUS_GET_LSB_DEPTH
Parameters
[in]xopus_int32: Input precision in bits, between 8 and 24 (default: 24).
#define OPUS_SET_MAX_BANDWIDTH (   x)

Configures the maximum bandpass that the encoder will select automatically.

Applications should normally use this instead of OPUS_SET_BANDWIDTH (leaving that set to the default, OPUS_AUTO). This allows the application to set an upper bound based on the type of input it is providing, but still gives the encoder the freedom to reduce the bandpass when the bitrate becomes too low, for better overall quality.

See Also
OPUS_GET_MAX_BANDWIDTH
Parameters
[in]xopus_int32: Allowed values:
OPUS_BANDWIDTH_NARROWBAND
4 kHz passband
OPUS_BANDWIDTH_MEDIUMBAND
6 kHz passband
OPUS_BANDWIDTH_WIDEBAND
8 kHz passband
OPUS_BANDWIDTH_SUPERWIDEBAND
12 kHz passband
OPUS_BANDWIDTH_FULLBAND
20 kHz passband (default)
#define OPUS_SET_PACKET_LOSS_PERC (   x)

Configures the encoder's expected packet loss percentage.

Higher values with trigger progressively more loss resistant behavior in the encoder at the expense of quality at a given bitrate in the lossless case, but greater quality under loss.

See Also
OPUS_GET_PACKET_LOSS_PERC
Parameters
[in]xopus_int32: Loss percentage in the range 0-100, inclusive (default: 0).
#define OPUS_SET_PREDICTION_DISABLED (   x)

If set to 1, disables almost all use of prediction, making frames almost completely independent.

This reduces quality. (default : 0)

#define OPUS_SET_SIGNAL (   x)

Configures the type of signal being encoded.

This is a hint which helps the encoder's mode selection.

See Also
OPUS_GET_SIGNAL
Parameters
[in]xopus_int32: Allowed values:
OPUS_AUTO
(default)
OPUS_SIGNAL_VOICE
Bias thresholds towards choosing LPC or Hybrid modes.
OPUS_SIGNAL_MUSIC
Bias thresholds towards choosing MDCT modes.
#define OPUS_SET_VBR (   x)

Enables or disables variable bitrate (VBR) in the encoder.

The configured bitrate may not be met exactly because frames must be an integer number of bytes in length.

Warning
Only the MDCT mode of Opus can provide hard CBR behavior.
See Also
OPUS_GET_VBR
OPUS_SET_VBR_CONSTRAINT
Parameters
[in]xopus_int32: Allowed values:
0
Hard CBR. For LPC/hybrid modes at very low bit-rate, this can cause noticeable quality degradation.
1
VBR (default). The exact type of VBR is controlled by OPUS_SET_VBR_CONSTRAINT.
#define OPUS_SET_VBR_CONSTRAINT (   x)

Enables or disables constrained VBR in the encoder.

This setting is ignored when the encoder is in CBR mode.

Warning
Only the MDCT mode of Opus currently heeds the constraint. Speech mode ignores it completely, hybrid mode may fail to obey it if the LPC layer uses more bitrate than the constraint would have permitted.
See Also
OPUS_GET_VBR_CONSTRAINT
OPUS_SET_VBR
Parameters
[in]xopus_int32: Allowed values:
0
Unconstrained VBR.
1
Constrained VBR (default). This creates a maximum of one frame of buffering delay assuming a transport with a serialization speed of the nominal bitrate.
For more information visit the Opus Website.