foxygit / doom Log in
commit 41eebca5614912abe656e443668b11214c6d51c1
Author:     Simon Howard <fraggle@soulsphere.org>
AuthorDate: Fri Jul 24 23:12:48 2015 -0400
Commit:     Simon Howard <fraggle@soulsphere.org>
CommitDate: Fri Jul 24 23:12:48 2015 -0400

    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.
---
 src/i_oplmusic.c     | 20 ++++++++++++++++++++
 src/setup/mainmenu.c |  2 +-
 2 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/src/i_oplmusic.c b/src/i_oplmusic.c
index 33685a5f..354c6a42 100644
--- a/src/i_oplmusic.c
+++ b/src/i_oplmusic.c
@@ -352,6 +352,12 @@ static unsigned int last_perc_count;
 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 @@ static void SetChannelPan(opl_channel_data_t *channel, unsigned int pan)
     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)
@@ -1728,6 +1744,10 @@ static boolean I_OPL_InitMusic(void)
         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.

     OPL_InitRegisters(opl_opl3mode);
diff --git a/src/setup/mainmenu.c b/src/setup/mainmenu.c
index 8c1a26a3..e4756f64 100644
--- a/src/setup/mainmenu.c
+++ b/src/setup/mainmenu.c
@@ -91,7 +91,7 @@ static void SensibleDefaults(void)
     show_endoom = 0;
     dclick_use = 0;
     novert = 1;
-    snd_dmxoption = "-opl3";
+    snd_dmxoption = "-opl3 -reverse";
     png_screenshots = 1;
 }