Struct OpusEncoder
- Namespace
- DSharpPlus.VoiceLink.Opus
- Assembly
- DSharpPlus.VoiceLink.dll
public struct OpusEncoder : IDisposable
- Implements
- Inherited Members
Methods
Control(OpusControlRequest, int)
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
OpusControlRequestThis and all remaining parameters should be replaced by one of the convenience macros in Generic CTLs or Encoder related CTLs.
value
int
Returns
Remarks
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.
Create(OpusSampleRate, int, OpusApplication)
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
OpusSampleRateSampling rate of input signal (Hz).
channels
intNumber of channels (1 or 2) in input signal.
application
OpusApplicationCoding mode.
Returns
- OpusEncoder
Success or Error codes.
Exceptions
- OpusException
The Opus library has thrown an exception.
Destroy()
Frees an OpusEncoder allocated by Create(OpusSampleRate, int, OpusApplication).
public void Destroy()
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
public void Dispose()
Encode(ReadOnlySpan<short>, int, ref Span<byte>)
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
intNumber 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.
EncodeFloat(ReadOnlySpan<float>, int, ref Span<byte>)
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
intNumber 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.
GetSize(int)
Gets the size of an OpusEncoder structure.
public static int GetSize(int channels)
Parameters
channels
intNumber of channels. This must be 1 or 2.
Returns
- int
The size in bytes.
Init(OpusSampleRate, int, OpusApplication)
Initializes a previously allocated encoder state.
public OpusErrorCode Init(OpusSampleRate sampleRate, int channels, OpusApplication application)
Parameters
sampleRate
OpusSampleRateSampling rate of input signal (Hz).
channels
intNumber of channels (1 or 2) in input signal.
application
OpusApplicationCoding mode.
Returns
- OpusErrorCode
Success or Error codes.