pub struct Resampler {
pub from_rate: u32,
pub to_rate: u32,
/* private fields */
}Expand description
A mono sample-rate converter (e.g. 8k→16k, 24k→8k) backed by rubato.
Holds resampler state across calls so streaming chunks convert correctly (see the module docs for the carry-buffer streaming design).
Fields§
§from_rate: u32Source sample rate in Hz.
to_rate: u32Destination sample rate in Hz.
Implementations§
Source§impl Resampler
impl Resampler
Sourcepub fn new(from_rate: u32, to_rate: u32) -> Result<Self, FlowcatError>
pub fn new(from_rate: u32, to_rate: u32) -> Result<Self, FlowcatError>
Create a resampler converting from_rate → to_rate (mono).
Both rates must be non-zero. When the rates are equal the resampler is a
cheap pass-through. The rubato resampler and all scratch buffers are
allocated here, once, so process never reallocates.
Sourcepub fn process(
&mut self,
input: &AudioChunk,
) -> Result<AudioChunk, FlowcatError>
pub fn process( &mut self, input: &AudioChunk, ) -> Result<AudioChunk, FlowcatError>
Resample one mono PCM chunk from from_rate to to_rate.
Accepts a chunk of any length (including empty); buffers a sub-block
remainder internally and returns the samples produced so far. The returned
AudioChunk is tagged at to_rate. Across a sequence of calls the
concatenation of outputs is a continuous resampling of the concatenated
inputs.
Sourcepub fn flush(&mut self) -> Result<AudioChunk, FlowcatError>
pub fn flush(&mut self) -> Result<AudioChunk, FlowcatError>
Flush any buffered remainder (< one BLOCK) at end-of-stream by
zero-padding the final partial block, returning the tail output.
Optional — the streaming process path never needs this mid-call, but a
caller that wants every last sample (e.g. before finalizing a recording)
can drain the resampler here. Returns an empty chunk for a pass-through or
an already-empty buffer.