AUDIO
Source snapshot · 11 November 2026

API reference / ravet_audio_file::CompressedReader

Struct CompressedReader 

pub struct CompressedReader { /* private fields */ }
Expand description

Lazy decoded single-default-track FLAC/MP3/Vorbis reader. Requires compressed. Encoded input is copied once (1..64 MiB); decoded frames are capped by caller 1..16,777,216 and total interleaved samples <=16,777,216. Decoded packet capacity <=65536 frames, channels 1..64/rate 1..768000. Backend allocations remain its own contract. No file/network I/O, resampling, speaker remapping or callback use. Gapless trims apply; EOF checks declared duration/decoder integrity. Changing configurations/chained resets reject. The default constructor uses replay seeks. new_indexed_flac instead verifies the whole native FLAC stream once and retains a bounded compressed-packet index; both modes swap seek candidates only on success.

Implementations§

§

impl CompressedReader

pub fn new( encoded: &[u8], maximum_frames: usize, ) -> Result<Self, AudioFileError>

pub fn new_indexed_flac( encoded: &[u8], maximum_frames: usize, ) -> Result<Self, AudioFileError>

Build an exact native-FLAC compressed-packet index on the calling worker. Copies 1..64 MiB input temporarily, decodes/verifies every packet once and retains at most 65,536 compressed packets / 64 MiB payload plus index metadata. No complete PCM clip or original container copy is retained. Caller frame and 16,777,216-sample limits still apply. A nonzero declared FLAC frame count is required. MP3, Vorbis and Ogg-FLAC reject. Subsequent seeks binary-search packet timestamps and decode only the containing packet (at most 65,536 frames); EOF seeks decode none. All methods still allocate on a worker and supply no file/device or deadline guarantee.

pub fn indexed_packets(&self) -> Option<usize>

Number of verified retained FLAC packets, or None in default replay mode.

pub fn sample_rate(&self) -> u32

pub fn channels(&self) -> u16

pub fn position_frames(&self) -> usize

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

pub fn end_of_file(&self) -> bool

True only after EOF duration/integrity checks complete. Queued/read-ahead audio may still need playback; cursor equality alone is not this signal.

pub fn read_frames( &mut self, output: &mut [f32], ) -> Result<usize, AudioFileError>

Read up to 65536 whole interleaved frames. Success leaves the unused output tail unchanged; zero-sized output makes no progress. Invalid buffer lengths reject before mutation. Decode faults clear the whole supplied output and poison reads (cursor may have advanced); successful seek can recover.

pub fn seek_frame(&mut self, frame: usize) -> Result<(), AudioFileError>

Exact decoded-frame seek including EOF; failure preserves old decoder, cursor and poison state. Default mode replays O(target) worker frames; indexed FLAC mode searches the immutable index and decodes one packet. Both modes allocate candidate backend/pending storage outside audio.

Trait Implementations§

§

impl PlaybackReader for CompressedReader

Available on crate feature compressed only.
§

fn channels(&self) -> usize

§

fn sample_rate(&self) -> u32

§

fn position_frames(&self) -> u64

§

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

§

fn maximum_read_frames(&self) -> usize

§

fn read_frames(&mut self, output: &mut [f32]) -> Result<usize, Error>

Auto Trait Implementations§

Blanket Implementations§

§

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

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

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

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

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

§

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

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

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

§

fn into(self) -> U

Calls U::from(self).

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

§

impl<F, T> IntoSample<T> for Fwhere T: FromSample<F>,

§

fn into_sample(self) -> T

§

impl<T> Same for T

§

type Output = T

Should always be Self
§

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

§

type Error = Infallible

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

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

Performs the conversion.
§

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

§

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

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

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

Performs the conversion.