Reputation: 653
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.)
Upvotes: 1
Views: 2463
Reputation: 653
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:
pa_mainloop_new
, and pa_mainloop_get_api
.pa_context_new
, pa_context_connect
, and pa_context_set_state_callback
.pa_context_get_source_info_list
or pa_context_get_sink_info_list
).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.
Similar enumeration for PipeWire API, which is newer: https://docs.pipewire.org/page_tutorial2.html
Upvotes: 1