1

I'm writing an application that is supposed to list all audio input devices along with their available channels and an id to identify the recording device across reboots and host systems.

I found that arecord -l can list (some?) audio input devices, but there doesn't seem to be a way to list the channel count, although you can use the -c flag to record a specific amount of channels.

I even tried to write a loop that attemps to record with an increasing amount of channels until it fails, but it always fails at 65, even if there is only 1 channel.

In addition to that, the ids are not unique and not safe to use across different host systems.

Any ideas how this can be achieved in Bash?

Ideally independant of what audio system the host is using (like ALSA, Pulseaudio, Pipewire, Jack, Wireplumber, ...)?

3
  • So, is it an "application" or a "bash script"? What are you going to do with this info? "Independent of audio system" doesn't look right because in the end you'll be dealing with this audio system. Does it matter if the device exposes 64 channels via ALSA if PA/PW on top if it supports only 2? Jun 26, 2023 at 9:40
  • I want to record channels of one or more devices selectively. But step 1 is to figure out a way to get the basic device info so that I can prompt the user properly. I need to support USB interfaces with up to 32 channels. Recording is gonna be a separate issue though.
    – Forivin
    Jun 26, 2023 at 10:42
  • For serial numbers and other generic USB device properties, lsusb and/or the /sys/bus/usb/... directory hierarchy might be the easiest ways; the audio APIs tend to not cover things like device serial numbers.
    – telcoM
    Jun 27, 2023 at 10:14

1 Answer 1

0

I use the /proc filesystem for this; it exposes various aspects of the ALSA sound card model to the filesystem.

Examples:

2 channel ADC connected via SoC (system on a chip) I2S interface:

$ cat /proc/asound/card0/pcm0c/sub0/hw_params
access: RW_INTERLEAVED
format: S32_LE
subformat: STD
channels: 2
rate: 48000 (48000/1)
period_size: 192
buffer_size: 2304

8 channel USB audio device:

 $ cat /proc/asound/card0/pcm0c/sub0/hw_params
access: RW_INTERLEAVED
format: S32_LE
subformat: STD
channels: 8
rate: 48000 (48000/1)
period_size: 192
buffer_size: 2304

There are a few other files that might be useful. /proc/asound/card0/stream0 has the channel count on the USB Audio device, but not on the SoC device. Either way, if you have more than one card, you'll need to enumerate over all of them to find what you want, as the enumeration order is not guaranteed.

You can also use amixer to inspect the control count, but I find procfs and sysfs easier to parse.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .