3
votes

I want to get the list of all audio devices that are available on my Linux system. Then I will show this list into a combo box from which user will select the device to use for recording/playback. Based on the user's selection, I will then construct QAudioInput and QAudioOutput for recording/playback.

According to the Qt documentation, this can be done using QAudioDeviceInfo::availableDevices static method. This method returns a list of all the available audio devices in my system.

I have used this method to list the number of audio devices. This method should have returned a list containing only two elements since my system has two sound cards installed in it (one is in motherboard, another one is a USB device). But it returned a list containing 23 items. When I accessed their names, I got something like below -

default
pulse
front:CARD=Intel,DEV=0
surround40:CARD=Intel,DEV=0
surround41:CARD=Intel,DEV=0
surround50:CARD=Intel,DEV=0
surround51:CARD=Intel,DEV=0
surround71:CARD=Intel,DEV=0
dmix:CARD=Intel,DEV=0
dsnoop:CARD=Intel,DEV=0
hw:CARD=Intel,DEV=0
plughw:CARD=Intel,DEV=0
front:CARD=default,DEV=0
surround40:CARD=default,DEV=0
surround41:CARD=default,DEV=0
surround50:CARD=default,DEV=0
surround51:CARD=default,DEV=0
surround71:CARD=default,DEV=0
iec958:CARD=default,DEV=0
dmix:CARD=default,DEV=0
dsnoop:CARD=default,DEV=0
hw:CARD=default,DEV=0
plughw:CARD=default,DEV=0

The reason behind this is probably the ALSA API that is being used in the back-end. According to this article ALSA logically partitions a sound card into multiple logical audio devices, which is being fetched by the Qt API when it queries the driver.

I don't want to list all these names for the user to choose from. I want to list something like -

HDA-Intel
USB-Audio

from which users will then choose their desired sound card..

Is there any way this can be done using Qt? If it's not, I would really like to know what other alternatives can be used here.

2

2 Answers

0
votes

I know it's called a workaround, but it seems you have this information by listing the different values of CARD= in your list : in your example, Intel and default.

If your application is supposed to be cross-platform, what does this command return under other operating systems ?

-1
votes

Apparently the only way to do this is to fire the aplay/arecord process from Qt, get the result output from the process and parse the output string to find card names and corresponding IDs. As this approach is too dependent on the output string format of those processes, I didn't use it.

Instead, I chose the PulseAudio server to fetch available devices on my system. I also used it for audio I/O as it provides much better control than Qt's multimedia API.