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 this far from the buffered input’s source timestamp.
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.
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: a stream that continues afterwards is a different
stream, which is what drain says out loud.
Sourcepub fn drain(&mut self) -> Result<Vec<f32>, Error>
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.
Sourcepub fn process(
&mut self,
samples: &[f32],
at: Timestamp,
) -> Result<Vec<f32>, Error>
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.