Struct Stream Interpolator
pub struct StreamInterpolator { /* private fields */ }Expand description
One-channel f64 reconstruction with five stack-backed history samples.
Construction, processing, additive processing, clone, reset and destruction
allocate/deallocate nothing. Every channel needs its own owner. Kind/rates are
immutable; construction of another owner explicitly changes the profile.
This is a low-cost reconstruction family, without anti-alias filtering.
Downsampling aliases and cubic/quartic kernels can overshoot. Use the separate
crate::SincResampler profile when filtering is required. No headroom,
denormal, finite-input sanitation or callback deadline policy is implied.
Integer output index J requires newest source index k=ceil(JI/O), with
backward fraction f=k-JI/O and initially zero history. Hold returns x[floor(J*I/O)]; linear interpolates x[k]
and x[k-1]. Catmull-Rom and cubic Lagrange
interpolate at JI/O-1; quartic Lagrange at JI/O-2. All profiles use common
bracketing consumption k+1, even when hold needs only the earlier sample.
Fractional bracketing can read up to one input sample ahead of the interpolation
coordinate; reported nominal delays do not include adapter buffering.
No source wrapping or EOS/tail policy: with N>0 supplied input samples and integer rates, all pending outputs total 1+floor((N-1)*O/I). Empty source produces nothing. Caller-supplied padding is ordinary consumed input; no trailing zeros or delay trimming are invented. Equal rates retain kernel delay/history, without a hidden copy bypass.
Implementations§
§impl StreamInterpolator
impl StreamInterpolator
pub fn new(
kind: InterpolationKind,
input_rate: f64,
output_rate: f64,
) -> Result<Self, InterpolationError>
pub fn new( kind: InterpolationKind, input_rate: f64, output_rate: f64, ) -> Result<Self, InterpolationError>
Prepare finite positive floating rates in matching units, ratio 1/16..=16.
Floating recurrence has no long-duration exact-count guarantee. Prefer
Self::new_integer_rates for exact positive-u32 rate scheduling.
pub fn new_integer_rates(
kind: InterpolationKind,
input_rate: u32,
output_rate: u32,
) -> Result<Self, InterpolationError>
pub fn new_integer_rates( kind: InterpolationKind, input_rate: u32, output_rate: u32, ) -> Result<Self, InterpolationError>
Positive u32 rates, ratio 1/16..=16. A bounded signed relative numerator schedules source/output without duration-dependent rounding recurrence. Only kernel evaluation uses f64; no rate edits/clock-drift mode.
pub fn kind(&self) -> InterpolationKind
pub fn latency_input_samples(&self) -> f64
pub fn latency_input_samples(&self) -> f64
Nominal reconstruction delay in source samples: hold/linear 0, Catmull-Rom/cubic Lagrange 1, quartic Lagrange 2. Fractional source bracketing, caller finite-stream tail and adapter buffering are separate.
pub fn reset(&mut self)
pub fn reset(&mut self)
Clear history/pending phase, preserving kind/rates without allocation.
pub fn process(
&mut self,
input: &[f64],
output: &mut [f64],
) -> ResamplingProgress
pub fn process( &mut self, input: &[f64], output: &mut [f64], ) -> ResamplingProgress
Replace only the produced output prefix. Retry with unconsumed input and fresh output capacity. Zero output capacity consumes nothing; empty input can drain pending upsample output. Suffix remains untouched. Nonfinite input can propagate through history until reset; consumption is irreversible.
use ravet_signal::{InterpolationKind, StreamInterpolator};
let mut stream = StreamInterpolator::new_integer_rates(
InterpolationKind::Linear, 1, 2).unwrap();
let mut first = [99.];
let progress = stream.process(&[2., 4.], &mut first);
assert_eq!((progress.consumed, progress.produced), (1, 1));
assert_eq!(first, [2.]);
let mut rest = [99.; 3];
let progress = stream.process(&[4.], &mut rest);
assert_eq!((progress.consumed, progress.produced), (1, 2));
assert_eq!(rest, [3., 4., 99.]);pub fn process_add(
&mut self,
input: &[f64],
output: &mut [f64],
gain: f64,
) -> Result<ResamplingProgress, InterpolationError>
pub fn process_add( &mut self, input: &[f64], output: &mut [f64], gain: f64, ) -> Result<ResamplingProgress, InterpolationError>
Add gain*reconstructed sample over the produced prefix only. Finite gain validation precedes all consumption/history/output edits. Zero gain still advances stream state but leaves output bitwise unchanged, including with nonfinite input. Finite gain/output arithmetic can overflow; no clamp.
Trait Implementations§
§impl Clone for StreamInterpolator
impl Clone for StreamInterpolator
§fn clone(&self) -> StreamInterpolator
fn clone(&self) -> StreamInterpolator
1.0.0 (const: unstable) · §fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more