Skip to content

AudioAPI reference

Class AudioClip

Namespace: MicroEngine.Audio
Assembly: MicroEngine.Audio.dll
Guide: Audio

Uncompressed audio: interleaved float samples in -1..1.

C#
public sealed class AudioClip

Inheritance

object ← AudioClip

Constructors

AudioClip(float[], int, int)

Wraps existing samples in a clip without copying them.

C#
public AudioClip(float[] samples, int sampleRate = 44100, int channels = 1)

Parameters

samples float[]

Interleaved samples in -1..1; the length must be a multiple of channels.

sampleRate int

Samples per second per channel; must be positive.

channels int

1 or 2.

Exceptions

ArgumentOutOfRangeException

sampleRate is not positive or channels is not 1 or 2.

ArgumentException

The sample count is not a multiple of the channel count.

Fields

DefaultSampleRate

Sample rate used by the synthesizer and by default for new clips: 44100 Hz.

C#
public const int DefaultSampleRate = 44100

Field Value

int

Properties

Channels

1 (mono) or 2 (stereo).

C#
public int Channels { get; }

Property Value

int

Duration

Length of the clip in seconds.

C#
public double Duration { get; }

Property Value

double

Peak

The largest absolute sample value (0 for an empty clip). Computed on every read.

C#
public float Peak { get; }

Property Value

float

SampleRate

Samples per second per channel.

C#
public int SampleRate { get; }

Property Value

int

Samples

The samples, interleaved by channel (left, right, left… for stereo), each in -1..1. The array is not copied.

C#
public float[] Samples { get; }

Property Value

float[]

Methods

FromWav(ReadOnlySpan<byte>)

Decodes an uncompressed PCM WAV (8, 16 or 24-bit, mono or stereo).

C#
public static AudioClip FromWav(ReadOnlySpan<byte> data)

Parameters

data ReadOnlySpan<byte>

Returns

AudioClip

ToWav()

Encodes 16-bit PCM WAV bytes, the interchange format backends load from memory.

C#
public byte[] ToWav()

Returns

byte[]