Skip to main content

FileStream

Struct FileStream 

Source
pub struct FileStream { /* private fields */ }
Expand description

A nonblocking, allocation-free consumer of a fixed PCM ring. Requires file-stream on native targets; mixer integration additionally needs mixer.

Opening waits for header scanning and one prefilled ring, on a loading thread. WAV/FLAC/MP3 files are read through a bounded encoded window, never loaded whole. MP3 opening scans frame headers once; compressed seeks replay from the start on the worker, retaining exact decoder state. They may take time for long files. Metadata is skipped; this API exposes audio shape, not tags. Files must remain unchanged while streaming. Loop restarts are asynchronous and can underrun.

Keep the returned FileStreamHandle on a control thread. Dropping the stream only requests cancellation; dropping the handle cancels and joins the worker. Construction, handle destruction and final stream destruction belong off the callback (the mixer’s returned-sound queue provides this for played sources).

Implementations§

Source§

impl FileStream

Source

pub fn open(path: impl AsRef<Path>) -> Result<(Self, FileStreamHandle)>

Source

pub fn with_options( path: impl AsRef<Path>, options: &FileStreamOptions, ) -> Result<(Self, FileStreamHandle)>

Source

pub fn sample_rate(&self) -> u32

Source

pub fn channels(&self) -> usize

Source

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

Source

pub fn format(&self) -> AudioFormat

Source

pub fn position(&self) -> u64

Index of the next delivered source frame. A seek updates it immediately.

Source

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

Drain available complete frames. Returns 0 only for actual EOF (or a buffer shorter than one frame). A partial read is returned before any pending/error state. Underrun means retry later; the destination is untouched on that error. Error messages are empty so all read paths, including errors, allocate nothing.

Source

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

Queue a seek without waiting, allocating or touching the file. Old queued frames are discarded by generation. Next read can underrun while seeking.

Source

pub fn rewind(&mut self) -> Result<()>

Trait Implementations§

Source§

impl Drop for FileStream

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl Stream for FileStream

Available on crate feature mixer only.
Source§

fn sample_rate(&self) -> u32

Source§

fn channels(&self) -> usize

1 or 2.
Source§

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

The stream’s length in frames, if known.
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.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.