[][src]Crate 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. 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.

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 f32 / 44100 as f32,
    params,
    1024,
    2,
);

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

Compatibility

The rubato crate only depends on the num crate and should work with any rustc version that crate supports.

Structs

InterpolationParameters

A struct holding the parameters for interpolation.

ResamplerError

Custom error returned by resamplers

SincFixedIn

A resampler that accepts a fixed number of audio chunks for input and returns a variable number of frames.

SincFixedOut

A resampler that return a fixed number of audio chunks. The number of input frames required is given by the frames_needed function.

Enums

InterpolationType

Interpolation methods that can be selected. For asynchronous interpolation where the ratio between inut and output sample rates can be any number, it's not possible to pre-calculate all the needed interpolation filters. Instead they have to be computed as needed, which becomes impractical since the sincs are very expensive to generate in terms of cpu time. It's more efficient to combine the sinc filters with some other interpolation technique. Then sinc filters are used to provide a fixed number of interpolated points between input samples, and then the new value is calculated by interpolation between those points.

WindowFunction

Different window functions that can be used to window the sinc function.

Traits

Resampler

A resampler that us used to resample a chunk of audio to a new sample rate. The rate can be adjusted as required.