tags:

views:

224

answers:

2

How do I find out the capabilities of ALSA devices without opening the device first? Problem is, I need to supply the parameters to the snd_pcm_open() function to use the test functions which to me is silly. Why ask whether this is a playback or record device if I have to tell it to the open function first?

As an example, I would like to list all playback devices but the only way I can think of is trying to open every device I find (with snd_device_name_hint()) and try to open them in playback mode and if I manage to open, everything is fine.

Problem is, with all the possible variations (sample rate, channels, etc) there would be an awful large number of open()'s I need to perform to find out the parameters.

A: 

Providing you can perform a shell command. Then aplay is your friend.

http://alsa.opensrc.org/index.php/Aplay

aplay -l

list all soundcards and digital audio devices

tgandrews
This doesn't tell me anything I don't know with snd_device_name_hint(). It doesn't seem to tell, for instance, what sample rates each device supports. Plus I wouldn't say it's very simple to call this from C code and handle the output even if it did produce the info I need...
Makis
+2  A: 

Use snd_ctl_next to iterate over all devices, then snd_ctl_open to get info about the device - this is not the same as snd_pcm_open, which could fail if another program has the device open or if you have bad settings.

It's quite dense, but here's some open-source code that iterates over all ALSA devices you could look at: http://portaudio.com/trac/browser/portaudio/trunk/src/hostapi/alsa/pa%5Flinux%5Falsa.c - search for BuildDeviceList to get started.

dmazzoni