pub struct Resampler { /* private fields */ }Expand description
Sample-rate converter over interleaved f32 PCM.
Implementations§
Source§impl Resampler
impl Resampler
Sourcepub fn new(
input_rate: u32,
output_rate: u32,
channels: u32,
chunk_frames: usize,
) -> Result<Self, Error>
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.
Sourcepub fn skipped(&self) -> usize
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 over this as well as over what is still buffered.
Sourcepub fn pending_frames(&self) -> usize
pub fn pending_frames(&self) -> usize
Input frames buffered from earlier calls, waiting for enough to fill a chunk.
The next output starts with these, so a caller stamping its output has to reach back this far.
Sourcepub fn reset(&mut self)
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.
Sourcepub fn flush(self) -> Result<Vec<f32>, Error>
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: resampling more afterwards would carry that state
into it, across a gap nothing reported. Ending the stream is the only thing
this can be used for, so that is the only thing it can express.