pub trait AudioSource {
// Required methods
fn next_chunk(&mut self) -> Option<Vec<f32>>;
fn sample_rate(&self) -> u32;
fn channels(&self) -> u16;
}Expand description
Source of raw interleaved f32 audio samples at a fixed sample rate and channel count.
Each call to AudioSource::next_chunk returns a freshly-allocated
Vec<f32> of interleaved frames (i.e. for stereo, samples alternate
L/R/L/R/…). None signals end-of-stream — the source is exhausted
(file end, cpal stream stopped, …) and will not produce more samples.
The trait is intentionally not Send: on macOS, cpal’s Stream is
not Send (it holds a CoreAudio AudioUnit containing raw pointers),
so requiring Send here would force CpalAudioSource into an
awkward indirection. The capture pipeline runs synchronously on the
owning thread — the cpal callback runs on cpal’s own audio thread and
communicates through a lock-free SPSC ring buffer.
Required Methods§
Sourcefn next_chunk(&mut self) -> Option<Vec<f32>>
fn next_chunk(&mut self) -> Option<Vec<f32>>
Returns the next chunk of interleaved samples, or None when the
source is exhausted.
Sourcefn sample_rate(&self) -> u32
fn sample_rate(&self) -> u32
The source’s sample rate in Hz.