pub struct InterleavedResampler<T = f64>{ /* private fields */ }Expand description
Chunked sample-rate converter for interleaved audio buffers.
Use this resampler when you can control both read and write buffer sizes. Query
input_buffer_size() and output_buffer_size(), then size your input and output
slices to those values.
- Construct with
InterleavedResampler::new(config). - Query
input_buffer_size()andoutput_buffer_size(). - Call
process_chunk(...)for each full interleaved chunk. - Call
process_chunk_final(...)once for the final chunk (it may be undersized). - Call
finalize(...)once per stream to emit delayed tail samples and reset stream state.
To end a stream early, call reset().
Internally, ardftsrc processes planar channels. This type is intended for callers that already work with interleaved audio and provides an optimized de-interleave/re-interleave path.
Implementations§
Source§impl<T> InterleavedResampler<T>
impl<T> InterleavedResampler<T>
Sourcepub fn input_sample_processed(&self) -> usize
pub fn input_sample_processed(&self) -> usize
Returns the total number of interleaved input samples processed.
Sourcepub fn output_sample_processed(&self) -> usize
pub fn output_sample_processed(&self) -> usize
Returns the total number of interleaved output samples processed.
Sourcepub fn input_buffer_size(&self) -> usize
pub fn input_buffer_size(&self) -> usize
Returns the required input length (interleaved samples) for each process_chunk() call.
Use this to allocate/read fixed-size streaming input buffers.
Sourcepub fn output_buffer_size(&self) -> usize
pub fn output_buffer_size(&self) -> usize
Returns the recommended per-call output capacity in interleaved samples.
For chunked streaming, size output slices passed to process_chunk() and
process_chunk_final() to at least this value.
Sourcepub fn output_delay_frames(&self) -> usize
pub fn output_delay_frames(&self) -> usize
Returns algorithmic latency to trim/flush, or zero in same-rate passthrough mode.
Sourcepub fn expected_output_size(&self, input_size: usize) -> usize
pub fn expected_output_size(&self, input_size: usize) -> usize
Returns the expected output length for a given input length.
input_size can be expressed in either frames or samples; the
returned value uses the same unit.
Sourcepub fn process_all<'a>(&mut self, input: &[T]) -> Result<PlanarVecs<T>, Error>
pub fn process_all<'a>(&mut self, input: &[T]) -> Result<PlanarVecs<T>, Error>
Resamples a complete interleaved input buffer and returns all output samples.
This is a convenience wrapper around the streaming API.
When the rayon feature is enabled, each channel is processed in parallel.
Sourcepub fn reset(&mut self)
pub fn reset(&mut self)
Resets internal streaming state so the next input is treated as a new, independent stream.
Call this between unrelated audio inputs (for example, between files) when reusing the same resampler instance, so edge/history state from one input cannot bleed into the next.
Sourcepub fn process_chunk<'a>(
&mut self,
input: &[T],
output: &mut [T],
) -> Result<usize, Error>
pub fn process_chunk<'a>( &mut self, input: &[T], output: &mut [T], ) -> Result<usize, Error>
Processes an interleaved chunk.
input must contain exactly input_buffer_size() samples (all channels, interleaved),
and output should provide at least output_buffer_size() capacity.
The method returns the actual sample count written for this chunk, which may be smaller (for example while startup delay is being trimmed).
Returns the number of samples written to the output buffer.
Sourcepub fn process_chunk_final<'a>(
&mut self,
input: &[T],
output: &mut [T],
) -> Result<usize, Error>
pub fn process_chunk_final<'a>( &mut self, input: &[T], output: &mut [T], ) -> Result<usize, Error>
Processes the final chunk, which may be shorter than the regular chunk size.
Call this exactly once at end-of-stream for the trailing partial chunk (it may be empty if
input length is an exact multiple of input_buffer_size()). After this call, no further
chunk-processing calls should be made; call finalize() to drain remaining delayed tail.
Size output to at least output_buffer_size().
Returns the number of samples written to the output buffer.
Sourcepub fn finalize<'a>(&mut self, output: &mut [T]) -> Result<usize, Error>
pub fn finalize<'a>(&mut self, output: &mut [T]) -> Result<usize, Error>
Emits delayed tail samples, then resets stream state.
This flushes any remaining delayed samples that were held back by the chunked
processing pipeline. It is the terminal step of a stream and should be called once per
stream. If process_chunk_final() was not called, this treats the last accepted full chunk
as terminal input.
Returns the number of samples written to the output buffer.
Sourcepub fn is_finalized(&self) -> bool
pub fn is_finalized(&self) -> bool
Returns true when all channels have been finalized.
Sourcepub fn pre<'a>(&mut self, pre: Vec<T>) -> Result<(), Error>
pub fn pre<'a>(&mut self, pre: Vec<T>) -> Result<(), Error>
Sets previous-track context.
Use this when resampling gapless material, for example an album where tracks are played back-to-back. In that case, pass the last chunk of the previous track.
The adapter must report the same channel count as this resampler.
Recommended size:
- Pass one full input chunk from the end of the previous track.
- Query chunk size with
input_buffer_size().
Shorter buffers are still valid: any missing start context falls back to LPC extrapolation.
Sourcepub fn post<'a>(&mut self, post: Vec<T>) -> Result<(), Error>
pub fn post<'a>(&mut self, post: Vec<T>) -> Result<(), Error>
Sets next-track context.
Use this when resampling gapless material, for example an album where tracks are played back-to-back. In that case, pass the first chunk of the next track.
You may call this at any time while the current stream is still active. It must be called before “process_chunk_final(…)”.
This is useful for live gapless handoff: while track A is streaming, once track B is known you
can call post(...) on track A with B’s head samples so A’s stop-edge uses real next-track
context.
The adapter must report the same channel count as this resampler.
Recommended size:
- Pass one full input chunk from the start of the next track.
- Query chunk size with
input_buffer_size().
Shorter buffers are still valid: any missing stop context falls back to LPC extrapolation.
Sourcepub fn batch(&self, inputs: &[&[T]]) -> Result<Vec<PlanarVecs<T>>, Error>
pub fn batch(&self, inputs: &[&[T]]) -> Result<Vec<PlanarVecs<T>>, Error>
Process multiple independent tracks.
Each input slice is treated as its own stream with no inter-track context. See
batch_gapless() for gapless processing of multiple tracks.
Enable the rayon feature for parallel processing.
Sourcepub fn batch_gapless(
&self,
inputs: &[&[T]],
) -> Result<Vec<PlanarVecs<T>>, Error>
pub fn batch_gapless( &self, inputs: &[&[T]], ) -> Result<Vec<PlanarVecs<T>>, Error>
Process multiple tracks as one gapless sequence.
Adjacent inputs are treated as tracks from the same album or other back-to-back material. Each track is returned separately, but the previous track’s tail and next track’s head are used as edge context to improve gapless playback.
Enable the rayon feature for parallel processing.