fixed-resample
An easy to use crate for resampling at a fixed ratio.
It supports resampling in both realtime and in non-realtime applications, and also includes a handy spsc ring buffer type that automatically resamples the input stream to match the output stream when needed.
This crate uses Rubato internally.
Non-realtime example
const IN_SAMPLE_RATE: u32 = 44100;
const OUT_SAMPLE_RATE: u32 = 48000;
const LEN_SECONDS: f64 = 1.0;
// Generate a sine wave at the input sample rate.
let mut phasor: f32 = 0.0;
let phasor_inc: f32 = 440.0 / IN_SAMPLE_RATE as f32;
let len_samples = .round as usize;
let in_samples: = .map.collect;
// Resample the signal to the output sample rate.
let mut resampler = new;
let mut out_samples: = Vec with_capacity;
// (There is also a method to process non-interleaved signals.)
resampler.process_interleaved;
// The resulting output may have a few extra padded zero samples on the end, so
// truncate those if desired.
out_samples.resize;
SPSC channel example
const IN_SAMPLE_RATE: u32 = 44100;
const OUT_SAMPLE_RATE: u32 = 48000;
const BLOCK_FRAMES: usize = 2048;
const NUM_CHANNELS: usize = 2;
let = resampling_channel;
// Simulate a realtime input/output stream.
let in_stream_interval =
from_secs_f64;
let out_stream_interval =
from_secs_f64;
let mut phasor: f32 = 0.0;
let phasor_inc: f32 = 440.0 / IN_SAMPLE_RATE as f32;
let mut in_buf = vec!;
spawn;
let mut out_buf = vec!;
loop