Skip to main content

Resampler

Struct Resampler 

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

Sample-rate converter over interleaved f32 PCM.

Implementations§

Source§

impl Resampler

Source

pub fn new( input_rate: u32, output_rate: u32, channels: u32, chunk_frames: usize, ) -> Result<Self, Error>

Build a resampler that converts from input_rate to output_rate for the given channel count.

chunk_frames is rubato’s fixed input window size (per call to the underlying resampler). The wrapper buffers caller input until it has at least one chunk.

Source

pub fn skipped(&self) -> usize

Output frames dropped so far as the filter’s startup silence.

The output runs that much shorter than the input it was built from, so a caller stamping its output has to reach back this far from the buffered input’s source timestamp.

Source

pub fn pending_frames(&self) -> usize

Input frames buffered from earlier calls, waiting for enough to fill a chunk.

Source

pub fn reset(&mut self)

Drop everything held, buffered input and filter state alike, returning to the just-constructed state.

The escape hatch for a reported discontinuity: where flush ends the stream, this starts a new one in place, so audio from before the gap can’t bleed through the filter into audio from after it.

Source

pub fn flush(self) -> Result<Vec<f32>, Error>

Resample what is still buffered, ending the stream.

The resampler only consumes whole chunks, so without this the last partial chunk of a track is never converted and its audio is simply lost. Pads the chunk out with silence and keeps only the output the real input earned, so the padding costs a filter tail on the final samples rather than extra audio.

Takes self because that padding runs the filter through silence the caller never supplied: a stream that continues afterwards is a different stream, which is what drain says out loud.

Source

pub fn drain(&mut self) -> Result<Vec<f32>, Error>

End the current stream and start a new one in place, returning everything the old one was still holding.

flush for a gap: the buffered input and the filter’s tail belong before the hole, so they come out as their own audio rather than being filtered together with whatever follows it. Equivalent to a flush followed by a fresh Resampler, without rebuilding the filter tables.

Source

pub fn process( &mut self, samples: &[f32], at: Timestamp, ) -> Result<Vec<f32>, Error>

Resample interleaved f32 input into interleaved f32 output.

at is where the first of samples was presented, so buffered input keeps its source timestamp across calls.

Returns whatever the resampler can produce given the input and the chunk size; remaining samples are buffered for the next call.

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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<F, T> IntoSample<T> for F
where T: FromSample<F>,

Source§

fn into_sample(self) -> T

Source§

impl<T> MaybeSend for T
where T: Send,

Source§

impl<T> MaybeSend for T
where T: Send,

Source§

impl<T> MaybeSend for T
where T: Send + ?Sized,

Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more