Expand description
Resampler is a small, no dependency crate that is optimized for resampling audio data from one to the other sampling rate. Optimized for the most common audio sampling rates.
§Usage Example
use resampler::{Resampler, SampleRate};
// Create a stereo resampler (2 channels) from 44.1 kHz to 48 kHz.
let mut resampler = Resampler::<2>::new(SampleRate::Hz44100, SampleRate::Hz48000);
// Get required buffer sizes (already includes all channels).
let input_size = resampler.chunk_size_input();
let output_size = resampler.chunk_size_output();
// Create input and output buffers (interleaved format: [L0, R0, L1, R1, ...]).
let input = vec![0.0f32; input_size];
let mut output = vec![0.0f32; output_size];
// Process audio.
match resampler.resample(&input, &mut output) {
Ok(()) => println!("Resample successful"),
Err(error) => eprintln!("Resampling error: {error:?}"),
}§Implementation
The resampler uses an FFT-based overlap-add algorithm with Kaiser windowing for high-quality audio resampling. Key technical details:
- Custom mixed-radix FFT with the standard Cooley-Tukey algorithm.
- SIMD optimizations: All butterflies have SSE, AVX, and ARM NEON implementations with compile time CPU feature detection.
- Real-valued FFT: Exploits conjugate symmetry for 2x performance.
- Kaiser window: Beta parameter of 10.0 provides excellent stopband attenuation of -100 dB while maintaining good time-domain localization.
- Optimal configurations: Pre-computed FFT sizes and factorizations for all supported sample rate pairs, with throughput scaling to ensure a latency around 256 samples.
§Performance
SSE on x86_64 and NEON on aarch64 are enabled by default. But to get the best performance on x86_64 AVX (+avx) and FMA (+fma) should be enabled at compile time as a target feature.
§License
Licensed under either of
- Apache License, Version 2.0
- MIT license
at your option.
Structs§
- Resampler
- High-quality and high-performance FFT-based audio resampler supporting multi-channel audio.
Enums§
- Resample
Error - Errors the process function can throw.
- Sample
Rate - All sample rates the resampler can operate on.