How to find out the capabilities of an ALSA audio device programmatically on Linux without opening a device

How do I know the capabilities of ALSA devices without first opening the device? The problem is that I need to pass function parameters in snd_pcm_open()order to use test functions that are silly to me. Why ask if this is a player or recorder if I have to pass it the opening function first?

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

The problem is that with all the possible options (sampling rate, channels, etc.) there would be a terribly large number of open () that I need to execute to find out the parameters.

+5
source share
3 answers

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

, , ALSA, : https://app.assembla.com/spaces/portaudio/git/source/master/src/hostapi/alsa/pa_linux_alsa.c - BuildDeviceList.

+6

linux/unix, . . , , . linux/unix, alsa Linux.

:

aplay -l

, , , alsa.

(.so) , ++.

-

[root@~]# ./IdeaAudioEngineTest
HDA Intel plughw:0,0
HDA Intel plughw:0,2

.

IdeaAudio Alsa

0

Enforcing shell command execution. Then aplay is your friend.

http://alsa.opensrc.org/Aplay

aplay -l

list of all sound cards and digital sound Devices

-1
source

All Articles