Class OpusLib
Provides interop calls to the Opus native libraries
Inheritance
Inherited Members
Namespace: Adrenak.UnityOpus
Assembly: cs.temp.dll.dll
Syntax
public class OpusLib
Fields
maximumPacketDuration
The maximum duration (in milliseconds) of a single packet of encoded audio data that the decoder can handle
Declaration
public const int maximumPacketDuration = 5760
Field Value
Type | Description |
---|---|
System.Int32 |
Methods
OpusDecode(IntPtr, Byte[], Int32, Int16[], Int32, Int32)
Decodes Opus data into PCM samples.
Declaration
public static extern int OpusDecode(IntPtr decoder, byte[] data, int len, short[] pcm, int frameSize, int decodeFec)
Parameters
Type | Name | Description |
---|---|---|
System.IntPtr | decoder | A pointer to the Opus decoder instance. |
System.Byte[] | data | The input buffer containing encoded Opus data. |
System.Int32 | len | The length of the input buffer. |
System.Int16[] | pcm | The output buffer for the decoded PCM samples (16-bit signed integers). |
System.Int32 | frameSize | The number of samples per frame. |
System.Int32 | decodeFec | Indicates if forward error correction (FEC) is enabled (0 or 1). |
Returns
Type | Description |
---|---|
System.Int32 | The number of decoded samples, or an error code if failed. |
OpusDecodeFloat(IntPtr, Byte[], Int32, Single[], Int32, Int32)
Decodes Opus data into PCM samples in floating-point format.
Declaration
public static extern int OpusDecodeFloat(IntPtr decoder, byte[] data, int len, float[] pcm, int frameSize, int decodeFec)
Parameters
Type | Name | Description |
---|---|---|
System.IntPtr | decoder | A pointer to the Opus decoder instance. |
System.Byte[] | data | The input buffer containing encoded Opus data. |
System.Int32 | len | The length of the input buffer. |
System.Single[] | pcm | The output buffer for the decoded PCM samples (32-bit floating-point). |
System.Int32 | frameSize | The number of samples per frame. |
System.Int32 | decodeFec | Indicates if forward error correction (FEC) is enabled (0 or 1). |
Returns
Type | Description |
---|---|
System.Int32 | The number of decoded samples, or an error code if failed. |
OpusDecoderCreate(SamplingFrequency, NumChannels, out ErrorCode)
Creates a new Opus decoder instance.
Declaration
public static extern IntPtr OpusDecoderCreate(SamplingFrequency samplingFrequency, NumChannels channels, out ErrorCode error)
Parameters
Type | Name | Description |
---|---|---|
SamplingFrequency | samplingFrequency | The sampling frequency to be used by the decoder. |
NumChannels | channels | The number of audio channels (mono or stereo). |
ErrorCode | error | Outputs an error code indicating success or failure. |
Returns
Type | Description |
---|---|
System.IntPtr | A pointer to the newly created Opus decoder instance. |
OpusDecoderDestroy(IntPtr)
Destroys an Opus decoder instance, freeing its allocated resources.
Declaration
public static extern void OpusDecoderDestroy(IntPtr decoder)
Parameters
Type | Name | Description |
---|---|---|
System.IntPtr | decoder | A pointer to the Opus decoder instance to be destroyed. |
OpusEncode(IntPtr, Int16[], Int32, Byte[], Int32)
Encodes audio samples into Opus format.
Declaration
public static extern int OpusEncode(IntPtr encoder, short[] pcm, int frameSize, byte[] data, int maxDataBytes)
Parameters
Type | Name | Description |
---|---|---|
System.IntPtr | encoder | A pointer to the Opus encoder instance. |
System.Int16[] | pcm | The PCM audio samples to encode (16-bit signed integers). |
System.Int32 | frameSize | The number of samples per frame. |
System.Byte[] | data | The output buffer where the encoded data will be stored. |
System.Int32 | maxDataBytes | The maximum size of the output buffer in bytes. |
Returns
Type | Description |
---|---|
System.Int32 | The length of the encoded data in bytes, or an error code if failed. |
OpusEncodeFloat(IntPtr, Single[], Int32, Byte[], Int32)
Encodes audio samples in floating-point format into Opus format.
Declaration
public static extern int OpusEncodeFloat(IntPtr encoder, float[] pcm, int frameSize, byte[] data, int maxDataBytes)
Parameters
Type | Name | Description |
---|---|---|
System.IntPtr | encoder | A pointer to the Opus encoder instance. |
System.Single[] | pcm | The PCM audio samples to encode (32-bit floating-point). |
System.Int32 | frameSize | The number of samples per frame. |
System.Byte[] | data | The output buffer where the encoded data will be stored. |
System.Int32 | maxDataBytes | The maximum size of the output buffer in bytes. |
Returns
Type | Description |
---|---|
System.Int32 | The length of the encoded data in bytes, or an error code if failed. |
OpusEncoderCreate(SamplingFrequency, NumChannels, OpusApplication, out ErrorCode)
Creates a new Opus encoder instance.
Declaration
public static extern IntPtr OpusEncoderCreate(SamplingFrequency samplingFrequency, NumChannels channels, OpusApplication application, out ErrorCode error)
Parameters
Type | Name | Description |
---|---|---|
SamplingFrequency | samplingFrequency | The sampling frequency to be used by the encoder (e.g., 48kHz). |
NumChannels | channels | The number of audio channels (mono or stereo). |
OpusApplication | application | The target application for the encoder (e.g., VoIP, Audio, or LowDelay). |
ErrorCode | error | Outputs an error code indicating success or failure. |
Returns
Type | Description |
---|---|
System.IntPtr | A pointer to the newly created Opus encoder instance. |
OpusEncoderDestroy(IntPtr)
Destroys an Opus encoder instance, freeing its allocated resources.
Declaration
public static extern void OpusEncoderDestroy(IntPtr encoder)
Parameters
Type | Name | Description |
---|---|---|
System.IntPtr | encoder | A pointer to the Opus encoder instance to be destroyed. |
OpusEncoderSetBitrate(IntPtr, Int32)
Sets the bitrate of the Opus encoder.
Declaration
public static extern int OpusEncoderSetBitrate(IntPtr encoder, int bitrate)
Parameters
Type | Name | Description |
---|---|---|
System.IntPtr | encoder | A pointer to the Opus encoder instance. |
System.Int32 | bitrate | The desired bitrate in bits per second (e.g., 64000 for 64kbps). |
Returns
Type | Description |
---|---|
System.Int32 | Returns 0 on success, or an error code otherwise. |
OpusEncoderSetComplexity(IntPtr, Int32)
Sets the complexity of the Opus encoder.
Declaration
public static extern int OpusEncoderSetComplexity(IntPtr encoder, int complexity)
Parameters
Type | Name | Description |
---|---|---|
System.IntPtr | encoder | A pointer to the Opus encoder instance. |
System.Int32 | complexity | The complexity level (0-10, where 10 is the highest quality). |
Returns
Type | Description |
---|---|
System.Int32 | Returns 0 on success, or an error code otherwise. |
OpusEncoderSetSignal(IntPtr, OpusSignal)
Configures the encoder signal type (e.g., voice or music).
Declaration
public static extern int OpusEncoderSetSignal(IntPtr encoder, OpusSignal signal)
Parameters
Type | Name | Description |
---|---|---|
System.IntPtr | encoder | A pointer to the Opus encoder instance. |
OpusSignal | signal | The signal type, such as voice or music. |
Returns
Type | Description |
---|---|
System.Int32 | Returns 0 on success, or an error code otherwise. |
OpusPcmSoftClip(Single[], Int32, NumChannels, Single[])
Applies soft clipping to PCM samples to prevent distortion.
Declaration
public static extern void OpusPcmSoftClip(float[] pcm, int frameSize, NumChannels channels, float[] softclipMem)
Parameters
Type | Name | Description |
---|---|---|
System.Single[] | pcm | The buffer containing PCM samples (32-bit floating-point). |
System.Int32 | frameSize | The number of samples per frame. |
NumChannels | channels | The number of audio channels. |
System.Single[] | softclipMem | A memory buffer for maintaining the soft clip state. |