views:

162

answers:

3

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?

thanks!

A: 

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.

Ignacio Vazquez-Abrams
GStreamer also isn't really good at the asked for use case because that's not what it's designed for... it's a multimedia framework so for supporting stuff like totem and rhytmbox or PiTiVi (non-linear video editor) that need to handle lots of media formats and stuff like that. For this question it is overkill and overcomplicated.
Spudd86
+1  A: 

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.

Spudd86
+1  A: 

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

Jeremiah Rose