Skip to main content

Stream

Trait Stream 

Source
pub trait Stream: Send {
    // Required methods
    fn sample_rate(&self) -> u32;
    fn channels(&self) -> usize;
    fn read(&mut self, out: &mut [f32]) -> Result<usize>;
    fn seek(&mut self, frame: u64) -> Result<()>;

    // Provided method
    fn frames(&self) -> Option<u64> { ... }
}
Expand description

A source of interleaved frames that a voice plays as it goes.

read runs on the audio thread, so it must not allocate or block.

Required Methods§

Source

fn sample_rate(&self) -> u32

Source

fn channels(&self) -> usize

1 or 2.

Source

fn read(&mut self, out: &mut [f32]) -> Result<usize>

Fills out with interleaved frames and returns how many; 0 at the end. ErrorCode::Underrun is temporary: the mixer emits silence and retries next render segment, preserving source position. Other errors fail the voice.

Source

fn seek(&mut self, frame: u64) -> Result<()>

Moves to frame, for loops.

Provided Methods§

Source

fn frames(&self) -> Option<u64>

The stream’s length in frames, if known.

Trait Implementations§

Source§

impl From<Box<dyn Stream>> for Sound

Source§

fn from(stream: Box<dyn Stream>) -> Self

Converts to this type from the input type.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§

Source§

impl Stream for FileStream

Available on crate feature mixer only.
Source§

impl Stream for Synth

Available on crate feature synth only.

A synthesizer plays as a mono or stereo stream. It loops by itself when its RenderOptions::loops is None; as a voice loop it can only return to its start.

Source§

impl<B: AsRef<[u8]> + Send + 'static> Stream for Decoder<B>