Sine wave in the time domain transformed via FFT into a frequency spectrum showing harmonic peaks
Last updated on

miniDSP: A Small C Library for DSP


I’ve been working on a small C library of DSP functions called miniDSP. It was born out of a need for simple, reusable lightweight components for audio processing tasks, without the overhead of massive frameworks. The library has grown quite a bit since I first wrote about it — here’s an updated overview of what’s in there now.

What is miniDSP?

miniDSP is a C23 library of essential digital signal processing tools, easy to integrate into any C project. It handles everything from spectral analysis and signal generation to DTMF decoding and live audio I/O. Full API reference and tutorials are at wooters.github.io/miniDSP.

What’s in the box?

The library is organized into a few logical areas. Each section links to its tutorial and API docs on the documentation site.

Frequency-domain analysis

The spectral analysis functions cover the fundamentals of frequency-domain work:

Signal generation

Generators for building test signals and demos: sine wave, white noise (Gaussian), impulse, chirp (linear and logarithmic), square wave, and sawtooth.

Filtering

Two filter families are included:

  • Biquad filters (biquad.h) — seven classic types based on Robert Bristow-Johnson’s Audio EQ Cookbook: low-pass, high-pass, band-pass, notch, peaking EQ, low shelf, and high shelf.
  • FIR filters & convolution — time-domain convolution, moving-average, general FIR, and FFT overlap-add for longer kernels.

Signal analysis & measurement

Functions for understanding what a signal is doing:

  • RMS, zero-crossing rate, autocorrelation, peak detection, and signal mixing
  • F0 estimation via autocorrelation and FFT peak-picking
  • Energy, power (dB), normalized entropy, scaling, and automatic gain control

Effects

A handful of simple audio effects implemented as self-contained C functions: delay/echo, tremolo, and comb-filter reverb.

DTMF tone detection and generation

DTMF (Dual-Tone Multi-Frequency) is the signalling system used by touch-tone telephones. miniDSP includes:

  • Multi-digit tone synthesis — generate DTMF sequences with configurable tone and pause durations
  • Sliding-window FFT detection — decode digits from audio using a frame-based detector with an ITU-T Q.24-compliant state machine that enforces minimum 40 ms tone-on and 40 ms inter-digit pause timing
  • Decoded digit output — each detected tone includes the digit character and onset/offset timestamps in seconds

Delay estimation

GCC-PHAT — estimate the time delay between two microphone signals using Generalized Cross-Correlation with Phase Transform. The core of acoustic source localization.

I/O

For reading, writing, and capturing audio:

  • File I/O (fileio.h) — read any format libsndfile supports (WAV, FLAC, AIFF, OGG, etc.); write WAV, NumPy .npy, or safetensors.
  • Live audio (liveio.h) — record from the microphone and play back to speakers via PortAudio, with a non-blocking callback API.

Example

Generate a 440 Hz sine wave and find its peak frequency bin:

#include "minidsp.h"
#include <stdio.h>

int main(void) {
    double signal[1024];
    MD_sine_wave(signal, 1024, 1.0, 440.0, 16000.0);

    double mag[1024 / 2 + 1];
    MD_magnitude_spectrum(signal, 1024, mag);

    unsigned peak = 0;
    for (unsigned k = 1; k < 1024 / 2 + 1; k++)
        if (mag[k] > mag[peak]) peak = k;
    printf("Peak bin: %u (%.1f Hz)\n", peak, peak * 16000.0 / 1024);

    MD_shutdown();
}

There are 16 runnable examples in the examples/ directory, many of which produce interactive HTML plots (Plotly.js + D3.js) for exploring the output visually.

Documentation & Tutorials

The documentation site includes a Doxygen API reference and step-by-step tutorials covering:

Get It

Clone and build:

git clone https://github.com/wooters/miniDSP.git
cd miniDSP
make

This produces libminidsp.a in the repo root. Link against it with -lminidsp -lfftw3 -lm (add -lsndfile for fileio.h, -lportaudio for liveio.h).

Dependencies

LibraryPurposeDebian/UbuntumacOS (Homebrew)
FFTW3Fast Fourier Transformapt install libfftw3-devbrew install fftw
PortAudioLive audio I/Oapt install portaudio19-devbrew install portaudio
libsndfileAudio file reading/writingapt install libsndfile1-devbrew install libsndfile

The Makefiles auto-detect Homebrew paths on macOS (both Apple Silicon and Intel). On Ubuntu, GCC 14 or later is required for C23 support.

Running tests

make test             # build and run all tests
make container-test   # run tests inside an Ubuntu 24.04 container (macOS only)
make docs             # generate API docs in docs/html

Full source, build instructions, and examples on GitHub: https://github.com/wooters/miniDSP