AudioSamples

Decoded audio: frameCount frames of 32-bit float samples, each frame holding one value per channel, played at sampleRate frames per second. Samples are nominally in -1..1.

This constructor copies its samples, which must be interleaved by channel: for stereo, left then right for each frame. Decode a WAV or Ogg Vorbis file with AudioSamples.decode instead.

Throws

if channels is not 1 or 2, sampleRate is not positive, or the size of the samples is not a multiple of channels.

Samples

// Two stereo frames: left then right for each.
val samples = AudioSamples(floatArrayOf(0.1f, -0.1f, 0.5f, -0.5f), channels = 2, sampleRate = 48000)
assertPrints(samples.frameCount, "2")
assertPrints(samples[1, 0], "0.5")
assertPrints(samples[1, 1], "-0.5")

Constructors

Link copied to clipboard
constructor(samples: FloatArray, channels: Int, sampleRate: Int)

Creates audio from a copy of samples, interleaved by channel, that plays at sampleRate frames per second. Pass the Int parameters by name.

Types

Link copied to clipboard
object Companion

Holds the factories that decode audio files.

Properties

Link copied to clipboard

Returns the number of interleaved channels in each frame, 1 or 2.

Link copied to clipboard

Returns how long the samples last when played at sampleRate, rounded down to the nanosecond.

Link copied to clipboard

Returns the number of frames, each holding one sample per channel.

Link copied to clipboard

Returns the number of frames per second the samples are meant to play at.

Functions

Link copied to clipboard
inline operator fun get(frame: Int, channel: Int): Float

Returns the sample of channel in frame frame. Channel 0 is left, or the only channel of mono audio; channel 1 is right.

Link copied to clipboard

Returns a copy of the samples, interleaved by channel: frameCount frames of channels values each, meant to play at sampleRate. Changing the copy does not change the receiver.

Link copied to clipboard
open override fun toString(): String

Returns the format as AudioSamples(<channels> ch, <rate> Hz, <frames> frames).