shithub: choc

Download patch

ref: cf82ce9d7bb8d71ae583753aab642c5ba4ee8d06
parent: b03de59700f80c75308849ac5f89310d010af066
author: Simon Howard <[email protected]>
date: Wed Nov 24 03:09:48 EST 2010

Add workaround to stop freezeups with old versions of SDL_mixer.

Subversion-branch: /trunk/chocolate-doom
Subversion-revision: 2165

--- a/src/i_sdlsound.c
+++ b/src/i_sdlsound.c
@@ -53,6 +53,8 @@
 #define MAX_SOUND_SLICE_TIME 70 /* ms */
 #define NUM_CHANNELS 16
 
+static boolean setpanning_workaround = false;
+
 static boolean sound_initialized = false;
 
 static Mix_Chunk sound_chunks[NUMSFX];
@@ -620,10 +622,19 @@
     left = ((254 - sep) * vol) / 127;
     right = ((sep) * vol) / 127;
 
+    // SDL_mixer version 1.2.8 and earlier has a bug in the Mix_SetPanning
+    // function.  A workaround is to call Mix_UnregisterAllEffects for
+    // the channel before calling it.  This is undesirable as it may lead
+    // to the channel volumes resetting briefly.
+
+    if (setpanning_workaround)
+    {
+        Mix_UnregisterAllEffects(handle);
+    }
+
     Mix_SetPanning(handle, left, right);
 }
 
-
 //
 // Starting a sound means adding it
 //  to the current list of active sounds
@@ -811,8 +822,34 @@
     }
 #endif
 
+    // SDL_mixer version 1.2.8 and earlier has a bug in the Mix_SetPanning
+    // function that can cause the game to lock up.  If we're using an old
+    // version, we need to apply a workaround.  But the workaround has its
+    // own drawbacks ...
+
+    {
+        const SDL_version *mixer_version;
+        int v;
+
+        mixer_version = Mix_Linked_Version();
+        v = SDL_VERSIONNUM(mixer_version->major,
+                           mixer_version->minor,
+                           mixer_version->patch);
+
+        if (v <= SDL_VERSIONNUM(1, 2, 8))
+        {
+            setpanning_workaround = true;
+            fprintf(stderr, "\n"
+              "ATTENTION: You are using an old version of SDL_mixer!\n"
+              "           This version has a bug that may cause "
+                          "your sound to stutter.\n"
+              "           Please upgrade to a newer version!\n"
+              "\n");
+        }
+    }
+
     Mix_AllocateChannels(NUM_CHANNELS);
-    
+
     SDL_PauseAudio(0);
 
     sound_initialized = true;