1
votes

I am trying to make a simple studio recording application. I have multiple sound input devices, and would like to record them all simultaneously.

How do I discover all physical audio inputs?

When I use sounddevice.query_devices(), I get a lot of virtual devices and a lot of virtual input channels, that contain no data:

>>> sd.query_devices()

  0 HDA Intel PCH: HDMI 0 (hw:0,3), ALSA (0 in, 8 out)
  1 HDA Intel PCH: HDMI 1 (hw:0,7), ALSA (0 in, 8 out)
  2 HDA Intel PCH: HDMI 2 (hw:0,8), ALSA (0 in, 8 out)
  3 hdmi, ALSA (0 in, 8 out)
  4 pulse, ALSA (32 in, 32 out)
* 5 default, ALSA (32 in, 32 out)
  6 /dev/dsp, OSS (16 in, 16 out)

I am only interested in real devices, and real input channels.

When I query microphone devices with pacmd and then list-sources I get two channels giving fake stereo, even though the device is mono:

$ pacmd
>>> list-sources
...
    channel map: front-left,front-right
                 Stereo

Is there a way to either query PulseAudio, or PortAudio to get physical input channels? And their parameters (so that I can pick sample rate etc.)

1
I don't think that's possible with PortAudio. You could try to scan for (hw:X,Y) in the device name, but I'm not sure if that matches exactly the devices you would like to see.Matthias
Thanks! I wonder if there is any other API that would make it easy?Michal Gajda
I found it is possible in PulseAudio.Michal Gajda

1 Answers

1
votes

It seems best to do more complex things possible in PulseAudio. Here I found the link to the example program. Unfortunately it is complex API that requires one to:

  1. First initialize event loop with pa_mainloop_new, and pa_mainloop_get_api.
  2. Then create a new context with pa_context_new, pa_context_connect, and pa_context_set_state_callback.
  3. In the context callback, one recognizes context initialization and starts enumeration (pa_context_get_source_info_list or pa_context_get_sink_info_list).
  4. Enumeration itself is performed by callbacks too.

Luckily it seems supported on all major platforms (I used Linux and MacOS X). Given the scope of interface, I will probably keep using PulseAudio for all my future audio projects.