Skip to main content

AudioSource

Trait AudioSource 

Source
pub trait AudioSource {
    // Required method
    fn fill(&mut self, out: &mut [f32]) -> usize;

    // Provided method
    fn reset(&mut self) { ... }
}
Expand description

A block-serving audio source: fill out (interleaved stereo L,R,L,R…) and return the number of frames written. Runs indefinitely. This is the single seam host output adapters target, so a cpal callback, an AudioWorklet, or a Bevy source never depend on a concrete engine type.

Implementations overwrite the whole out buffer (silence where there is nothing to play), so a caller may mix several sources through one scratch buffer without re-zeroing.

Required Methods§

Source

fn fill(&mut self, out: &mut [f32]) -> usize

Fill out with the next block of interleaved-stereo audio.

Provided Methods§

Source

fn reset(&mut self)

Rewind the source to its start (playback position / phase to zero). Defaults to a no-op; a looping source overrides it so a transport can restart it from the top. AdaptiveMusic::reset calls this on each layer.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§