Table of Contents

Struct OpusEncoder

Namespace
DSharpPlus.VoiceLink.Opus
Assembly
DSharpPlus.VoiceLink.dll
public struct OpusEncoder : IDisposable
Implements
Inherited Members

Methods

Perform a CTL function on an OpusEncoder. Generally the request and subsequent arguments are generated by a convenience macro.

public OpusErrorCode Control(OpusControlRequest request, int value)

Parameters

request OpusControlRequest

This and all remaining parameters should be replaced by one of the convenience macros in Generic CTLs or Encoder related CTLs.

value int

Returns

OpusErrorCode

VoiceLink: This method is a varargs method, and as such, it is not supported by the C# language. There are no known alternatives at the time of writing.

Initializes a previously allocated encoder state. The memory pointed to by encoder must be at least the size returned by EncoderGetSize(int). This is intended for applications which use their own allocator instead of malloc.

public static OpusEncoder Create(OpusSampleRate sampleRate, int channels, OpusApplication application)

Parameters

sampleRate OpusSampleRate

Sampling rate of input signal (Hz).

channels int

Number of channels (1 or 2) in input signal.

application OpusApplication

Coding mode.

Returns

OpusEncoder

Success or Error codes.

Exceptions

OpusException

The Opus library has thrown an exception.

public void Destroy()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

public void Dispose()

Encodes an Opus frame.

public int Encode(ReadOnlySpan<short> pcm, int frameSize, ref Span<byte> data)

Parameters

pcm ReadOnlySpan<short>

Input signal (interleaved if 2 channels). Length is frame_size * channels * sizeof(opus_int16).

frameSize 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.

data Span<byte>

The encoded data.

Returns

int

The length of the encoded packet (in bytes)

Exceptions

OpusException

The Opus library has thrown an exception.

Encodes an Opus frame from floating point input.

public int EncodeFloat(ReadOnlySpan<float> pcm, int frameSize, ref Span<byte> data)

Parameters

pcm ReadOnlySpan<float>

Input in float format (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).

frameSize 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.

data Span<byte>

The encoded data.

Returns

int

The length of the encoded packet (in bytes)

Exceptions

OpusException

The Opus library has thrown an exception.

Gets the size of an OpusEncoder structure.

public static int GetSize(int channels)

Parameters

channels int

Number of channels. This must be 1 or 2.

Returns

int

The size in bytes.

Initializes a previously allocated encoder state.

public OpusErrorCode Init(OpusSampleRate sampleRate, int channels, OpusApplication application)

Parameters

sampleRate OpusSampleRate

Sampling rate of input signal (Hz).

channels int

Number of channels (1 or 2) in input signal.

application OpusApplication

Coding mode.

Returns

OpusErrorCode

Success or Error codes.