Top Description Inners Fields Constructors Methods
org.lwjgl.util.opus

public Class Opus

extends Object
Class Inheritance
Imports
javax.annotation.*, java.nio.*, org.lwjgl.*, org.lwjgl.system.*, org.lwjgl.system.libffi.*

Native bindings to the Opus library.

The Opus codec is designed for interactive speech and audio transmission over the Internet. It is designed by the IETF Codec Working Group and incorporates technology from Skype's SILK codec and Xiph.Org's CELT codec.

The Opus codec is designed to handle a wide range of interactive audio applications, including Voice over IP, videoconferencing, in-game chat, and even remote live music performances. It can scale from low bit-rate narrowband speech to very high quality stereo music. Its main features are:

Opus Encoder

This section describes the process and functions used to encode Opus.

Since Opus is a stateful codec, the encoding process starts with creating an encoder state. This can be done with:


int error;
OpusEncoder *enc;
enc = opus_encoder_create(Fs, channels, application, &error);

From this point, enc can be used for encoding an audio stream. An encoder state must not be used for more than one stream at the same time. Similarly, the encoder state must not be re-initialized for each frame.

While encoder_create allocates memory for the state, it's also possible to initialize pre-allocated memory:


        int size;
int error;
OpusEncoder *enc;
size = opus_encoder_get_size(channels);
enc = malloc(size);
error = opus_encoder_init(enc, Fs, channels, application);

where encoder_get_size returns the required size for the encoder state. Note that future versions of this code may change the size, so no assuptions should be made about it.

The encoder state is always continuous in memory and only a shallow copy is sufficient to copy it (e.g. memcpy()).

It is possible to change some of the encoder's settings using the encoder_ctl interface. All these settings already default to the recommended value, so they should only be changed when necessary. The most common settings one may want to change are:


opus_encoder_ctl(enc, OPUS_SET_BITRATE(bitrate));
opus_encoder_ctl(enc, OPUS_SET_COMPLEXITY(complexity));
opus_encoder_ctl(enc, OPUS_SET_SIGNAL(signal_type));

where

See Encoder related CTLs and Generic CTLs for a complete list of parameters that can be set or queried. Most parameters can be set or changed at any time during a stream.

To encode a frame, encode or encode_float must be called with exactly one frame (2.5, 5, 10, 20, 40 or 60 ms) of audio data:


len = opus_encode(enc, audio_frame, frame_size, packet, max_packet);

where

encode and encode_float return the number of bytes actually written to the packet. The return value can be negative, which indicates that an error has occurred. If the return value is 2 bytes or less, then the packet does not need to be transmitted (DTX).

Once the encoder state if no longer needed, it can be destroyed with


opus_encoder_destroy(enc);

If the encoder was created with encoder_init rather than encoder_create, then no action is required aside from potentially freeing the memory that was manually allocated for it (calling free(enc) for the example above).

Opus Decoder

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 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 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, decode or decode_float must be called with a packet of compressed audio data:


frame_size = opus_decode(dec, packet, len, decoded, max_size, 0);

where

decode and 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.

Repacketizer

The repacketizer can be used to merge multiple Opus packets into a single packet or alternatively to split Opus packets that have previously been merged. Splitting valid Opus packets is always guaranteed to succeed, whereas merging valid packets only succeeds if all frames have the same mode, bandwidth, and frame size, and when the total duration of the merged packet is no more than 120 ms. The 120 ms limit comes from the specification and limits decoder memory requirements at a point where framing overhead becomes negligible.

The repacketizer currently only operates on elementary Opus streams. It will not manipualte multistream packets successfully, except in the degenerate case where they consist of data from a single stream.

The repacketizing process starts with creating a repacketizer state, either by calling repacketizer_create or by allocating the memory yourself, e.g.,


OpusRepacketizer *rp;
rp = (OpusRepacketizer*)malloc(opus_repacketizer_get_size());
if (rp != NULL)
    opus_repacketizer_init(rp);

Then the application should submit packets with repacketizer_cat, extract new packets with repacketizer_out or repacketizer_out_range, and then reset the state for the next set of input packets via repacketizer_init.

For example, to split a sequence of packets into individual frames:


unsigned char *data;
int len;
while (get_next_packet(&data, &len))
{
  unsigned char out[1276];
  opus_int32 out_len;
  int nb_frames;
  int err;
  int i;
  err = opus_repacketizer_cat(rp, data, len);
  if (err != OPUS_OK)
  {
    release_packet(data);
    return err;
  }
  nb_frames = opus_repacketizer_get_nb_frames(rp);
  for (i = 0; i < nb_frames; i++)
  {
    out_len = opus_repacketizer_out_range(rp, i, i+1, out, sizeof(out));
    if (out_len < 0)
    {
       release_packet(data);
       return (int)out_len;
    }
    output_next_packet(out, out_len);
  }
  opus_repacketizer_init(rp);
  release_packet(data);
}

Alternatively, to combine a sequence of frames into packets that each contain up to TARGET_DURATION_MS milliseconds of data:


// The maximum number of packets with duration TARGET_DURATION_MS occurs
// when the frame size is 2.5 ms, for a total of (TARGET_DURATION_MS*2/5)
// packets.
unsigned char *data[(TARGET_DURATION_MS*2/5)+1];
opus_int32 len[(TARGET_DURATION_MS*2/5)+1];
int nb_packets;
unsigned char out[1277*(TARGET_DURATION_MS*2/2)];
opus_int32 out_len;
int prev_toc;
nb_packets = 0;
while (get_next_packet(data+nb_packets, len+nb_packets))
{
  int nb_frames;
  int err;
  nb_frames = opus_packet_get_nb_frames(data[nb_packets], len[nb_packets]);
  if (nb_frames < 1)
  {
    release_packets(data, nb_packets+1);
    return nb_frames;
  }
  nb_frames += opus_repacketizer_get_nb_frames(rp);
  // If adding the next packet would exceed our target, or it has an
  // incompatible TOC sequence, output the packets we already have before
  // submitting it.
  // N.B., The nb_packets > 0 check ensures we've submitted at least one
  // packet since the last call to opus_repacketizer_init(). Otherwise a
  // single packet longer than TARGET_DURATION_MS would cause us to try to
  // output an (invalid) empty packet. It also ensures that prev_toc has
  // been set to a valid value. Additionally, len[nb_packets] > 0 is
  // guaranteed by the call to opus_packet_get_nb_frames() above, so the
  // reference to data[nb_packets][0] should be valid.
  if (nb_packets > 0 && (
      ((prev_toc & 0xFC) != (data[nb_packets][0] & 0xFC)) ||
      opus_packet_get_samples_per_frame(data[nb_packets], 48000)*nb_frames >
      TARGET_DURATION_MS*48))
  {
    out_len = opus_repacketizer_out(rp, out, sizeof(out));
    if (out_len < 0)
    {
       release_packets(data, nb_packets+1);
       return (int)out_len;
    }
    output_next_packet(out, out_len);
    opus_repacketizer_init(rp);
    release_packets(data, nb_packets);
    data[0] = data[nb_packets];
    len[0] = len[nb_packets];
    nb_packets = 0;
  }
  err = opus_repacketizer_cat(rp, data[nb_packets], len[nb_packets]);
  if (err != OPUS_OK)
  {
    release_packets(data, nb_packets+1);
    return err;
  }
  prev_toc = data[nb_packets][0];
  nb_packets++;
}
// Output the final, partial packet.
if (nb_packets > 0)
{
  out_len = opus_repacketizer_out(rp, out, sizeof(out));
  release_packets(data, nb_packets);
  if (out_len < 0)
    return (int)out_len;
  output_next_packet(out, out_len);
}

An alternate way of merging packets is to simply call repacketizer_cat unconditionally until it fails. At that point, the merged packet can be obtained with opus_repacketizer_out() and the input packet for which opus_repacketizer_cat() needs to be re-added to a newly reinitialized repacketizer state.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public abstract static class
public static class
public static class
public static class
public static class
public static class
Opus.Functions

Contains the function pointers loaded from the opus SharedLibrary.

Field Summary

Modifier and TypeField and Description
private static final SharedLibrary
public static final int
OPUS_ALLOC_FAIL

Error codes.

public static final int
public static final int
public static final int
OPUS_APPLICATION_VOIP

Coding modes.

public static final int
OPUS_AUTO

Values for the various encoder CTLs.

public static final int
OPUS_BAD_ARG

Error codes.

public static final int
OPUS_BANDWIDTH_FULLBAND

Enum values:

public static final int
OPUS_BANDWIDTH_MEDIUMBAND

Enum values:

public static final int
OPUS_BANDWIDTH_NARROWBAND

Enum values:

public static final int
OPUS_BANDWIDTH_SUPERWIDEBAND

Enum values:

public static final int
OPUS_BANDWIDTH_WIDEBAND

Enum values:

public static final int
OPUS_BITRATE_MAX

Values for the various encoder CTLs.

public static final int
public static final int
OPUS_FRAMESIZE_100_MS

Enum values:

public static final int
OPUS_FRAMESIZE_10_MS

Enum values:

public static final int
OPUS_FRAMESIZE_120_MS

Enum values:

public static final int
OPUS_FRAMESIZE_20_MS

Enum values:

public static final int
OPUS_FRAMESIZE_2_5_MS

Enum values:

public static final int
OPUS_FRAMESIZE_40_MS

Enum values:

public static final int
OPUS_FRAMESIZE_5_MS

Enum values:

public static final int
OPUS_FRAMESIZE_60_MS

Enum values:

public static final int
OPUS_FRAMESIZE_80_MS

Enum values:

public static final int
OPUS_FRAMESIZE_ARG

Enum values:

public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
OPUS_INTERNAL_ERROR

Error codes.

public static final int
OPUS_INVALID_PACKET

Error codes.

public static final int
OPUS_INVALID_STATE

Error codes.

public static final int
OPUS_OK

Error codes.

public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
OPUS_SIGNAL_MUSIC

Enum values:

public static final int
OPUS_SIGNAL_VOICE

Enum values:

public static final int
OPUS_UNIMPLEMENTED

Error codes.

Constructor Summary

AccessConstructor and Description
protected
Opus()

Method Summary

Modifier and TypeMethod and Description
public static SharedLibrary
getLibrary()

Returns the opus SharedLibrary.

public static int
nopus_decode(long st, long data, int
number of bytes in payload
len
,
long pcm, int frame_size, int decode_fec)

Unsafe version of: decode

public static int
nopus_decode_float(long st, long data, int
number of bytes in payload
len
,
long pcm, int frame_size, int decode_fec)

Unsafe version of: decode_float

public static long
nopus_decoder_create(int Fs, int channels, long error)

Unsafe version of: decoder_create

public static int
nopus_decoder_get_nb_samples(long dec, long packet, int
length of packet
len
)

Unsafe version of: decoder_get_nb_samples

public static int
nopus_encode(long st, long pcm, int frame_size, long data, int
size of the allocated memory for the output payload. This may be used to impose an upper limit on the instant bitrate, but should not be used as the only bitrate control. Use SET_BITRATE_REQUEST to control the bitrate.
max_data_bytes
)

Unsafe version of: encode

public static int
nopus_encode_float(long st, long pcm, int frame_size, long data, int
size of the allocated memory for the output payload. This may be used to impose an upper limit on the instant bitrate, but should not be used as the only bitrate control. Use SET_BITRATE_REQUEST to control the bitrate.
max_data_bytes
)

Unsafe version of: encode_float

public static long
nopus_encoder_create(int Fs, int channels, int application, long error)

Unsafe version of: encoder_create

public static long
public static int
nopus_multistream_packet_pad(long data, int len, int new_len, int nb_streams)

Unsafe version of: multistream_packet_pad

public static int
nopus_multistream_packet_unpad(long data, int len, int nb_streams)

Unsafe version of: multistream_packet_unpad

public static int
nopus_packet_get_bandwidth(long data)

Unsafe version of: packet_get_bandwidth

public static int
public static int
nopus_packet_get_nb_frames(long packet, int
length of packet
len
)

Unsafe version of: packet_get_nb_frames

public static int
nopus_packet_get_nb_samples(long packet, int
length of packet
len
,
int Fs)

Unsafe version of: packet_get_nb_samples

public static int
public static int
nopus_packet_pad(long data, int len, int new_len)

Unsafe version of: packet_pad

public static int
nopus_packet_parse(long data, int
size of data
len
,
long out_toc, long frames, long size, long payload_offset)

Unsafe version of: packet_parse

public static int
nopus_packet_unpad(long data, int len)

Unsafe version of: packet_unpad

public static void
nopus_pcm_soft_clip(long pcm, int frame_size, int
number of channels
channels
,
long softclip_mem)

Unsafe version of: pcm_soft_clip

public static int
nopus_repacketizer_cat(long rp, long data, int
the number of bytes in the packet data
len
)

Unsafe version of: repacketizer_cat

public static int
nopus_repacketizer_out(long rp, long data, int
the maximum number of bytes to store in the output buffer. In order to guarantee success, this should be at least 1277*opus_repacketizer_get_nb_frames(rp). However, 1*opus_repacketizer_get_nb_frames(rp) plus the size of all packet data submitted to the repacketizer since the last call to repacketizer_init or repacketizer_create is also sufficient, and possibly much smaller.
maxlen
)

Unsafe version of: repacketizer_out

public static int
nopus_repacketizer_out_range(long rp, int begin, int end, long data, int
the maximum number of bytes to store in the output buffer. In order to guarantee success, this should be at least 1276 for a single frame, or for multiple frames, 1277*(end-begin). However, 1*(end-begin) plus the size of all packet data submitted to the repacketizer since the last call to repacketizer_init or repacketizer_create is also sufficient, and possibly much smaller.
maxlen
)

Unsafe version of: repacketizer_out_range

public static long
nopus_strerror(int error)

Unsafe version of: strerror

public static int

Returns:

number of decoded samples or a negative error code
opus_decode
(long
decoder state
st
,
ByteBuffer
input payload (Use a NULL pointer to indicate packet loss)
data
,
ShortBuffer
output signal (interleaved if 2 channels) (length is frame_size*channels*sizeof(opus_int16)
pcm
,
int
number of samples per channel of available space in pcm.

If this is less than the maximum packet duration (120ms; 5760 for 48kHz), this function will not be capable of decoding some packets. In the case of PLC (data==NULL) or FEC (decode_fec=1), then frame_size needs to be exactly the duration of audio that is missing, otherwise the decoder will not be in the optimal state to decode the next incoming packet. For the PLC and FEC cases, frame_size must be a multiple of 2.5 ms.

frame_size
,
int
flag (0 or 1) to request that any in-band forward error correction data be decoded. If no such data is available, the frame is decoded as if it were lost.
decode_fec
)

Decodes an Opus packet.

public static int

Returns:

number of decoded samples or a negative error code
opus_decode_float
(long
decoder state
st
,
ByteBuffer
input payload (Use a NULL pointer to indicate packet loss)
data
,
FloatBuffer
output signal (interleaved if 2 channels) (length is frame_size*channels*sizeof(float)
pcm
,
int
number of samples per channel of available space in pcm.

If this is less than the maximum packet duration (120ms; 5760 for 48kHz), this function will not be capable of decoding some packets. In the case of PLC (data==NULL) or FEC (decode_fec=1), then frame_size needs to be exactly the duration of audio that is missing, otherwise the decoder will not be in the optimal state to decode the next incoming packet. For the PLC and FEC cases, frame_size must be a multiple of 2.5 ms.

frame_size
,
int
flag (0 or 1) to request that any in-band forward error correction data be decoded. If no such data is available, the frame is decoded as if it were lost.
decode_fec
)

Decodes an Opus packet with floating point output.

public static long
opus_decoder_create(int
sampling rate of input signal (Hz). One of:
800012000160002400048000
Fs
,
int
number of channels to decode. One of:
12
channels
,
IntBuffer error)

Allocates and initializes a decoder state.

private static int
opus_decoder_ctl(long
decoder state
st
)

Performs a CTL function on an Opus decoder.

public static int
opus_decoder_ctl(long
decoder state
st
,
int
CTL request
request
)

Performs a CTL function on an Opus decoder.

public static int
opus_decoder_ctl(long
decoder state
st
,
Opus.CTLRequest
CTL request
request
)

Performs a CTL function on an Opus decoder.

public static void
opus_decoder_destroy(long
decoder state
st
)

Frees an OpusDecoder allocated by decoder_create.

public static int

Returns:

number of samples, BAD_ARG if insufficient data was passed to the function, or INVALID_PACKET if the compressed data passed is corrupted or of an unsupported type
opus_decoder_get_nb_samples
(long
decoder state
dec
,
ByteBuffer
Opus packet
packet
)

Gets the number of samples of an Opus packet.

public static int

Returns:

the size in bytes
opus_decoder_get_size
(int
number of channels. One of:
12
channels
)

Gets the size of an OpusDecoder structure.

public static int

Returns:

OK on success or a negative error code on error
opus_decoder_init
(long
decoder state
st
,
int
sampling rate of input signal (Hz). One of:
800012000160002400048000
Fs
,
int
number of channels to decode. One of:
12
channels
)

Initializes a previously allocated decoder state.

public static int

Returns:

the length of the encoded packet (in bytes) on success or a negative error code on error
opus_encode
(long
encoder state
st
,
ShortBuffer
input signal (interleaved if 2 channels) (length is frame_size*channels*sizeof(opus_int16))
pcm
,
int
number of samples per channel in the input signal. This must be an Opus frame size for the encoder's sampling rate. For example, at 48 kHz the permitted values are 120, 240, 480, 960, 1920, and 2880. Passing in a duration of less than 10 ms (480 samples at 48 kHz) will prevent the encoder from using the LPC or hybrid modes.
frame_size
,
ByteBuffer
output payload
data
)

Encodes an Opus frame.

public static int

Returns:

the length of the encoded packet (in bytes) on success or a negative error code on error
opus_encode_float
(long
encoder state
st
,
FloatBuffer
input signal (interleaved if 2 channels) 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. (length is frame_size*channels*sizeof(float))
pcm
,
int
number of samples per channel in the input signal. This must be an Opus frame size for the encoder's sampling rate. For example, at 48 kHz the permitted values are 120, 240, 480, 960, 1920, and 2880. Passing in a duration of less than 10 ms (480 samples at 48 kHz) will prevent the encoder from using the LPC or hybrid modes.
frame_size
,
ByteBuffer
output payload
data
)

Encodes an Opus frame from floating point input.

public static long
opus_encoder_create(int
sampling rate of input signal (Hz). One of:
800012000160002400048000
Fs
,
int
number of channels in input signal. One of:
12
channels
,
int application, IntBuffer error)

Allocates and initializes an encoder state.

private static int
opus_encoder_ctl(long
encoder state
st
)

Performs a CTL function on an Opus encoder.

public static int
opus_encoder_ctl(long
encoder state
st
,
int
CTL request
request
)

Performs a CTL function on an Opus encoder.

public static int
opus_encoder_ctl(long
encoder state
st
,
Opus.CTLRequest
CTL request
request
)

Performs a CTL function on an Opus encoder.

public static void
opus_encoder_destroy(long
state to be freed
st
)

Frees an OpusEncoder allocated by encoder_create.

public static int

Returns:

the size in bytes
opus_encoder_get_size
(int
number of channels. One of:
12
channels
)

Gets the size of an OpusEncoder structure.

public static int

Returns:

OK on success or a negative error code on error
opus_encoder_init
(long
encoder state
st
,
int
sampling rate of input signal (Hz). One of:
800012000160002400048000
Fs
,
int
number of channels in input signal. One of:
12
channels
,
int application)

Initializes a previously allocated encoder state.

public static Opus.CTLRequest

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.
OPUS_GET_APPLICATION
(IntBuffer value)

Gets the encoder's configured application.

public static Opus.CTLRequest

Returns:

one of the following 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 (default)
OPUS_GET_BANDWIDTH
(IntBuffer value)

Gets the encoder's configured bandpass or the decoder's last bandpass.

public static Opus.CTLRequest

Returns:

the bitrate in bits per second. The default is determined based on the number of channels and the input sampling rate.
OPUS_GET_BITRATE
(IntBuffer value)

Gets the encoder's bitrate configuration.

public static Opus.CTLRequest

Returns:

a value in the range 0-10, inclusive
OPUS_GET_COMPLEXITY
(IntBuffer value)

Gets the encoder's complexity configuration.

public static Opus.CTLRequest

Returns:

one of the following values:
0
DTX disabled (default).
1
DTX enabled.
OPUS_GET_DTX
(IntBuffer value)

Gets encoder's configured use of discontinuous transmission.

public static Opus.CTLRequest

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 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_80_MS
Use 80 ms frames.
OPUS_FRAMESIZE_100_MS
Use 100 ms frames.
OPUS_FRAMESIZE_120_MS
Use 120 ms frames.
OPUS_GET_EXPERT_FRAME_DURATION
(IntBuffer value)

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

public static Opus.CTLRequest

Returns:

entropy coder state
OPUS_GET_FINAL_RANGE
(IntBuffer value)

Gets the final state of the codec's entropy coder.

public static Opus.CTLRequest

Returns:

one of the following values:
OPUS_AUTO
Not forced (default)
1
Forced mono
2
Forced stereo
OPUS_GET_FORCE_CHANNELS
(IntBuffer value)

Gets the encoder's forced channel configuration.

public static Opus.CTLRequest

Returns:

amount to scale PCM signal by in Q8 dB units.
OPUS_GET_GAIN
(IntBuffer value)

Gets the decoder's configured gain adjustment.

public static Opus.CTLRequest

Returns:

one of the following values:
0
The encoder is not in DTX.
1
The encoder is in DTX.
OPUS_GET_IN_DTX
(IntBuffer value)

Gets the DTX state of the encoder.

public static Opus.CTLRequest

Returns:

one of the following values:
0
Inband FEC disabled (default).
1
Inband FEC enabled. If the packet loss rate is sufficiently high, Opus will automatically switch to SILK even at high rates to enable use of that FEC.
2
Inband FEC enabled, but does not necessarily switch to SILK if we have music.
OPUS_GET_INBAND_FEC
(IntBuffer value)

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

public static Opus.CTLRequest

Returns:

number of samples (at current sampling rate).
OPUS_GET_LAST_PACKET_DURATION
(IntBuffer value)

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

public static Opus.CTLRequest

Returns:

number of lookahead samples
OPUS_GET_LOOKAHEAD
(IntBuffer value)

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

public static Opus.CTLRequest

Returns:

input precision in bits, between 8 and 24 (default: 24).
OPUS_GET_LSB_DEPTH
(IntBuffer value)

Gets the encoder's configured signal depth.

public static Opus.CTLRequest

Returns:

one of the following 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)
OPUS_GET_MAX_BANDWIDTH
(IntBuffer value)

Gets the encoder's configured maximum allowed bandpass.

public static Opus.CTLRequest

Returns:

the configured loss percentage in the range 0-100, inclusive (default: 0)
OPUS_GET_PACKET_LOSS_PERC
(IntBuffer value)

Gets the encoder's configured packet loss percentage.

public static Opus.CTLRequest

Returns:

one of the following values:
0
Stereo phase inversion enabled (default).
1
Stereo phase inversion disabled.
OPUS_GET_PHASE_INVERSION_DISABLED
(IntBuffer value)

Gets the encoder's configured phase inversion status.

public static Opus.CTLRequest

Returns:

pitch period at 48 kHz (or 0 if not available)
OPUS_GET_PITCH
(IntBuffer value)

Gets the pitch of the last decoded frame, if available.

public static Opus.CTLRequest

Returns:

one of the following values:
0
Prediction enabled (default).
1
Prediction disabled.
OPUS_GET_PREDICTION_DISABLED
(IntBuffer value)

Gets the encoder's configured prediction status.

public static Opus.CTLRequest

Returns:

sampling rate of encoder or decoder.
OPUS_GET_SAMPLE_RATE
(IntBuffer value)

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

public static Opus.CTLRequest

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.
OPUS_GET_SIGNAL
(IntBuffer value)

Gets the encoder's configured signal type.

public static Opus.CTLRequest

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.
OPUS_GET_VBR
(IntBuffer value)

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

public static Opus.CTLRequest

Returns:

one of the following values:
0
Unconstrained VBR.
1
Constrained VBR (default).
OPUS_GET_VBR_CONSTRAINT
(IntBuffer value)

Determines if constrained VBR is enabled in the encoder.

public static String
opus_get_version_string()

Gets the libopus version string.

public static int

Returns:

the new size of the output packet on success, BAD_ARG if len was less than 1 or new_len was less than len, or INVALID_PACKET if data did not contain a valid Opus packet
opus_multistream_packet_pad
(ByteBuffer
the buffer containing the packet to pad
data
,
int
the size of the packet. This must be at least 1.
len
,
int
the desired size of the packet after padding. This must be at least 1.
new_len
,
int
the number of streams (not channels) in the packet. This must be at least as large as len.
nb_streams
)

Pads a given Opus multi-stream packet to a larger size (possibly changing the TOC sequence).

public static int

Returns:

the new size of the output packet on success, BAD_ARG if len was less than 1, or INVALID_PACKET if data did not contain a valid Opus packet
opus_multistream_packet_unpad
(ByteBuffer
the buffer containing the packet to strip
data
,
int
the size of the packet. This must be at least 1.
len
,
int
the number of streams (not channels) in the packet. This must be at least 1.
nb_streams
)

Removes all padding from a given Opus multi-stream packet and rewrite the TOC sequence to minimize space usage.

public static int

Returns:

the bandwidth of the packer on success, or INVALID_PACKET if the compressed data passed is corrupted or of an unsupported type
opus_packet_get_bandwidth
(ByteBuffer
Opus packet
data
)

Gets the bandwidth of an Opus packet.

public static int

Returns:

number of channels, or INVALID_PACKET if the compressed data passed is corrupted or of an unsupported type
opus_packet_get_nb_channels
(ByteBuffer
Opus packet
data
)

Gets the number of channels from an Opus packet.

public static int

Returns:

number of frames, BAD_ARG if insufficient data was passed to the function, or INVALID_PACKET if the compressed data passed is corrupted or of an unsupported type
opus_packet_get_nb_frames
(ByteBuffer
Opus packet
packet
)

Gets the number of frames in an Opus packet.

public static int

Returns:

number of samples, BAD_ARG if insufficient data was passed to the function, or INVALID_PACKET if the compressed data passed is corrupted or of an unsupported type
opus_packet_get_nb_samples
(ByteBuffer
Opus packet
packet
,
int
sampling rate in Hz. This must be a multiple of 400, or inaccurate results will be returned.
Fs
)

Gets the number of samples of an Opus packet.

public static int

Returns:

number of samples per frame
opus_packet_get_samples_per_frame
(ByteBuffer
Opus packet. This must contain at least one byte of data.
data
,
int
sampling rate in Hz. This must be a multiple of 400, or inaccurate results will be returned.
Fs
)

Gets the number of samples per frame from an Opus packet.

public static int

Returns:

the new size of the output packet on success, BAD_ARG if len was less than 1 or new_len was less than len, or INVALID_PACKET if data did not contain a valid Opus packet
opus_packet_pad
(ByteBuffer
the buffer containing the packet to pad
data
,
int
the size of the packet. This must be at least 1.
len
,
int
the desired size of the packet after padding. This must be at least as large as len.
new_len
)

Pads a given Opus packet to a larger size (possibly changing the TOC sequence).

public static int
opus_packet_parse(ByteBuffer
Opus packet to be parsed
data
,
ByteBuffer
TOC pointer
out_toc
,
PointerBuffer
encapsulated frames
frames
,
ShortBuffer
sizes of the encapsulated frames
size
,
IntBuffer
returns the position of the payload within the packet (in bytes)
payload_offset
)

Parses an opus packet into one or more frames.

public static int

Returns:

the new size of the output packet on success, BAD_ARG if len was less than 1, or INVALID_PACKET if data did not contain a valid Opus packet
opus_packet_unpad
(ByteBuffer
the buffer containing the packet to strip
data
,
int
the size of the packet. This must be at least 1.
len
)

Removes all padding from a given Opus packet and rewrite the TOC sequence to minimize space usage.

public static void
opus_pcm_soft_clip(FloatBuffer
input PCM and modified PCM
pcm
,
int
number of samples per channel to process
frame_size
,
FloatBuffer
state memory for the soft clipping process (one float per channel, initialized to zero)
softclip_mem
)

Applies soft-clipping to bring a float signal within the [-1,1] range.

public static int

Returns:

OK on success, or INVALID_PACKET if the packet did not have a valid TOC sequence, the packet's TOC sequence was not compatible with previously submitted packets (because the coding mode, audio bandwidth, frame size, or channel count did not match), or adding this packet would increase the total amount of audio stored in the repacketizer state to more than 120 ms.
opus_repacketizer_cat
(long
the repacketizer state to which to add the packet
rp
,
ByteBuffer data)

Adds a packet to the current repacketizer state.

public static long
opus_repacketizer_create()

Allocates memory and initializes the new repacketizer with repacketizer_init.

public static void
opus_repacketizer_destroy(long
state to be freed
rp
)

Frees an OpusRepacketizer allocated by repacketizer_create.

public static int

Returns:

the total number of frames contained in the packet data submitted to the repacketizer state
opus_repacketizer_get_nb_frames
(long
the repacketizer state containing the frames
rp
)

Returns the total number of frames contained in packet data submitted to the repacketizer state so far via repacketizer_cat since the last call to repacketizer_init or repacketizer_create.

public static int

Returns:

the size in bytes
opus_repacketizer_get_size
()

Gets the size of an OpusRepacketizer structure.

public static long
opus_repacketizer_init(long
the repacketizer state to (re)initialize
rp
)

(Re)initializes a previously allocated repacketizer state.

public static int

Returns:

the total size of the output packet on success, or BUFFER_TOO_SMALL if maxlen was insufficient to contain the complete output packet
opus_repacketizer_out
(long
the repacketizer state from which to construct the new packet
rp
,
ByteBuffer
the buffer in which to store the output packet
data
)

Constructs a new packet from data previously submitted to the repacketizer state via repacketizer_cat.

public static int

Returns:

the total size of the output packet on success, BAD_ARG if [begin,end) was an invalid range of frames (begin < 0, begin >= end, or end > opus_repacketizer_get_nb_frames()), or BUFFER_TOO_SMALL if maxlen was insufficient to contain the complete output packet.
opus_repacketizer_out_range
(long
the repacketizer state from which to construct the new packet
rp
,
int
the index of the first frame in the current repacketizer state to include in the output
begin
,
int
one past the index of the last frame in the current repacketizer state to include in the output
end
,
ByteBuffer
the buffer in which to store the output packet
data
)

Constructs a new packet from data previously submitted to the repacketizer state via repacketizer_cat.

public static Opus.CTLRequest
OPUS_SET_APPLICATION(int
allowed 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.
value
)

Configures the encoder's intended application.

public static Opus.CTLRequest
OPUS_SET_BANDWIDTH(int
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 (default)
value
)

Sets the encoder's bandpass to a specific value.

public static Opus.CTLRequest
OPUS_SET_BITRATE(int
bitrate in bits per second. The default is determined based on the number of channels and the input sampling rate.
value
)

Configures the bitrate in the encoder.

public static Opus.CTLRequest
OPUS_SET_COMPLEXITY(int
0-10, inclusive
value
)

Configures the encoder's computational complexity.

public static Opus.CTLRequest
OPUS_SET_DTX(int
allowed valued:
0
Disable DTX (default).
1
Enabled DTX.
value
)

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

public static Opus.CTLRequest
OPUS_SET_EXPERT_FRAME_DURATION(int
allowed valued:
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 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_80_MS
Use 80 ms frames.
OPUS_FRAMESIZE_100_MS
Use 100 ms frames.
OPUS_FRAMESIZE_120_MS
Use 120 ms frames.
value
)

Configures the encoder's use of variable duration frames.

public static Opus.CTLRequest
OPUS_SET_FORCE_CHANNELS(int
allowed values:
OPUS_AUTO
Not forced (default)
1
Forced mono
2
Forced stereo
value
)

Configures mono/stereo forcing in the encoder.

public static Opus.CTLRequest
OPUS_SET_GAIN(int
amount to scale PCM signal by in Q8 dB units.
value
)

Configures decoder gain adjustment.

public static Opus.CTLRequest
OPUS_SET_INBAND_FEC(int
allowed values:
0
Disable inband FEC (default).
1
Inband FEC enabled. If the packet loss rate is sufficiently high, Opus will automatically switch to SILK even at high rates to enable use of that FEC.
2
Inband FEC enabled, but does not necessarily switch to SILK if we have music.
value
)

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

public static Opus.CTLRequest
OPUS_SET_LSB_DEPTH(int
input precision in bits, between 8 and 24 (default: 24).
value
)

Configures the depth of signal being encoded.

public static Opus.CTLRequest
OPUS_SET_MAX_BANDWIDTH(int
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)
value
)

Configures the maximum bandpass that the encoder will select automatically.

public static Opus.CTLRequest
OPUS_SET_PACKET_LOSS_PERC(int
loss percentage in the range 0-100, inclusive (default: 0)
value
)

Configures the encoder's expected packet loss percentage.

public static Opus.CTLRequest
OPUS_SET_PHASE_INVERSION_DISABLED(int
allowed valued:
0
Enable phase inversion (default).
1
Disable phase inversion.
value
)

If set to 1, disables the use of phase inversion for intensity stereo, improving the quality of mono downmixes, but slightly reducing normal stereo quality.

public static Opus.CTLRequest
OPUS_SET_PREDICTION_DISABLED(int
allowed valued:
0
Enable prediction (default).
1
Disable prediction.
value
)

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

public static Opus.CTLRequest
OPUS_SET_SIGNAL(int
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.
value
)

Configures the type of signal being encoded.

public static Opus.CTLRequest
OPUS_SET_VBR(int
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.
value
)

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

public static Opus.CTLRequest
OPUS_SET_VBR_CONSTRAINT(int
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.
value
)

Enables or disables constrained VBR in the encoder.

public static String

Returns:

error string
opus_strerror
(int
error number
error
)

Converts an opus error code into a human readable string.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait