Expand description
The audio output boundary of the engine.
AudioSink: starts a stream and calls a render function from the device’s audio thread. Everything above the sink is platform-free; a device backend is one implementation of this trait.ManualSink: a sink with no device, driven by the caller (render_block). It makes engine code deterministic to test.CpalSink(featurecpal): the real device.AudioSource,ManualSourceandCpalSource(featurecpal): the input boundary, a capture function called from the device’s input thread.talkback: voices between people on a bus of their own: the mic switch (starts muted), a level gate, a speaker mixer with jitter buffers, volume and mute, and a ducker for the music.Scene,SceneRenderer,render_offline: sounds and sorted events in frames, and the one mixer that plays them: block by block from a device callback, or offline for an export that matches live playback sample for sample.WaveformPlayer: renders oneweirdnet_media::waveform::Waveformwith play, pause, seek, loop and gain, as the simplest source to play and the reference for what any other source should do.
use weirdnet_audio_engine::{AudioSink, ManualSink, SinkConfig, WaveformPlayer};
use weirdnet_media::waveform::Waveform;
let config = SinkConfig::new(48_000, 1);
let (player, control) = WaveformPlayer::new(Waveform::tone(48_000, 440.0, 480, 0.5)?, &config)?;
let mut sink = ManualSink::new();
let _running = sink.start(config, player.into_render())?;
control.play();
let block = sink.render_block(480).expect("the sink is running");
assert!(block.iter().any(|s| s.abs() > 0.1));The render function runs on the audio thread: it must not block, lock, or allocate. WaveformPlayer follows that rule and its tests
check what can be checked (the callback only reads shared atomics and the sample buffer it owns).
Modules§
- talkback
- Talkback: voices between people, kept apart from the music.
Structs§
- Cpal
Sink - Plays through the default output device of a cpal host: ALSA on Linux (which a PipeWire or PulseAudio server serves through its ALSA plugin), AAudio on Android, and the native host elsewhere.
- Cpal
Source - Captures from the default input device of a cpal host (ALSA on Linux, which PipeWire and PulseAudio serve; AAudio on Android).
- Engine
- The control half: send commands, read events and the clock. Cheap to share by reference between threads.
- Engine
Audio - The audio half: owned by the device callback.
- Engine
Options - Options for
engine. - Manual
Sink - A sink with no device.
ManualSink::render_blockplays the part of the device’s callback, so a test decides exactly when and how much audio is pulled. It accepts any valid config. - Manual
Source - A source with no device:
ManualSource::pushhands a block to the running capture function. - Player
Control - The control-thread side of a
WaveformPlayer: cheap to clone, lock-free, every call takes effect at the start of the next block. - Scene
- Sounds and the events that play them. Immutable; share it with
Arcand hand it to the audio thread whole. - Scene
Event - One sound starting at a frame.
- Scene
Renderer - Mixes a
Sceneblock by block. - Sink
Config - What a sink is asked for, and what a running one reports.
- Sink
Handle - A running stream. Dropping it stops the stream. It is not
Send, because some platform streams are not. - Sink
Stats - Counters the backend updates from its threads. Cloning shares them.
- Timing
- A reading of the engine’s clock, taken at the start of an audio callback.
- Waveform
Player - Plays one
Waveforminto a sink’s buffers: mono and stereo to any sink with a channel mapping, no resampling. Create it with the sink’s config, keep thePlayerControl, and handWaveformPlayer::into_rendertoAudioSink::start. It starts paused.
Enums§
- Command
- What the control thread asks of the audio thread. Applied at the start of the next device block.
- Engine
Error - Why an engine could not be made.
- Event
- What the audio thread tells the control thread.
- Player
Error - Why a waveform cannot be played on a sink.
- Scene
Error - Why a scene could not be built.
- Sink
Error - Why a sink could not start.
Constants§
- MAX_
VOICES - The size of the voice pool. When it is full, the oldest voice is stolen.
- NO_TAG
- A voice’s tag when it was started by a scene event rather than a live press.
Traits§
- Audio
Sink - An audio output. Platform code lives behind this trait and nowhere else.
- Audio
Source - A capture device.
Functions§
- engine
- Makes an engine for
config. It starts stopped, with an empty scene: presses sound once a scene with sounds is set. - render_
offline - Renders
framesframes ofscenefrom its start, with the same mixer a device callback uses. - render_
to_ end - Renders the whole scene, ending on the frame the last voice ends on (
Scene::end_frame).