braddock
braddock

Reputation: 1345

Best practice for C++ audio capture API under Linux?

I need to create a C++ application with a simple audio recording from microphone functionality.

I can't say that there aren't enough audio APIs to do this! Pulse, ALSA, /dev/dsp, OpenAL, etc. My question is what is the current "Best practice" API?

Pulse seems supported by most modern distros, but seems almost devoid of documentation. Will OpenAL be supported across different distros, or is it too obscure? Have I missed any?
Is there not a simple answer?

Upvotes: 10

Views: 12795

Answers (3)

Jeremiah Rose
Jeremiah Rose

Reputation: 4122

there is no simple answer; best practise depends on the context and specific use cases that your application will be exposed to.

for the greatest ease of programming and widest audience, i would choose gstreamer as it is quick and straightforward, well integrated in gnome and ubuntu and supports a wide range of audio subsystems and configurations. it is very flexible.

for example, the command:

gst-launch autoaudiosrc ! audioconvert ! flacenc ! filesink location="foo.flac"

will create a .flac file from microphone input, regardless of the audio system (Pulse, ALSA, ESD ...). an equivalent pipeline can be written using the c / gobject bindings as documented here.

p.s the above command requires the gstreamer-tools package

Upvotes: 1

Spudd86
Spudd86

Reputation: 3006


Lennart Pottering has a guide here:

http://0pointer.de/blog/projects/guide-to-sound-apis

basically use the 'safe' subset of alsa then all the other important ones should work too.

Barring that OpenAL works on Linux

EDIT: Also pulseaudio has reasonably good doxygen generated documentation here and some other stuff here and some of the utilities are good examples, you can see them in gitweb here

Also I've written some code that uses pulse for audio input you can look at it here, however I'm not sure I handle everything totally correctly, and I know I'm missing code to handle certain situations... but that should get you started should you go with pulse.

Upvotes: 4

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 798676

GStreamer will allow you and the end user the most flexibility with regards to sound capture, but its cross-platform viability is not that great, particularly on OS X.

Upvotes: 0

Related Questions