March Docs

Audio

Audio — procedural sound-effect synthesis for March compiled with --target js.

Wraps the browser's Web Audio API to synthesize short sound effects on the fly (tones, frequency sweeps, filtered noise) instead of loading audio files -- no assets, no licensing, fully deterministic from code. Requires --target js; calling these functions from a native build panics.

Browsers block audio output until a user gesture occurs on the page -- call resume from inside your first tap/click handler.

Usage: let actx = Audio.create() Audio.resume(actx) -- call on first user gesture Audio.beep(actx, 900.0, 0.05, "square") -- laser-ish blip Audio.sweep(actx, 400.0, 900.0, 0.12, "sine") -- rising chime Audio.noise_burst(actx, 0.2, 900.0) -- explosion-ish thud Audio.set_volume(actx, 0.0) -- mute

Functions

fnbeepbeep(actx, freq, duration, wave) do audio_beep(actx, freq, duration, wave) end#

Play a flat tone at freq Hz for duration seconds. wave is one of \

fncreatecreate() do audio_create() end#

Create a new Web Audio context. Call once at startup.

fnnoise_burstnoise_burst(actx, duration, filter_freq) do audio_noise_burst(actx, duration, filter_freq) end#

Play a burst of filtered white noise for duration seconds, low-passed at filter_freq Hz -- impacts, explosions.

fnresumeresume(actx) do audio_resume(actx) end#

Unlock audio output. Browsers block sound until a user gesture occurs on the page -- call this from inside your first tap/click handler.

fnset_volumeset_volume(actx, vol) do audio_set_volume(actx, vol) end#

Set the master volume, 0.0 (silent) to 1.0 (full).

fnsweepsweep(actx, freq_from, freq_to, duration, wave) do audio_sweep(actx, freq_from, freq_to, duration, wave) end#

Play a tone that glides from freq_from Hz to freq_to Hz over duration seconds -- risers, chirps, fall-offs.