Skip to main content

resample

Function resample 

Source
pub fn resample(
    samples: &[f64],
    from: SampleRate,
    to: SampleRate,
) -> Result<Vec<f64>, ResampleError>
Expand description

Resamples a mono signal from one rate to another in f64.

The synchronous FFT resampler of rubato does the work: its band-limited conversion keeps the passband and removes everything above the new Nyquist frequency. The output has ceil(len * to / from) samples, with the resampler’s whole-sample delay trimmed, so sample n of the output sits at the time of sample n * from / to of the input. Equal rates return a copy.

rubato leaves a fractional delay that this trim cannot remove: for some rate pairs, among them 16, 32, 48, 96 and 192 kHz to 22050 Hz and 48 to 8 kHz, the output lags by half an output sample, 23 us at 22050 Hz. Pairs such as 44.1 to 22.05 kHz, 48 to 44.1 kHz and 22.05 to 48 kHz have no lag. Half a sample is far below any time this program reports.

Resampling to a lower rate removes the band above the new Nyquist frequency. Never feed such output to a spectral descriptor.

§Errors

Returns a ResampleError when a sample is NaN or infinite, which would make rubato panic, and when rubato rejects the rates or fails. Equal rates copy the samples unchecked.