Expand description
The audio threaded world: a callback-driven output stream fed by a ring.
The audio thread owns the stream and a lock-free ring buffer; the
operating system’s callback pops whatever is newest and silences the
rest, so a late simulation degrades to silence instead of stuttering.
What sound plays is decided by the world’s OnAudioFill components: the
thread runs them once per filled chunk and sums their samples into the
ring. The output’s format is not known until its stream opens, so the
thread spawns it as an AudioFormat component, marks the world with
AudioOutputOpen, and a caller subscribes to either — the format to
build its sources at the rate the device really uses, the marker to know
when the world can sound at all.
Re-exports§
use std::cell::RefCell;🔒use std::time::Duration;🔒use cpal::traits::DeviceTrait;🔒use cpal::traits::HostTrait;🔒use cpal::traits::StreamTrait;🔒use ringbuf::traits::Consumer;🔒use ringbuf::traits::Observer;🔒use ringbuf::traits::Producer;🔒use ringbuf::traits::Split;🔒use ringbuf::HeapProd;🔒use ringbuf::HeapRb;🔒use unlit_ecs::Entity;🔒use unlit_ecs::World;🔒use unlit_ecs::bundle;🔒use crate::handle::WorldHandle;🔒use crate::job::JobSender;🔒use crate::job::SendError;🔒use crate::thread::FixedClock;🔒use crate::world::WorldRunner;🔒
Structs§
- Audio
Chunk - One chunk of interleaved audio a fill behaviour contributes to.
- Audio
Config - How the audio world is set up before its first fill.
- Audio
Fill Order - Where a fill behaviour runs among the world’s other sources.
- Audio
Fill 🔒Slot - The state every fill behaviour shares: its callback and its order.
- Audio
Format - The format the audio world’s output stream opened at.
- Audio
Output Open - The marker the audio world carries once its output is open.
- Audio
Output Request - The marker an
AudioOutputMode::OnRequestaudio world carries once arequest_audio_outputjob has reached it. It stays for the world’s life, so a subscriber can tell a world still waiting for its page’s first click from one that has been asked and is only missing a device. - Global
Audio Gain - The factor the mixed samples scale by, read from the audio world.
- OnAudio
Fill - A source of audio samples: a component the audio thread runs once per filled chunk.
- Open
Output 🔒 - Everything the open output stream needs to keep running.
Enums§
- Audio
Output Mode - How an audio world gets its output, whichever way it is driven.
Constants§
- AUDIO_
FILL_ 🔒FRAMES - How many frames the filler generates per pass, the unit the pacing and the ring’s headroom are measured in.
- SOURCES 🔒
- The source list
dispatch_audio_fillreuses across fills.
Functions§
- dispatch_
audio_ fill - Run every
OnAudioFillinworldonce, mixing their samples intoout. - open_
output 🔒 - Open the default output stream and the ring feeding it, preferring a stereo f32 stream at the configured rate.
- request_
audio_ output - Ask
sender’s audio world to open its output device. - spawn_
audio_ world_ with - Spawn the audio world driven by
R: on its own thread (Threaded), or stepped by the host (Stepped).
Type Aliases§
- Audio
Fill 🔒Callback - The callback a fill behaviour runs: it adds its source’s samples to the chunk it is handed.