C library for cross-platform real-time audio input and output
Go to file
2015-07-10 00:46:03 -07:00
cmake skeleton 2015-06-30 14:04:45 -07:00
example sample formats: take into account ALSA 2015-07-10 00:46:03 -07:00
src sample formats: take into account ALSA 2015-07-10 00:46:03 -07:00
test sample formats: take into account ALSA 2015-07-10 00:46:03 -07:00
.gitignore closer to building on windows 2015-07-02 03:48:27 -07:00
CMakeLists.txt beginning of ALSA support - list_devices works 2015-07-07 02:55:32 -07:00
LICENSE add LICENSE 2015-06-30 14:12:52 -07:00
README.md ALSA backend determines channel layout of devices 2015-07-09 23:35:58 -07:00

libsoundio

C library which provides cross-platform audio input and output. The API is suitable for real-time software such as digital audio workstations as well as consumer software such as music players.

This library is an abstraction; however it prioritizes performance and power over API convenience. Features that only exist in some sound backends are exposed.

This library is a work-in-progress.

Alternatives

  • PortAudio
    • It does not support PulseAudio.
    • It logs messages to stdio and you can't turn that off.
    • It is not written by me.
  • rtaudio
    • It is not a C library.
    • It uses exceptions.
    • It is not written by me.
  • SDL
    • It comes with a bunch of other baggage - display, windowing, input handling, and lots more.
    • It is not designed with real-time low latency audio in mind.
    • Listing audio devices is broken.
    • It does not support recording devices.
    • It is not written by me.

How It Works

libsoundio tries these backends in order. If unable to connect to that backend, due to the backend not being installed, or the server not running, or the platform is wrong, the next backend is tried.

  1. JACK
  2. PulseAudio
  3. ALSA (Linux)
  4. CoreAudio (OSX)
  5. ASIO (Windows)
  6. DirectSound (Windows)
  7. OSS (BSD)
  8. Dummy

Contributing

libsoundio is programmed in a tiny subset of C++11:

  • No STL.
  • No new or delete.
  • No class. All fields in structs are public.
  • No exceptions or run-time type information.
  • No references.
  • No linking against libstdc++.

Don't get tricked - this is a C library, not a C++ library. We just take advantage of a select few C++11 compiler features such as templates, and then link against libc.

Building

Install the dependencies:

  • cmake
  • ALSA library (optional)
  • libjack2 (optional)
  • libpulseaudio (optional)
mkdir build
cd build
cmake ..
make
sudo make install

Building for Windows

You can build libsoundio with mxe. Follow the requirements section to install the packages necessary on your system. Then somewhere on your file system:

git clone https://github.com/mxe/mxe
cd mxe
make gcc

Then in the libsoundio source directory (replace "/path/to/mxe" with the appropriate path):

mkdir build-win
cd build-win
cmake .. -DCMAKE_TOOLCHAIN_FILE=/path/to/mxe/usr/i686-w64-mingw32.static/share/cmake/mxe-conf.cmake
make

Running the Tests

make test

For more detailed output:

make
./unit_tests

To see test coverage, install lcov, run make coverage and then view coverage/index.html in a browser.

Roadmap

  1. implement ALSA (Linux) backend, get examples working
  2. pipe record to playback example working with dummy linux, osx, windows
  3. pipe record to playback example working with pulseaudio linux
  4. implement CoreAudio (OSX) backend, get examples working
  5. implement DirectSound (Windows) backend, get examples working
  6. implement JACK backend, get examples working
  7. Avoid calling panic in PulseAudio.
  8. implement ASIO (Windows) backend, get examples working
  9. clean up API and improve documentation
    • make sure every function which can return an error documents which errors it can return
    • consider doing the public/private struct thing and make backend_data a union instead of a void *
  10. use a documentation generator and host the docs somewhere
  11. -fvisibility=hidden and then explicitly export stuff
  12. Integrate into libgroove and test with Groove Basin
  13. Consider testing on FreeBSD
  14. look at microphone example and determine if fewer memcpys can be done with the audio data
    • pulseaudio has peek() drop() which sucks, but what if libsoundio lets you specify how much to peek() and if you don't peek all of it, save the unused to a buffer for you.
  15. add len arguments to APIs that have char *

Planned Uses for libsoundio