#interpolation #resampling

rubato

Asynchronous resampling library intended for audio data

9 unstable releases (3 breaking)

0.5.0 Oct 10, 2020
0.4.4 Oct 6, 2020
0.4.3 Jun 25, 2020
0.2.1 May 18, 2020
0.1.0 May 6, 2020

#39 in Audio

Download history 175/week @ 2020-06-30 19/week @ 2020-07-07 48/week @ 2020-07-14 111/week @ 2020-07-21 28/week @ 2020-07-28 57/week @ 2020-08-04 58/week @ 2020-08-11 80/week @ 2020-08-18 30/week @ 2020-08-25 48/week @ 2020-09-01 61/week @ 2020-09-08 85/week @ 2020-09-15 101/week @ 2020-09-22 50/week @ 2020-09-29 86/week @ 2020-10-06 237/week @ 2020-10-13

274 downloads per month
Used in 3 crates (via hrtf)

MIT license

73KB
1.5K SLoC

rubato

An audio sample rate conversion library for Rust.

This library provides resamplers to process audio in chunks.

The ratio between input and output sample rates is completely free. Implementations are available that accept a fixed length input while returning a variable length output, and vice versa.

Asynchronous resampling

The resampling is based on band-limited interpolation using sinc interpolation filters. The sinc interpolation upsamples by an adjustable factor, and then the new sample points are calculated by interpolating between these points. The resampling ratio can be updated at any time.

Synchronous resampling

Synchronous resampling is implemented via FFT. The data is FFT:ed, the spectrum modified, and then inverse FFT:ed to get the resampled data. This type of resampler is considerably faster but doesn't support changing the resampling ratio.

Documentation

The full documentation can be generated by rustdoc. To generate and view it run:

cargo doc --open

Example

Resample a single chunk of a dummy audio file from 44100 to 48000 Hz. See also the "fixedin64" example that can be used to process a file from disk.

use rubato::{Resampler, SincFixedIn, InterpolationType, InterpolationParameters, WindowFunction};
let params = InterpolationParameters {
    sinc_len: 256,
    f_cutoff: 0.95,
    interpolation: InterpolationType::Nearest,
    oversampling_factor: 160,
    window: WindowFunction::BlackmanHarris2,
};
let mut resampler = SincFixedIn::<f64>::new(
    48000 as f64 / 44100 as f64,
    params,
    1024,
    2,
);

let waves_in = vec![vec![0.0f64; 1024];2];
let waves_out = resampler.process(&waves_in).unwrap();

Compatibility

The rubato crate requires rustc version 1.40 or newer.

License: MIT

Dependencies

~580KB
~11K SLoC