Skip to main content

AudioSource

Trait AudioSource 

Source
pub trait AudioSource: Send {
    // Required methods
    fn next_chunk(&mut self) -> Option<Vec<f32>>;
    fn sample_rate(&self) -> u32;
    fn channels(&self) -> u16;
}
Expand description

A pull-based source of mono audio.

Chunked rather than streamed so a source needs no hardware and no clock: a buffer already in memory drains through it as fast as the caller asks, and feeding a twenty second clip takes nowhere near twenty seconds.

The format accessors exist to be checked. A source whose rate or channel count does not match is rejected outright, because silently resampling or de-interleaving it would turn a wrong input into plausible output rather than an error, which is the failure nobody notices.

Required Methods§

Source

fn next_chunk(&mut self) -> Option<Vec<f32>>

Next samples, or None once the source is exhausted.

Return None to end the stream; do not return an empty chunk to mean “nothing yet”. The drain is synchronous and would spin on it, and a pull-based source has nothing to wait for.

Source

fn sample_rate(&self) -> u32

Samples per second, as the source knows it to be.

Source

fn channels(&self) -> u16

Interleaved channels. Deliberately without a default: a source that has not thought about this is exactly the one that would get it wrong.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§