So, I ran into an interesting problem this week while working on the “Alien Invasion” music disk that causes all sound to be disabled when the main SDL window would lose focus or become hidden. This could be a bit of a problem for a music disk, so I looked into trying to figure it out for myself.At first I tried the usual SDL culprits, which are the event system for handling focus, but no luck there.

After some poking around in the SDL source code, I was finally able to find a fix. In SDL_dx5audio.c you can change the following function to read:

void DX5_SoundFocus(HWND hwnd)
{
    // This makes sound audible regardless of focus being lost
    //mainwin = hwnd;
}

A better solution long-term in SDL will be to have an option to do this, rather than having to change the code, or just have this enabled by default. We’ll see! This was tested on 1.2.14 which is available to download from http://www.libsdl.org Hopefully someone else can find this useful too 🙂