resampler
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 ;
// Create a stereo resampler (2 channels) from 44.1 kHz to 48 kHz.
let mut resampler = new;
// 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!;
let mut output = vec!;
// Process audio.
match resampler.resample
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.
Quality Analysis
The following spectrograms demonstrate the high-quality output of the resampler across different conversion scenarios:
44.1 kHz → 48 kHz Conversion
22.05 kHz → 44.1 kHz Conversion
License
Licensed under either of
- Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.