Problem enumerating devices based on Pa_GetHostApiInfo()

2 views
Skip to first unread message

Tim Pattinson

unread,
Jul 4, 2026, 12:17:45 PM (12 days ago) Jul 4
to PortAudio Mailing List
Hi all,
I am encountering a problem which could be a bug in PortAudio, or could be my misunderstanding.

I am attempting to enumerate the audio devices made available by each host API.
The logic is: Call Pa_GetHostApiInfo() to get the number of devices, then call Pa_HostApiDeviceIndextoDeviceIndex() to get the global index of it.

(I am aware that I could enumerate directly, but it seemed useful to do it this way to make a list of what is available in each host API)

The issue I am having is that  Pa_HostApiDeviceIndextoDeviceIndex() returns the error paInvalidDevice when queried with a device index which is less that what is returned by  Pa_GetHostApiInfo()->deviceCount

My expectation was that I can query Pa_HostApiDeviceIndextoDeviceIndex() with 0 to deviceCount-1 and get a valid index. This is based on the comments in the PaHostApiInfo struct.
Stepping inside the function, it seems to compare my index with a different value for the maximum number of devices, and returns the error code.

I have attached a short program which reproduces this issue.
My system is Windows 11 25H2 but I am using the latest MSYS2 MinGW toolchain.

The output is: 

tim@TIMSPC UCRT64 ~
$ ./a.exe
PortAudio initialised
enumerating 5 APIs.
PA API: MME
        has 7 devices, default input device: 1
Trying device 0 on api 0 (index: 14)
        PA device (API idx 0): Realtek ASIO
        Input Channels: 2
                defaultLowOutputLatency: 0.023220
                defaultHighInputLatency: 0.023220
                defaultSampleRate 44100.000000
Trying device 1 on api 0 (index: -9996)
Segmentation fault         ./a.exe

I seperately compiled the example "pa_devs.c" and that seems to work fine, although it doesn't enumerate devices in the same way.

I'd appreciate someone pointing out my error or reproducing on their system.
Thanks
test.cpp
Reply all
Reply to author
Forward
0 new messages