AUDIO
Source snapshot · 12 October 2026

API reference / ravet_signal::StreamInterpolator

Struct StreamInterpolator 

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

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>

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

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)

Clear history/pending phase, preserving kind/rates without allocation.

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>

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

§

fn clone(&self) -> StreamInterpolator

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · §

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
§

impl Debug for StreamInterpolator

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> CloneToUninit for T
where T: Clone,

§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

Performs copy-assignment from self to dest. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.