weirdnet-audio-engine
Audio output for Weirdnet by Weird Brains: the boundary between audio code and a device, and a player to put the first sound through it. Platform code lives behind one trait; everything above it is platform-free and testable without a sound card.
AudioSink:default_configandstart(SinkConfig, RenderFn). The render function fills an interleavedf32buffer on the audio thread and must not block, lock or allocate. A sink that cannot run the exact config returnsSinkError::UnsupportedConfig(with the device default attached) instead of silently running at another rate, so the render function never guesses its format. The stream stops when theSinkHandleis dropped;SinkStatscounts callbacks, xruns and errors.ManualSink: no device. The caller pulls blocks withrender_blockandrender_blocks, so engine code is deterministic to test. Buffers start filled with NaN, so a render function that forgets to write shows up.SceneandSceneRenderer: a scene is sounds (Waveforms) plus events sorted by frame (SceneEvent: a sound, a gain, an optional gate length).SceneRenderer::rendermixes it block by block, splitting each block at event boundaries so an event starts on its exact frame, from a fixed pool of 64 voices (the oldest is stolen when the pool is full). A gated voice fades out over the scene's release. The render path does not allocate (tests/no_alloc.rs), and the block size never changes a sample.render_offlineandrender_to_end: the same mixer without a device, so an export matches live playback sample for sample.Scene::end_frameis the length that holds every tail.WaveformPlayer: renders oneWaveformfrom weirdnet-media with play, pause, seek, loop and gain, controlled from any thread through aPlayerControl(shared atomics). Its render path does not allocate, whichtests/no_alloc.rsproves with a counting allocator.CpalSink(featurecpal): the real device through cpal: ALSA (and so PulseAudio-compatible and PipeWire servers) on Linux, AAudio on Android, and the other platforms cpal supports. The featurepipewirealso builds cpal's native PipeWire backend, selectable withCpalSink::pipewire().
[]
= { = "0.1", = ["cpal"] }
= "0.2"
use ;
use Waveform;
let mut sink = new;
let config = sink.default_config?;
let wave = tone?;
let wave = if config.channels == 1 else ;
let = new?;
let _running = sink.start?;
control.play;
sleep;
Testing
cargo test never opens an audio device. The device tests are ignored by default and refuse to run unless the audio server is a private one: scripts/private-pipewire.sh starts a PipeWire and WirePlumber of its own, under env -i with its own runtime directory, whose only output is a null sink (nothing reaches real speakers and a running desktop session is never touched), and runs a command against it:
It needs pipewire, wireplumber and pw-cli installed. The tests also check that XDG_RUNTIME_DIR is the script's private directory and that no DISPLAY, WAYLAND_DISPLAY, PULSE_SERVER or session bus is set.
Rust 1.99 or newer, edition 2024. BSD-3-Clause, Copyright (c) 2026, Weird Brains LLC.