Changing audio output when the default audio playback device changes?

Recently purchased a new system which has multiple audio devices: on board sound, and HDMI sound. HDMI goes to in-built monitor speakers, and on board sound goes so amplified speakers. I like to swap between the two, and most apps change their output on-the-fly when I change the default playback device in Windows 10.

When my SDL app initializes, it chooses the correct default playback device, but the output doesn’t change to the new default audio device. Can I get notification in SDL about an audio device change? I was hoping SDL_AudioDeviceEvent would trigger, but it doesn’t. I assume that closing the audio down and re-opening it would change to the new default device? I’m using SDL_Mixer, but I don’t think that’s an issue.

I assume that closing the audio down and re-opening it would change to the new default device?

In many cases, SDL will quietly move to new default audio devices on your behalf if you’ve opened the default device. If you’ve opened a specific one by name, even if happened to be the system’s default device, it won’t migrate.

This depends on the audio target, though, and some platforms and audio APIs are nicer about this than others (some won’t do it at all, some do it without SDL’s intervention, some SDL handles it internally). What platform are you using?

Also: assuming the platform supports it, SDL will tell you as audio devices come and go, but we don’t have an event to tell you when the default device changes at the moment; currently we prefer to handle that special case transparently for your app, if it’s possible to be handled.

(In cases where it can’t be handled, closing the default device and reopening it should give you the new default device. If anything I said here is proving untrue, it’s possibly an SDL bug and I want to hear about it, though!)

Hi Ryan,

Thanks for giving this attention. I’ve taken another look and it is most certainly not changing the sound device output live when I change default in the operating system. I have to exit and re-run my game to force it to switch output, or close audio and re-open audio; but there’s no event that tells me when default audio has changed? I’ve tested this on many other games and it works as expected (I’m not sure of said games were using SDL2 though, I can dig deeper?).

Does it matter that I’m using SDL_Mixer?

I’m using Windows10, i686-w64-mingw32, 2.0.5 pre-compiled lib. Not sure what else you need to know.



I’m using Windows10, i686-w64-mingw32, 2.0.5 pre-compiled lib. Not sure what else you need to know.

This should start working for you in 2.0.6 (or right now in revision control), because the new WASAPI target definitely supports this.

I am finding on macOS that it chooses the correct default audio device when you open the audio with the NULL parameter, but when you change the audio device using the menubar it doesn’t change within SDL.

I am tracking the audio device added/removed events, and these work in situations such as turning on or off bluetooth headphones in that if I react to these events by closing and reopening the audio (again with NULL) then it does switch between internal speakers and headphones, but there doesn’t seem to be away of having it respond to manual changes to the default audio device.

This is macOS 10.15 and SDL 2.0.10. Could this be addressed? Or maybe we could have that event and then my existing changes should just work by tracking this new event too.

I’m pretty sure this used to work; I’ve opened a bug to look into this further here:


Okay, turns out it never did.

The latest in SDL’s revision control will now switch between audio devices as you change the default in System Preferences. It should also work if the default device was a USB thing and you yank it out of the machine (as macOS should change the system default automatically then).

This is only when opening a NULL (default) device in SDL. If you open a specific device, we won’t switch to a new one on your behalf if it goes away or a default changes.

This does not alert the app with an event, we just transparently switch over to the new device. Likewise if the default recording device changes, too.

1 Like