| Crates.io | resampler |
| lib.rs | resampler |
| version | 0.4.1 |
| created_at | 2025-10-27 19:09:47.918289+00 |
| updated_at | 2026-01-14 16:15:36.711069+00 |
| description | A small audio resampling library |
| homepage | |
| repository | https://github.com/hasenbanck/resampler |
| max_upload_size | |
| id | 1903600 |
| size | 1,116,110 |
Resampler is a small, zero-dependency crate for high-quality audio resampling between common sample rates. It provides both FFT-based and FIR-based resamplers optimized for different use cases.
use resampler::{ResamplerFft, SampleRate};
// Create a stereo resampler (2 channels) from 44.1 kHz to 48 kHz.
let mut resampler = ResamplerFft::new(2, 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];
resampler.resample(&input, &mut output).unwrap();
use resampler::{Attenuation, Latency, ResamplerFir, SampleRate};
// Create a stereo resampler with configurable latency (16, 32, or 64 samples).
let mut resampler = ResamplerFir::new(
2,
SampleRate::Hz48000,
SampleRate::Hz44100,
Latency::Sample64,
Attenuation::Db90,
);
// Streaming API - accepts arbitrary input buffer sizes.
let input = vec![0.0f32; 512];
let mut output = vec![0.0f32; resampler.buffer_size_output()];
let (consumed, produced) = resampler.resample(&input, &mut output).unwrap();
println!("Consumed {consumed} samples, produced {produced} samples");
Both resamplers provide good quality, but are optimized for different use cases:
| Feature | ResamplerFft | ResamplerFir |
|---|---|---|
| Quality | Very good (sharp rolloff) | Good (slow rolloff) |
| Performance | Very fast | Fast (configurable) |
| Latency | ~256 samples | 16-64 samples (configurable) |
| API | Fixed chunk size | Flexible streaming |
| Best for | Non-latency sensitive processing | Low-latency processing |
Use ResamplerFft when:
Use ResamplerFir when:
The resampler uses an FFT-based overlap-add algorithm with Kaiser windowing for high-quality audio resampling. Key technical details:
The FIR resampler uses a polyphase filter with linear interpolation for high-quality audio resampling with low latency. Key technical details:
Both resamplers include SIMD optimizations with runtime CPU feature detection for maximum performance and compatibility.
But for up to 25% better performance on x86_64, compile with target-cpu=x86-64-v3 (enables AVX2, FMA, and other
optimizations).
Overall the SIMD for x86_64 have four levels implemented, targeting four possible CPU generations that build up on each other:
The library supports no-std environments with alloc. To use the library in a no-std environment, enable the
no_std feature:
[dependencies]
resampler = { version = "0.2", features = ["no_std"] }
When the no_std feature is enabled:
Caching: The library will not cache FFT and FIR objects globally to shorten resampler creation time and lower overall memory consumption for multiple resamplers.
No runtime detection of SIMD functionality. You need to activate SIMD via compile time target features.
The default build (without no_std feature) has zero dependencies and uses the standard library for optimal performance
and memory efficiency through global caching.
The following spectrograms demonstrate the high-quality output of the resampler across different conversion scenarios:


Other high-quality audio resampling libraries in Rust are:
Licensed under either of
at your option.
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.