Introduction
miniaudio is a C library contained in a single header file that handles audio playback, recording, and decoding across all major platforms. It abstracts away platform-specific audio APIs while remaining lightweight enough for game engines, embedded apps, and quick prototypes.
What miniaudio Does
- Plays and captures audio on Windows (WASAPI), macOS (Core Audio), Linux (PulseAudio, ALSA), and more
- Decodes WAV, FLAC, and MP3 files with built-in decoders
- Provides a high-level engine API for spatial audio and sound groups
- Supports sample rate conversion, channel mapping, and format conversion
- Runs on Android, iOS, Emscripten, and BSD in addition to desktop OSes
Architecture Overview
miniaudio has two layers: a low-level device API that talks to platform audio backends, and a high-level engine that manages sound instances, effects, and spatialization. All audio processing happens in a lock-free callback running on a dedicated audio thread to avoid glitches.
Self-Hosting & Configuration
- Copy the single header file into your project; define MINIAUDIO_IMPLEMENTATION in one .c file
- Choose a backend at compile time or let miniaudio auto-detect the best option
- Configure buffer sizes and sample rates via ma_device_config
- Use the engine API for game audio with 3D spatialization and groups
- Link no additional libraries; miniaudio loads platform APIs at runtime
Key Features
- Truly single-file with zero external dependencies
- Public-domain (Unlicense or MIT-0) — no licensing concerns
- Low-latency audio suitable for real-time games and music apps
- Built-in WAV, FLAC, and MP3 decoders
- Lock-free design prevents audio glitches from main-thread stalls
Comparison with Similar Tools
- SDL_mixer — requires SDL; miniaudio is fully standalone
- OpenAL Soft — 3D audio focus but heavier; miniaudio is simpler to integrate
- FMOD/Wwise — commercial game audio middleware; miniaudio is free and open source
- PortAudio — low-level only with no decoders; miniaudio adds playback and decoding in one file
FAQ
Q: Can I use miniaudio in a commercial project? A: Yes. It is dual-licensed under Unlicense and MIT-0, both of which allow unrestricted commercial use.
Q: Does miniaudio support MIDI? A: No. miniaudio focuses on PCM audio playback, capture, and decoding. Use a separate library for MIDI.
Q: How do I add effects like reverb? A: miniaudio includes a node graph system for chaining effects. Built-in nodes include low-pass filter, delay, and splitter.
Q: What is the latency? A: With default settings, latency is typically 10-30ms depending on the platform and backend.