cpal
cpal copied to clipboard
Input stream silently changes to system default input device when disconnected (macOS)
Hi there, first of all thank you SO MUCH for maintaining this library!
I'm running into what might be a bug on macOS. I have an external USB audio device connected, and I start a stream reading from this input. This works perfectly. Now, I want to implement some logic to inform me if the device has disconnected/provide support for automatic re-connection. Unfortunately, when I pull the USB cable and the device disappears, my error_callback is never invoked - the stream continues running, but appears to fall back to receiving input from whatever the system default input device happens to be at that moment.
Any suggestions? Is this just an idiosyncracy of CoreAudio?
Thanks for using cpal and for reaching out. Sadly, I don't have macOS expertise and the project is also lacking a macOS expert in the maintainers, so it's likely that you won't get an answer here.
Thanks for the guidance - I might be able to take a stab at implementing something based on how other projects are handling it. The main example I've found so far is this section of code in rtaudio
https://github.com/thestk/rtaudio/blob/master/RtAudio.cpp#L1907-L1916
Looks like the approach taken there is to register a callback that is triggered when the device is no longer "alive", which calls a stream close method. If you could provide a bit of guidance as to how cpal is handling this problem in the general case (for other backends), I could at least dedicate a bit of time to experimentation and see if I can implement something.