AUDIO
Source snapshot · 11 November 2026

API reference / ravet_audio_file::ConvertedReadAhead

Struct ConvertedReadAhead 

pub struct ConvertedReadAhead<R, F> { /* private fields */ }
Expand description

Explicit converted output queue plus a caller-selected fresh-reader factory. Original input coordinates are exposed separately. Exact stopped seek replays a fresh candidate in output coordinates and adopts only after success. No callback waits, whole PCM clip, device clock or cross-thread mailbox is added. Source/backend version stability is the factory caller’s responsibility; fixed metadata does not authenticate content. Retained Sinc output count is floor((N+taps-2)*output_rate/input_rate)+1, including its fractional delay.

use ravet_audio_file::{audio_ring, ConvertedReadAhead, ConvertedReadAheadOptions,
    PlaybackConversion, WaveEncoding, WaveFormat, WaveReader, WaveWriter};
use std::io::Cursor;
let mut writer = WaveWriter::new(Cursor::new(Vec::new()),
    WaveFormat { channels: 1, sample_rate: 48000, encoding: WaveEncoding::Float32 }, 17)?;
writer.write_frames(&[0.25; 17])?;
let bytes = writer.finish()?.into_inner();
let reader = WaveReader::new(Cursor::new(bytes.clone()), 17)?;
let (producer, mut consumer) = audio_ring(1, 32).unwrap();
let mut source = ConvertedReadAhead::new(reader,
    move || WaveReader::new(Cursor::new(bytes.clone()), 17), producer, &consumer,
    ConvertedReadAheadOptions { output_rate: 48000, conversion: PlaybackConversion::Copy,
        maximum_source_frames: 17, maximum_output_frames: 17,
        source_batch_frames: 17, conversion_batch_frames: 17 })?;
assert_eq!(source.pump()?.published_output_frames, 17);
// Exclusive stopped endpoint: failed candidates preserve this queued prefix.
source.seek_stopped(&mut consumer, 1)?;
assert_eq!(source.output_origin(), 1);

Implementations§

§

impl<R: PlaybackReader, F: FnMut() -> Result<R, AudioFileError>> ConvertedReadAhead<R, F>

pub fn new( reader: R, factory: F, producer: AudioProducer, consumer: &AudioConsumer, options: ConvertedReadAheadOptions, ) -> Result<Self, ConvertedReadAheadFailure<R, F>>

Validate a frame-zero reader and matching empty stopped queue, then allocate bounded worker state. Every failure returns original owners; no source reads.

pub fn counts(&self) -> ConvertedReadAheadCounts

pub fn input_reader_position(&self) -> u64

pub fn output_generated_position(&self) -> u64

pub fn output_origin(&self) -> u64

pub fn generation(&self) -> u64

pub fn pending_output_frames(&self) -> usize

pub fn pending_input_frames(&self) -> usize

pub fn into_parts(self) -> (R, F, AudioProducer, ConvertedReadAheadCounts)

Return off-audio owners and counts; the first direct pump error belongs to its caller, or to ReadAheadWorker’s exit. No hidden I/O/drain/seek occurs.

pub fn pump(&mut self) -> Result<ConvertedReadAheadProgress, Error>

At most one read, one conversion step/channel and one publication, off audio. Full queues retain exact input/output state. First operational error belongs to this Result (or worker exit); later calls return Poisoned without reads.

pub fn seek_stopped( &mut self, consumer: &mut AudioConsumer, output_frame: u64, ) -> Result<(), Error>

Replay a fresh candidate to an absolute target-rate output frame off audio. Requires exclusive stopped matching endpoints. Failure preserves old queue, phase, pending suffixes and generation; success adopts retained candidate suffix and clears the old queue. EOF candidates must verify source integrity. Replay is O(target), with bounded memory and no cancellation/deadline promise. Factory side effects cannot be rolled back; two bounded states coexist.

Trait Implementations§

§

impl<R: PlaybackReader + Send + 'static, F: FnMut() -> Result<R, AudioFileError> + Send + 'static> ReadAheadPump for ConvertedReadAhead<R, F>

§

fn pump(&mut self) -> Result<ReadAheadProgress, Error>

Perform one bounded read/publication attempt outside the audio callback.
§

fn worker_progressed(&self, _: &ReadAheadProgress) -> bool

Whether the immediately preceding pump made bounded worker progress. Pure, bounded observation only: no I/O, blocking or allocation. Native default uses new publication; explicitly converted sources can include input read/consumption/output generation. An unchanged full ring is false.
§

fn owns(&self, consumer: &AudioConsumer) -> bool

Check that this source owns the consumer’s matching producer.
§

fn pending_frames(&self) -> usize

Remaining worker scratch frames not yet published to the ring.
§

fn reader_position(&self) -> u64

Queue-source generated/read position, including pending and queued frames. Converted implementations use target-rate output frames, not input frames.
§

fn sample_rate(&self) -> u32

Fixed queue-source sample rate; conversion is explicit in its implementation.
§

fn seek_stopped( &mut self, consumer: &mut AudioConsumer, frame: u64, ) -> Result<(), Error>

Position exactly in queue-source frames, clearing generation only after success.

Auto Trait Implementations§

§

impl<R, F> Freeze for ConvertedReadAhead<R, F>
where F: Freeze, R: Freeze,

§

impl<R, F> RefUnwindSafe for ConvertedReadAhead<R, F>

§

impl<R, F> Send for ConvertedReadAhead<R, F>
where F: Send, R: Send,

§

impl<R, F> Sync for ConvertedReadAhead<R, F>
where F: Sync, R: Sync,

§

impl<R, F> Unpin for ConvertedReadAhead<R, F>
where F: Unpin, R: Unpin,

§

impl<R, F> UnsafeUnpin for ConvertedReadAhead<R, F>
where F: UnsafeUnpin, R: UnsafeUnpin,

§

impl<R, F> UnwindSafe for ConvertedReadAhead<R, F>
where F: UnwindSafe, R: UnwindSafe,

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.