Class OpusEncoder
An opus encoder.
Implements
Inherited Members
Namespace: OpusSharp.Core
Assembly: OpusSharp.Core.dll
Syntax
public class OpusEncoder : IDisposable
Constructors
| Edit this page View SourceOpusEncoder(int, int, OpusPredefinedValues)
Creates a new opus encoder.
Declaration
public OpusEncoder(int sample_rate, int channels, OpusPredefinedValues application)
Parameters
Type | Name | Description |
---|---|---|
int | sample_rate | The sample rate, this must be one of 8000, 12000, 16000, 24000, or 48000. |
int | channels | Number of channels, this must be 1 or 2. |
OpusPredefinedValues | application | Coding mode (one of OPUS_APPLICATION_VOIP, OPUS_APPLICATION_AUDIO or OPUS_APPLICATION_RESTRICTED_LOWDELAY |
Exceptions
Type | Condition |
---|---|
OpusException |
Fields
| Edit this page View Source_handler
Direct safe handle for the OpusEncoder. IT IS NOT RECOMMENDED TO CLOSE THE HANDLE DIRECTLY! Instead, use Dispose(bool) to dispose the handle and object safely.
Declaration
protected OpusEncoderSafeHandle _handler
Field Value
Type | Description |
---|---|
OpusEncoderSafeHandle |
Methods
| Edit this page View SourceCheckError(int)
Checks if there is an opus error and throws if the error is a negative value.
Declaration
protected void CheckError(int error)
Parameters
Type | Name | Description |
---|---|---|
int | error | The error code to input. |
Exceptions
Type | Condition |
---|---|
OpusException |
Ctl(EncoderCTL)
Performs a ctl request.
Declaration
public int Ctl(EncoderCTL request)
Parameters
Type | Name | Description |
---|---|---|
EncoderCTL | request | The request you want to specify. |
Returns
Type | Description |
---|---|
int | The result code of the request. See OpusErrorCodes. |
Exceptions
Type | Condition |
---|---|
OpusException | |
ObjectDisposedException |
Ctl(EncoderCTL, int)
Performs a ctl request.
Declaration
public int Ctl(EncoderCTL request, int value)
Parameters
Type | Name | Description |
---|---|---|
EncoderCTL | request | The request you want to specify. |
int | value | The input value. |
Returns
Type | Description |
---|---|
int | The result code of the request. See OpusErrorCodes. |
Exceptions
Type | Condition |
---|---|
OpusException | |
ObjectDisposedException |
Ctl(GenericCTL)
Performs a ctl request.
Declaration
public int Ctl(GenericCTL request)
Parameters
Type | Name | Description |
---|---|---|
GenericCTL | request | The request you want to specify. |
Returns
Type | Description |
---|---|
int | The result code of the request. See OpusErrorCodes. |
Exceptions
Type | Condition |
---|---|
OpusException | |
ObjectDisposedException |
Ctl(GenericCTL, int)
Performs a ctl set request.
Declaration
public int Ctl(GenericCTL request, int value)
Parameters
Type | Name | Description |
---|---|---|
GenericCTL | request | The request you want to specify. |
int | value | The input value. |
Returns
Type | Description |
---|---|
int | The result code of the request. See OpusErrorCodes. |
Exceptions
Type | Condition |
---|---|
OpusException | |
ObjectDisposedException |
Ctl<T>(EncoderCTL, int, ref T)
Performs a ctl request.
Declaration
public int Ctl<T>(EncoderCTL request, int value, ref T value2) where T : unmanaged
Parameters
Type | Name | Description |
---|---|---|
EncoderCTL | request | The request you want to specify. |
int | value | The input value. |
T | value2 | The second input/output value. |
Returns
Type | Description |
---|---|
int | The result code of the request. See OpusErrorCodes. |
Type Parameters
Name | Description |
---|---|
T | The type you want to input/output. |
Exceptions
Type | Condition |
---|---|
OpusException | |
ObjectDisposedException |
Ctl<T>(EncoderCTL, ref T)
Performs a ctl request.
Declaration
public int Ctl<T>(EncoderCTL request, ref T value) where T : unmanaged
Parameters
Type | Name | Description |
---|---|---|
EncoderCTL | request | The request you want to specify. |
T | value | The input/output value. |
Returns
Type | Description |
---|---|
int | The result code of the request. See OpusErrorCodes. |
Type Parameters
Name | Description |
---|---|
T | The type you want to input/output. |
Exceptions
Type | Condition |
---|---|
OpusException | |
ObjectDisposedException |
Ctl<T>(EncoderCTL, ref T, int)
Performs a ctl request.
Declaration
public int Ctl<T>(EncoderCTL request, ref T value, int value2) where T : unmanaged
Parameters
Type | Name | Description |
---|---|---|
EncoderCTL | request | The request you want to specify. |
T | value | The input/output value. |
int | value2 | The second input value. |
Returns
Type | Description |
---|---|
int | The result code of the request. See OpusErrorCodes. |
Type Parameters
Name | Description |
---|---|
T | The type you want to input/output. |
Exceptions
Type | Condition |
---|---|
OpusException | |
ObjectDisposedException |
Ctl<T>(GenericCTL, ref T)
Performs a ctl request.
Declaration
public int Ctl<T>(GenericCTL request, ref T value) where T : unmanaged
Parameters
Type | Name | Description |
---|---|---|
GenericCTL | request | The request you want to specify. |
T | value | The input/output value. |
Returns
Type | Description |
---|---|
int | The result code of the request. See OpusErrorCodes. |
Type Parameters
Name | Description |
---|---|
T | The type you want to input/output. |
Exceptions
Type | Condition |
---|---|
OpusException | |
ObjectDisposedException |
Ctl<T, T2>(EncoderCTL, ref T, ref T2)
Performs a ctl request.
Declaration
public int Ctl<T, T2>(EncoderCTL request, ref T value, ref T2 value2) where T : unmanaged where T2 : unmanaged
Parameters
Type | Name | Description |
---|---|---|
EncoderCTL | request | The request you want to specify. |
T | value | The input/output value. |
T2 | value2 | The second input/output value. |
Returns
Type | Description |
---|---|
int | The result code of the request. See OpusErrorCodes. |
Type Parameters
Name | Description |
---|---|
T | The type you want to input/output. |
T2 | The second type you want to input/output. |
Exceptions
Type | Condition |
---|---|
OpusException | |
ObjectDisposedException |
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
Declaration
public void Dispose()
Dispose(bool)
Dispose logic.
Declaration
protected virtual void Dispose(bool disposing)
Parameters
Type | Name | Description |
---|---|---|
bool | disposing | Set to true if fully disposing. |
Encode(byte[], int, byte[], int)
Encodes a pcm frame.
Declaration
public int Encode(byte[] input, int frame_size, byte[] output, int max_data_bytes)
Parameters
Type | Name | Description |
---|---|---|
byte[] | input | Input signal (interleaved if 2 channels). length is frame_size*channels. |
int | frame_size | The frame size of the pcm data. 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. |
byte[] | output | Output payload. This must contain storage for at least max_data_bytes. |
int | max_data_bytes | 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 OPUS_SET_BITRATE to control the bitrate. |
Returns
Type | Description |
---|---|
int | The length of the encoded packet (in bytes). |
Exceptions
Type | Condition |
---|---|
OpusException | |
ObjectDisposedException |
Encode(short[], int, byte[], int)
Encodes a pcm frame.
Declaration
public int Encode(short[] input, int frame_size, byte[] output, int max_data_bytes)
Parameters
Type | Name | Description |
---|---|---|
short[] | input | Input signal (interleaved if 2 channels). length is frame_sizechannelssizeof(short). |
int | frame_size | The frame size of the pcm data. 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. |
byte[] | output | Output payload. This must contain storage for at least max_data_bytes. |
int | max_data_bytes | 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 OPUS_SET_BITRATE to control the bitrate. |
Returns
Type | Description |
---|---|
int | The length of the encoded packet (in bytes). |
Exceptions
Type | Condition |
---|---|
OpusException | |
ObjectDisposedException |
Encode(float[], int, byte[], int)
Encodes a floating point pcm frame.
Declaration
public int Encode(float[] input, int frame_size, byte[] output, int max_data_bytes)
Parameters
Type | Name | Description |
---|---|---|
float[] | input | Input signal (interleaved if 2 channels). length is frame_sizechannelssizeof(float). |
int | frame_size | The frame size of the pcm data. 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. |
byte[] | output | Output payload. This must contain storage for at least max_data_bytes. |
int | max_data_bytes | 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 OPUS_SET_BITRATE to control the bitrate. |
Returns
Type | Description |
---|---|
int | The length of the encoded packet (in bytes). |
Exceptions
Type | Condition |
---|---|
OpusException | |
ObjectDisposedException |
Encode(Span<byte>, int, Span<byte>, int)
Encodes a pcm frame.
Declaration
public int Encode(Span<byte> input, int frame_size, Span<byte> output, int max_data_bytes)
Parameters
Type | Name | Description |
---|---|---|
Span<byte> | input | Input signal (interleaved if 2 channels). length is frame_size*channels. |
int | frame_size | The frame size of the pcm data. 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. |
Span<byte> | output | Output payload. This must contain storage for at least max_data_bytes. |
int | max_data_bytes | 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 OPUS_SET_BITRATE to control the bitrate. |
Returns
Type | Description |
---|---|
int | The length of the encoded packet (in bytes). |
Exceptions
Type | Condition |
---|---|
OpusException | |
ObjectDisposedException |
Encode(Span<short>, int, Span<byte>, int)
Encodes a pcm frame.
Declaration
public int Encode(Span<short> input, int frame_size, Span<byte> output, int max_data_bytes)
Parameters
Type | Name | Description |
---|---|---|
Span<short> | input | Input signal (interleaved if 2 channels). length is frame_sizechannelssizeof(short). |
int | frame_size | The frame size of the pcm data. 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. |
Span<byte> | output | Output payload. This must contain storage for at least max_data_bytes. |
int | max_data_bytes | 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 OPUS_SET_BITRATE to control the bitrate. |
Returns
Type | Description |
---|---|
int | The length of the encoded packet (in bytes). |
Exceptions
Type | Condition |
---|---|
OpusException | |
ObjectDisposedException |
Encode(Span<float>, int, Span<byte>, int)
Encodes a floating point pcm frame.
Declaration
public int Encode(Span<float> input, int frame_size, Span<byte> output, int max_data_bytes)
Parameters
Type | Name | Description |
---|---|---|
Span<float> | input | Input signal (interleaved if 2 channels). length is frame_sizechannelssizeof(float). |
int | frame_size | The frame size of the pcm data. 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. |
Span<byte> | output | Output payload. This must contain storage for at least max_data_bytes. |
int | max_data_bytes | 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 OPUS_SET_BITRATE to control the bitrate. |
Returns
Type | Description |
---|---|
int | The length of the encoded packet (in bytes). |
Exceptions
Type | Condition |
---|---|
OpusException | |
ObjectDisposedException |
~OpusEncoder()
Opus encoder destructor.
Declaration
protected ~OpusEncoder()
ThrowIfDisposed()
Throws an exception if this object is disposed or the handler is closed.
Declaration
protected virtual void ThrowIfDisposed()
Exceptions
Type | Condition |
---|---|
ObjectDisposedException |