I struggled with buffer underruns for a long time. I seemed to be dealing with some enigmatic audio problems.
After many failed attempts to solve the audio problems I was having, I decided to tackle the problem head on. I extracted the audio engine code and started a new project, one in which I was dedicated to becoming an expert at how audio input and output is handled on every platform. Hopefully after solving the crap out of sound I/O in a way independent from the other issues I was having, I would be able to solve the Genesis problems.
Well, 3 months and a lot of hard work later I have completed libsoundio 1.0.0.
libsoundio is a lightweight abstraction over various sound drivers. It provides a well-documented API that operates consistently regardless of the sound driver it connects to. It performs no buffering or processing on your behalf; instead exposing the raw power of the underlying backend.
libsoundio is appropriate for games, music players, digital audio workstations, and various utilities.
libsoundio is serious about robustness. It even handles out of memory conditions correctly.
Features & Limitations
- Supported backends:
- Exposes both raw devices and shared devices. Raw devices give you the best performance but prevent other applications from using them. Shared devices are default and usually provide sample rate conversion and format conversion.
- Exposes both device id and friendly name. id you could save in a config file because it persists between devices becoming plugged and unplugged, while friendly name is suitable for exposing to users.
- Supports optimal usage of each supported backend. The same API does the right thing whether the backend has a fixed buffer size, such as on JACK and CoreAudio, or whether it allows directly managing the buffer, such as on ALSA or PulseAudio.
- C library. Depends only on the respective backend API libraries and libc. Does not depend on libstdc++, and does not have exceptions, run-time type information, or setjmp.
- Errors are communicated via return codes, not logging to stdio.
- Supports channel layouts (also known as channel maps), important for surround sound applications.
- Ability to monitor devices and get an event when available devices change.
- Ability to get an event when the backend is disconnected, for example when the JACK server or PulseAudio server shuts down.
- Detects which input device is default and which output device is default.
- Ability to connect to multiple backends at once. For example you could have an ALSA device open and a JACK device open at the same time.
- Meticulously checks all return codes and memory allocations and uses meaningful error codes.
- Compare libsoundio to: PortAudio, RtAudio, or SDL2.