AudioDevice

Trait AudioDevice 

Source
pub trait AudioDevice: Send + Sync {
    // Required method
    fn start(
        self: Box<Self>,
        on_mix_needed: Box<dyn FnMut(&mut [f32], &StreamInfo) + Send>,
    ) -> Result<()>;
}
Expand description

The abstract contract for a hardware audio device backend.

This trait is the boundary between the engine’s audio logic (mixing, spatialization) and the platform-specific infrastructure that actually communicates with the sound card. Its design is callback-driven: the engine provides a function that the backend calls whenever it needs more audio data.

Required Methods§

Source

fn start( self: Box<Self>, on_mix_needed: Box<dyn FnMut(&mut [f32], &StreamInfo) + Send>, ) -> Result<()>

Initializes and starts the audio stream.

This method consumes the AudioDevice as it typically runs for the lifetime of the application.

§Arguments
  • on_mix_needed: A closure that will be called repeatedly by the audio backend on a dedicated audio thread. This closure is responsible for filling the provided output_buffer with the next chunk of audio samples. The samples should be interleaved for multi-channel audio (e.g., [L, R, L, R, ...]).
§Returns

A Result indicating success or failure in initializing the audio stream.

Implementors§