foxygit / doom Log in
commit db8f3c5b15d008587e84409e2fe6e7fb965424f5
Author:     Michael Day <43701387+mikeday0@users.noreply.github.com>
AuthorDate: Wed Jun 11 05:49:15 2025 -0400
Commit:     GitHub <noreply@github.com>
CommitDate: Wed Jun 11 11:49:15 2025 +0200

    Disable SDL Mixer Windows native midi (#1742)

    * Disable SDL Mixer Windows native midi

    * Add _WIN32 guard and comment for env string
---
 src/i_sdlmusic.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/src/i_sdlmusic.c b/src/i_sdlmusic.c
index 313ca63c..70502d0b 100644
--- a/src/i_sdlmusic.c
+++ b/src/i_sdlmusic.c
@@ -177,6 +177,11 @@ static boolean SDLIsInitialized(void)
     return Mix_QuerySpec(&freq, &format, &channels) != 0;
 }

+#ifdef _WIN32
+// putenv requires a non-const string whose lifetime is the whole program
+static char sdl_mixer_disable_nativemidi[] = "SDL_MIXER_DISABLE_NATIVEMIDI=1";
+#endif
+
 // Initialize music subsystem
 static boolean I_SDL_InitMusic(void)
 {
@@ -208,6 +213,12 @@ static boolean I_SDL_InitMusic(void)
         }
     }

+    #ifdef _WIN32
+    // Never let SDL Mixer use native midi on Windows. Avoids SDL Mixer bug
+    // where music volume affects global application volume.
+    putenv(sdl_mixer_disable_nativemidi);
+    #endif
+
     // Initialize SDL_Mixer for MIDI music playback
     Mix_Init(MIX_INIT_MID);