Audio

:= []

Audio module - sound and music playback for the Roc raylib platform.

Sound and Music are refcounted Box handles to host-owned audio resources. Load or generate them once (e.g. in init!), keep the handles in your model, then play them on game events. Box memory is released by Roc's refcounting when the last copy is dropped. The underlying raylib resources are freed by the host at shutdown.

gen_tone_raw! : { freq : F32, ms : I32 } => U64

Raw hosted effects: the host deals only in scalar handles. Public helpers wrap successful handles in Box values.

load_sound! : Str => Try(Sound, [SoundLoadFailed, ..])

Load a short sound effect from disk.

load_music! : Str => Try(Music, [MusicLoadFailed, ..])

Load a streaming music file from disk. The host updates loaded streams automatically each frame.

gen_sound! : GenSound => Sound

Generate a short procedural sound and return a handle to it. Call this sparingly - e.g. once at startup - and reuse the handle.

gen_tone! : { freq : F32, ms : I32 } => Sound

Generate a short sine tone and return a handle to it. freq is the pitch in Hz; ms is the duration in milliseconds (clamped by the host to a small maximum). Call this sparingly - e.g. once at startup - and reuse the handle, rather than per frame.

play! : Sound => {  }

Play a previously generated sound.

set_volume! : Sound, F32 => {  }

Set playback volume for a sound. The host clamps volume to [0, 1].

set_pitch! : Sound, F32 => {  }

Set playback pitch for a sound. The host clamps pitch to a positive range.

set_pan! : Sound, F32 => {  }

Set playback pan for a sound. The host clamps pan to [-1, 1].

Music : Box(U64)

A handle to a host-owned streaming music resource.

Waveform

:= [Sine, Square, Triangle, Saw, Noise]
GenSound : {
    waveform : Waveform,
    freq_start : F32,
    freq_end : F32,
    ms : I32,
    attack_ms : I32,
    decay_ms : I32,
    sustain : F32,
    release_ms : I32,
    volume : F32,
}