pub fn convert(
from_rate: u32,
to_rate: u32,
channels: usize,
converter_type: ConverterType,
input: &[f32],
) -> Result<Vec<f32>, Error>Expand description
Perform a simple samplerate conversion of a large chunk of audio.
This calls src_simple of libsamplerate which is not suitable for streamed audio. Use the
Samplerate struct instead for this.
The length of input must be input_frame_count * channels.
The length of result Vec<f32> should be input_frames * to_rate + (from_rate - 1)) / from_rate
ยงExample
use samplerate_rs::{convert, ConverterType};
// Generate a 880Hz sine wave for 1 second in 44100Hz with one channel.
let freq = std::f32::consts::PI * 880f32 / 44100f32;
let mut input: Vec<f32> = (0..44100).map(|i| (freq * i as f32).sin()).collect();
// Resample the input from 44100Hz to 48000Hz.
let resampled = convert(44100, 48000, 1, ConverterType::SincBestQuality, &input).unwrap();
assert_eq!(resampled.len(), 48000);