pub struct Resampler<T: Transcendental> { /* private fields */ }Expand description
Sample-rate converter wrapping InterpolatedReader.
Accepts a pre-loaded buffer with a known source sample rate and outputs at a target rate that can differ from the source rate.
§Examples
use rill_core::traits::Algorithm;
use rill_core_dsp::generators::Resampler;
let source_rate = 44100.0;
let samples = vec![0.0f32; 1024];
let mut rs = Resampler::new(samples, source_rate);
rs.init(48000.0);
let mut out = vec![0.0f32; 512];
rs.process(None, &mut out).unwrap();
assert!((rs.position() - 512.0 * 44100.0 / 48000.0).abs() < 1.0);Implementations§
Source§impl<T: Transcendental> Resampler<T>
impl<T: Transcendental> Resampler<T>
Sourcepub fn new(buffer: Vec<T>, source_rate: f64) -> Self
pub fn new(buffer: Vec<T>, source_rate: f64) -> Self
Create a new resampler from a sample buffer and its source sample rate.
The resampler starts with target_rate = source_rate (passthrough).
Call Algorithm::init or [set_target_rate] to convert to a
different rate.
Sourcepub fn from_boxed(buffer: Box<[T]>, source_rate: f64) -> Self
pub fn from_boxed(buffer: Box<[T]>, source_rate: f64) -> Self
Create a resampler from a pre-allocated boxed slice.
Sourcepub fn source_rate(&self) -> f64
pub fn source_rate(&self) -> f64
Source sample rate in Hz.
Sourcepub fn set_source_rate(&mut self, hz: f64)
pub fn set_source_rate(&mut self, hz: f64)
Set the source sample rate and recompute the interpolation ratio.
Sourcepub fn target_rate(&self) -> f64
pub fn target_rate(&self) -> f64
Target sample rate in Hz.
Sourcepub fn set_target_rate(&mut self, hz: f64)
pub fn set_target_rate(&mut self, hz: f64)
Set the target sample rate and recompute the interpolation ratio.
Sourcepub fn set_cubic(&mut self, cubic: bool)
pub fn set_cubic(&mut self, cubic: bool)
Enable (true) or disable (false) cubic Hermite interpolation.
Linear interpolation (default) is faster; cubic gives higher quality at the cost of more computation.
Sourcepub fn set_position(&mut self, pos: f64)
pub fn set_position(&mut self, pos: f64)
Set the read position in the source buffer.
Sourcepub fn set_buffer(&mut self, buffer: Vec<T>)
pub fn set_buffer(&mut self, buffer: Vec<T>)
Replace the source buffer and reset position to 0.
The new buffer is assumed to have the same source rate.