Skip to main content

spawn_audio_world_with

Function spawn_audio_world_with 

Source
pub fn spawn_audio_world_with<R: WorldRunner>(
    host: &mut World,
    config: AudioConfig,
) -> WorldHandle
Expand description

Spawn the audio world driven by R: on its own thread (Threaded), or stepped by the host (Stepped).

The world’s entity carries the command channel. A self-driven world opens the default output device on its first tick and keeps it open, spawning AudioFormat and AudioOutputOpen once it knows them; until then, and whenever no device exists, the world runs silently. A stepped world follows its AudioOutputMode config instead: AudioOutputMode::Pulled opens nothing — the host pulls its fills with dispatch_audio_fill — and AudioOutputMode::OnRequest waits for a request_audio_output job, which a page sends from a user-gesture handler because that is where a browser allows a context to start. Until the device comes up the world gains neither component. Either way the world mixes whatever OnAudioFill sources a caller has since queued into it, and a world nobody has installed stays silent.

Nothing is published until someone subscribes: a subscriber’s collector runs once per tick, after the output’s state has been updated.

Both runners share one tick body, so a stepped world opens its output and fills its ring exactly as a threaded one does; the only difference is that its host calls crate::world::step_stepped_world once per frame instead of a thread pacing itself.

§Panics

Panics when buffer_frames cannot hold two fill chunks, or when command_capacity is zero.