|
miniDSP
A small C library for audio DSP
|
resample converts a mono audio file from one sample rate to another using the miniDSP polyphase sinc resampler. It reads any format supported by libsndfile (WAV, FLAC, AIFF, OGG, etc.) and writes WAV output (IEEE float).
From the repository root:
This compiles tools/resample/resample (requires FFTW3 and libsndfile).
| Argument | Description |
|---|---|
| <input> | Input audio file (must be mono) |
| <rate> | Target sample rate in Hz (positive integer) |
| <output.wav> | Output file path (WAV format only) |
| Flag | Default | What it does |
|---|---|---|
| -z N | 32 | Number of sinc zero-crossings per side. More zero-crossings produce a sharper cutoff and better stopband rejection at the cost of speed. |
| -b F | 10.0 | Kaiser window beta parameter. Higher values widen the mainlobe but deepen stopband attenuation (10.0 gives >100 dB rejection). |
The defaults work well for most use cases. Bump them up (e.g. -z 64 -b 14.0) for mastering-quality conversion where you want even cleaner anti-aliasing.
Upsample from 16 kHz to 48 kHz:
Downsample to 8 kHz (telephone quality):
The resampler automatically applies an anti-aliasing lowpass filter when downsampling — no separate filtering step is needed.
High-quality conversion with custom parameters:
The tool reads the input file via libsndfile, converts the samples to double precision for the DSP pipeline, resamples using MD_resample(), converts back to float, and writes the output as IEEE float WAV.
Buffers are freed eagerly after each stage to keep peak memory at roughly 2x the larger of the input or output signal.
Same-rate detection: if the input is already at the target rate, the tool copies the audio directly and prints a note — no resampling overhead.
Constraints:
The core algorithm is a 512-phase polyphase sinc interpolation filter with Kaiser windowing. For a detailed explanation of the math, including the Bessel function, normalised sinc, and filter design, see the Sample Rate Conversion tutorial.