Warning
🔨 Work in progress - almost done!
SoundIO (Sound Input/Output) is a header-only, cross-platform, high-level audio library for C++ built on top of miniaudio.
It gives you a node-based audio graph abstraction so you can connect audio inputs, outputs, files and manage playback without worrying about low-level device handling, memory safety, or backend quirks for those who want to work with audio quickly and easily.
Works anywhere miniaudio works - from desktop to mobile to the web;
Because simple audio shouldn't be such a headache.
Not yet :v
- Header-only, modern
C++17+
, no extra library required - Extremely simple API, node-based graph, subscription based calls
- Low memory footprint and low overhead, simply wrapping miniaudio
- Format negociation built-in, no need to resample or convert between inputs and outputs
- Supports for input and output devices, microphones and speakers, for all platforms are built in, with ability to fetch them with a normalized id for all platforms
- File playback and recording, (WAV, MP3, OGG, PCM) - support for the following formats are out of the box
- Mixing, combining, resampling, playback, built-in for complex but easy-to-use audio manipulation
- Runs anywhere miniaudio runs: Windows, macOS, Linux, Android, iOS, Web (see supported backends below)
- SoundIO
- Demo
- Features
- Table of contents
- Specifications
- Installation
- Usage
- Documentation
- Building
- Disclaimer
Click to see the remaining features...
AudioFileOutput.h
- Exports file data
AudioMixer.h
- Base class for mixing PCM audioAudioCombiner.h
- Combines multiple inputs into a single mixed output
AudioPlayer.h
- Manages the playback of an input into the output
Finishing the SoundIO.h class, cleaning up code, documenting methods, detecting properly when devices uninit (miniaudio is not properly handling this well), making debugging optional Better building script QA + Testing and example scripts should be written.
- C++ Standard: C++17 or above, exclusively written in std code only
- Supported audio formats: PCM (all formats), WAV, MP3, OGG
- Supported audio backends:
Operating System | Supported backends |
---|---|
Windows | WASAPI, DirectSound, WinMM |
macOS/iOS | Core Audio |
Linux | ALSA, PulseAudio, JACK |
FreeBSD | OSS, sndio, audio(4) |
OpenBSD | OSS, sndio, audio(4) |
NetBSD | OSS, sndio, audio(4) |
Android | AAudio, OpenSL/ES |
Web | Emscripten, WebAudio |
TL;DR: if its supported by miniaudio, it is supported by SoundIO.
To use SoundIO, simply include the header file.
#include <SoundIO.h>
Initialize and shutting down SoundIO:
// storing result is optional.
ma_result result = SoundIO::initialize();
// shutting down (when done to clean up)
ma_result result = SoundIO::shutdown();
Warning
To create SoundIO instances, it is required that you use SoundIO::create*
because their memory management will be handled by SoundIO.
Playing a file
// get default speaker
auto* speaker = SoundIO::getDefaultSpeaker();
// create a file input, and open the file
auto* file = SoundIO::createFileInput();
ma_result result = file->open("sample.mp3");
// if the file was successfully loaded
if (result == MA_SUCCESS)
// the output of the file will be drained to the speaker.
file->subscribe(speaker);
Playing a file with playback
Important
To avoid wasting resources, devices are not active by default.
You must wake up a device with device->ensureAwake()
before using it.
The default microphone and speaker are automatically woken up when you request them (this is optional, but enabled by default).
Listing devices and getting their information
for (auto* device : SoundIO::getAllDevices()) {
// Device name / normalized id
std::cout << "Device: " << device->name << " (ID: " << device->id << ")\n";
// Device type
std::cout << " Type: " << (device->deviceType == ma_device_type_playback ? "Speaker" : "Microphone") << "\n";
// Device channels
std::cout << " Channels: " << device->deviceFormat.channels << "\n";
// Device sample rate
std::cout << " Sample Rate: " << device->deviceFormat.sampleRate << "\n";
// Device format
std::cout << " Format: " << device->deviceFormat.format << "\n";
// Is device default
if (device->isDefault) std::cout << " [default]" << "\n";
}
Simple microphone to speaker loopback
// get default microphone and speaker
auto* microphone = SoundIO::getDefaultMicrophone();
auto* speaker = SoundIO::getDefaultSpeaker();
// initialize loopback.
// resampling and format negociation is automatically handled by SoundIO.
microphone->subscribe(speaker);
Recording microphone data to a file
// get default microphone
auto* microphone = SoundIO::getDefaultMicrophone();
// create a file input, and open the file
// format IS required (mp3, wav, pcm etc)
auto* file = SoundIO::createFileOutput();
ma_result result = file->open("recording.wav", mic->deviceFormat);
// if the file was successfully loaded
if (result == MA_SUCCESS)
// the output of the microphone will be saved to the file automatically.
microphone->subscribe(file);
Note
Resampling, format conversion, negociation and normalization are automatically done and handled by the library. That means unless specifically set; the input will always match the output format without audio degradation.
Resampling and converting a file
// get the mp3 sample
auto* mp3Sample = SoundIO::createFileInput();
mp3Sample->open("sample.mp3");
// create the wav sample
auto* wavSample = SoundIO::createFileOutput();
wavSample->open("sample.wav", mp3sample->format);
// this will start draining
mp3Sample->subscribe(wavSample);
// keep converting until finished
// (the input is DRAINED by the output here)
while (!mp3Sample->isFinished())
std::this_thread::yield();
// close files
mp3Sample->close();
wavSample->close();
Generating and playing back a sine wave stream
See sin_wave.cpp.
More detailed examples are available here.
By default, SoundIO will remain silent and not print anything out because most methods return an ma_result
, however using the following define statement will enable verbose debugging statements.
#define SOUNDIO_LOG_ENABLED 1
Click here to see the full documentation
🚀 If you have an issue or idea, let me know in the Issues section.
📜 If you use this library, you also bound by the terms of miniaudio.h
's license and this library's MIT license.
☕ Want to support me? You can send me a coffee on ko.fi: https://ko-fi.com/coloride.
© (real)Coloride - 2025, Licensed MIT.