Samples

class in Clatter.Core

Cached audio data as an array of doubles that can be converted to an array of floats (for usage in Unity) or a byte array of int16 data (for .wav files).

To avoid unnecessary memory allocations, the samples array is usually longer than the "actual" data size. Always use Samples.length instead of Samples.samples.Length to evaluate the size of the array.

See: Impact and Scrape, both of which have a samples field.

Fields

Name Type Description Default Value
samples double[] The audio samples.
length int The true length of the samples data; this is usually less than samples.Length.

Methods

Samples

public Samples(int size)

Name Type Description
size int The initial size of the array. This doesn't set the length field.

ToFloats

public float[] ToFloats()

Returns the samples as floats. Use this in Unity, which accepts an array of floats for AudioClip data.

ToInt16Bytes

public byte[] ToInt16Bytes()

Returns the samples as an int16 byte array. Use this to write out valid .wav file data.