[Big Sur] Audio playback freezes in desktop applications when disconnecting headphones

This is reproducible with the juce tutorials (tested with noise generator and audio player).

It seems that in Big Sur the headphones and the speakers are two different devices (as opposed to previous OSX versions).
While the playback is enabled in the desktop app, if I try to remove the headphones then the application playback stops (getNextAudioCallback is not called anymore). If I try to plug in the headphones again nothing happens. What is more, I have to launch the app again to restore audio (this happens because the audio device is initialized correctly).

Based on other applications the expected behavior would be that the app should use the Speakers device (since at least on my machine it’s the only available output device).

Has anyone faced this problem? Is there any quick fix?

Could it be related to the fact the the currentSetup should be a null pointer when the device is re-initialized? (JUCE/juce_AudioDeviceManager.cpp at master · juce-framework/JUCE · GitHub)

I’m unable to reproduce this on the lastest develop tip on macOS 11.4 using the SimpleSynthNoiseTutorial, building on Xcode 12.5 against the macOS 11.3 SDK with a deployment target of 10.11. If I disconnect the headphones whilst the application is running the output switches to the speakers and when plugging the headphones back in playback switches to the headphones as expected. getNextAudioBlock() is called continuously.

Can you stick a breakpoint on this line in the CoreAudio internals? I get a kAudioDevicePropertyDeviceHasChanged property changed callback when plugging the headphones back in (not when unplugging them) which causes the audio device to be reinitialised and prepareToPlay() to be called. Perhaps you are missing that callback for some reason so the device is not being reinitialised.

Are you sure this is a Big Sur thing or specific hardware?

I’ve seen similar issues with T2 based Macs (2018+) and M1/Apple Silicon.But it’s agnostic to OS (I have exact same issue with Mojave).

Not sure about freezing, but the need to actually switch device for the CoreAudio output exists also in Logic.

About stuttering/freeze.
JUCE uses its own combinator that can cause dropouts.
For 10.9 or newer Apple’s aggregated device seems to work much better.