shithub: choc

Download patch

ref: 41eebca5614912abe656e443668b11214c6d51c1
parent: 2ed00ec19cefa96419d376ba726dec93fdcd7d86
author: Simon Howard <fraggle@soulsphere.org>
date: Fri Jul 24 19:12:48 EDT 2015

opl: Add a secret DMXOPTION to reverse stereo channels.

The OPL3 support in Doom's DMX library includes stereo panning support,
but there is a bug where the stereo channels are backwards for some
reason. By default preserve this behavior so that we behave like
Vanilla, but add a secret DMXOPTION so that the channels can be
"reversed" into the correct positions by people who really want it.

Thanks to CSonicGo (@sneakernets) for the original pull request to fix
this (#586), and Alexey Khokholov for assistance in diagnosing the bug.

--- a/src/i_oplmusic.c
+++ b/src/i_oplmusic.c
@@ -352,6 +352,12 @@
 char *snd_dmxoption = "";
 int opl_io_port = 0x388;
 
+// If true, OPL sound channels are reversed to their correct arrangement
+// (as intended by the MIDI standard) rather than the backwards one
+// used by DMX due to a bug.
+
+static boolean opl_stereo_correct = false;
+
 // Load instrument table from GENMIDI lump:
 
 static boolean LoadInstrumentTable(void)
@@ -1133,6 +1139,16 @@
     unsigned int reg_pan;
     unsigned int i;
 
+    // The DMX library has the stereo channels backwards, maybe because
+    // Paul Radek had a Soundblaster card with the channels reversed, or
+    // perhaps it was just a bug in the OPL3 support that was never
+    // finished. By default we preserve this bug, but we also provide a
+    // secret DMXOPTION to fix it.
+    if (opl_stereo_correct)
+    {
+        pan = 144 - pan;
+    }
+
     if (opl_opl3mode)
     {
         if (pan >= 96)
@@ -1727,6 +1743,10 @@
         opl_opl3mode = 0;
         num_opl_voices = OPL_NUM_VOICES;
     }
+
+    // Secret, undocumented DMXOPTION that reverses the stereo channels
+    // into their correct orientation.
+    opl_stereo_correct = strstr(dmxoption, "-reverse") != NULL;
 
     // Initialize all registers.
 
--- a/src/setup/mainmenu.c
+++ b/src/setup/mainmenu.c
@@ -91,7 +91,7 @@
     show_endoom = 0;
     dclick_use = 0;
     novert = 1;
-    snd_dmxoption = "-opl3";
+    snd_dmxoption = "-opl3 -reverse";
     png_screenshots = 1;
 }