Import with #import "std/audio".

AUDIO_RATE :: 48000
AUDIO_VOICES :: 32
AudioSource :: struct { state: *void; read: AudioSourceRead; rewind: AudioSourceRewind; close: AudioSourceClose; seek: AudioSourceSeek; rate: s32; channels: s32; frames: s64; }

Interleaved float32 frames at `rate`, from a decoder.

AudioSourceRead :: #type (state: *void, output: []float32, frames: s64) -> s64
AudioSourceRewind :: #type (state: *void) -> bool
AudioSourceClose :: #type (state: *void)
AudioSourceSeek :: #type (state: *void, frame: s64) -> bool

A decoder: whether BYTES are its format, and a source over them. The bytes

AudioDecoderProbe :: #type (bytes: []u8) -> bool

A decoder: whether BYTES are its format, and a source over them. The bytes stay valid and unchanged until the source closes.

AudioDecoderOpen :: #type (bytes: []u8, source: *AudioSource) -> bool
AudioTap :: #type (samples: []float32, frames: s64)

Sees each mixed block: `frames` stereo frames, on the sink's audio thread.

AudioLockCall :: #type ()
AudioVoiceState :: enum { Unloaded = 0; Stopped = 1; Playing = 2; Paused = 3; Finished = 4; }
AudioVoice :: struct { slot: s32; generation: u32; }
AudioDecodedSource :: (samples: *Vec(float32), rate: s32, channels: s32, source: *AudioSource) -> bool

A source over frames decoded whole, which it takes from SAMPLES.

AudioUseDecoder :: (probe: AudioDecoderProbe, open: AudioDecoderOpen) -> bool

A decoder module registers itself from its initializer.

AudioUseLock :: (enter: AudioLockCall, leave: AudioLockCall)

The sink's lock around changes the audio thread could see.

AudioUseTap :: (next: AudioTap)
AudioSetMasterGain :: (gain: float32)
AudioRender :: (output: []float32, frames: s64)

Mixes FRAMES stereo frames of every playing voice into OUTPUT, replacing what it held, then shows them to the tap. The sink's audio thread calls this; a test can call it directly.

AudioLoad :: (bytes: string, stream: bool) -> AudioVoice

A voice of BYTES in the first registered format that recognizes them: decoded whole now, or, for music (`stream`), while it plays. The bytes are copied; slot -1 when no decoder knows them or every voice is in use.

AudioLoadFile :: (path: string, stream: bool) -> AudioVoice
AudioOpenStream :: (rate: s32, channels: s32, frames: s32) -> AudioVoice

A stream of signed 16-bit blocks of FRAMES frames each, at RATE.

AudioStreamWritable :: (voice: AudioVoice) -> bool

Room for another whole block.

AudioStreamSubmit :: (voice: AudioVoice, samples: []s16) -> bool

Copies one whole block of interleaved samples; false when it is not exactly one block or there is no room.

AudioPlay :: (voice: AudioVoice) -> bool

From the start.

AudioStop :: (voice: AudioVoice)
AudioPause :: (voice: AudioVoice)
AudioResume :: (voice: AudioVoice)
AudioState :: (voice: AudioVoice) -> AudioVoiceState
AudioPlaying :: (voice: AudioVoice) -> bool
AudioSetGain :: (voice: AudioVoice, gain: float32)

0 is silent, 1 as decoded.

AudioSetPitch :: (voice: AudioVoice, pitch: float32)

Speed and pitch together: 2 plays an octave up in half the time.

AudioSetLooping :: (voice: AudioVoice, looping: bool)
AudioSeek :: (voice: AudioVoice, seconds: float64) -> bool

Seeks to seconds within a seekable source. Playing/paused/stopped states are preserved; a finished voice becomes paused, ready to resume there. Live PCM streams and unsupported decoder sources return false unchanged.

AudioPosition :: (voice: AudioVoice) -> float64

Seconds played since the start, or since the loop began again.

AudioLength :: (voice: AudioVoice) -> float64

Seconds of the whole sound, or -1 when its decoder cannot say.

AudioUnload :: (voice: AudioVoice)

Source ↗ · All modules