foxygit / doom Log in
commit ee19f832605b17ad153bd492dbc556d7de57b2b6
Author:     ceski <56656010+ceski-1@users.noreply.github.com>
AuthorDate: Wed Oct 25 23:32:59 2023 -0700
Commit:     ceski <56656010+ceski-1@users.noreply.github.com>
CommitDate: Wed Oct 25 23:32:59 2023 -0700

    Add Strife PC speaker sound support
---
 src/doom/d_main.c    |  2 +-
 src/heretic/d_main.c |  2 +-
 src/hexen/h2_main.c  |  2 +-
 src/i_pcsound.c      | 27 ++++++++++++++++++++++-----
 src/i_sdlsound.c     |  4 ++--
 src/i_sound.c        |  8 ++++----
 src/i_sound.h        |  5 +++--
 src/setup/sound.c    |  2 +-
 src/strife/d_main.c  |  2 +-
 9 files changed, 36 insertions(+), 18 deletions(-)

diff --git a/src/doom/d_main.c b/src/doom/d_main.c
index d2e0c635..5b46132f 100644
--- a/src/doom/d_main.c
+++ b/src/doom/d_main.c
@@ -1770,7 +1770,7 @@ void D_DoomMain (void)
     I_CheckIsScreensaver();
     I_InitTimer();
     I_InitJoystick();
-    I_InitSound(true);
+    I_InitSound(doom);
     I_InitMusic();

     printf ("NET_Init: Init network subsystem.\n");
diff --git a/src/heretic/d_main.c b/src/heretic/d_main.c
index 9e81f49e..e140a745 100644
--- a/src/heretic/d_main.c
+++ b/src/heretic/d_main.c
@@ -1020,7 +1020,7 @@ void D_DoomMain(void)
     }

     I_InitTimer();
-    I_InitSound(false);
+    I_InitSound(heretic);
     I_InitMusic();

     tprintf("NET_Init: Init network subsystem.\n", 1);
diff --git a/src/hexen/h2_main.c b/src/hexen/h2_main.c
index 44b28723..bbd39116 100644
--- a/src/hexen/h2_main.c
+++ b/src/hexen/h2_main.c
@@ -477,7 +477,7 @@ void D_DoomMain(void)
     I_CheckIsScreensaver();
     I_InitTimer();
     I_InitJoystick();
-    I_InitSound(false);
+    I_InitSound(hexen);
     I_InitMusic();

     ST_Message("NET_Init: Init networking subsystem.\n");
diff --git a/src/i_pcsound.c b/src/i_pcsound.c
index c1ceb5ab..6eeba1be 100644
--- a/src/i_pcsound.c
+++ b/src/i_pcsound.c
@@ -33,7 +33,7 @@
 static boolean pcs_initialized = false;

 static SDL_mutex *sound_lock;
-static boolean use_sfx_prefix;
+static GameMission_t gamemission;

 static uint8_t *current_sound_lump = NULL;
 static uint8_t *current_sound_pos = NULL;
@@ -184,7 +184,14 @@ static int I_PCS_StartSound(sfxinfo_t *sfxinfo,
         return -1;
     }

-    if (IsDisabledSound(sfxinfo))
+    if (gamemission == strife)
+    {
+        if (!strcmp(sfxinfo->name, "rifle"))
+        {
+            return -1;
+        }
+    }
+    else if (IsDisabledSound(sfxinfo))
     {
         return -1;
     }
@@ -244,9 +251,19 @@ static int I_PCS_GetSfxLumpNum(sfxinfo_t* sfx)
 {
     char namebuf[9];

-    if (use_sfx_prefix)
+    if (gamemission == doom)
+    {
+        M_snprintf(namebuf, sizeof(namebuf), "dp%s", DEH_String(sfx->name));
+    }
+    else if (gamemission == strife)
     {
         M_snprintf(namebuf, sizeof(namebuf), "dp%s", DEH_String(sfx->name));
+
+        if (W_CheckNumForName(namebuf) == -1)
+        {
+            // Missing sounds replaced with DPRIFLE, which is then disabled.
+            M_snprintf(namebuf, sizeof(namebuf), "dp%s", DEH_String("rifle"));
+        }
     }
     else
     {
@@ -272,9 +289,9 @@ static boolean I_PCS_SoundIsPlaying(int handle)
     return current_sound_lump != NULL && current_sound_remaining > 0;
 }

-static boolean I_PCS_InitSound(boolean _use_sfx_prefix)
+static boolean I_PCS_InitSound(GameMission_t mission)
 {
-    use_sfx_prefix = _use_sfx_prefix;
+    gamemission = mission;

     // Use the sample rate from the configuration file

diff --git a/src/i_sdlsound.c b/src/i_sdlsound.c
index f04cd445..26f4139c 100644
--- a/src/i_sdlsound.c
+++ b/src/i_sdlsound.c
@@ -1059,11 +1059,11 @@ static int GetSliceSize(void)
     return 1024;
 }

-static boolean I_SDL_InitSound(boolean _use_sfx_prefix)
+static boolean I_SDL_InitSound(GameMission_t mission)
 {
     int i;

-    use_sfx_prefix = _use_sfx_prefix;
+    use_sfx_prefix = (mission == doom || mission == strife);

     // No sounds yet
     for (i=0; i<NUM_CHANNELS; ++i)
diff --git a/src/i_sound.c b/src/i_sound.c
index 90709662..f08fb2c8 100644
--- a/src/i_sound.c
+++ b/src/i_sound.c
@@ -125,7 +125,7 @@ static boolean SndDeviceInList(snddevice_t device, const snddevice_t *list,
 // Find and initialize a sound_module_t appropriate for the setting
 // in snd_sfxdevice.

-static void InitSfxModule(boolean use_sfx_prefix)
+static void InitSfxModule(GameMission_t mission)
 {
     int i;

@@ -142,7 +142,7 @@ static void InitSfxModule(boolean use_sfx_prefix)
         {
             // Initialize the module

-            if (sound_modules[i]->Init(use_sfx_prefix))
+            if (sound_modules[i]->Init(mission))
             {
                 sound_module = sound_modules[i];
                 return;
@@ -195,7 +195,7 @@ static void InitMusicModule(void)
 //  allocates channel buffer, sets S_sfx lookup.
 //

-void I_InitSound(boolean use_sfx_prefix)
+void I_InitSound(GameMission_t mission)
 {
     boolean nosound, nosfx, nomusic, nomusicpacks;

@@ -250,7 +250,7 @@ void I_InitSound(boolean use_sfx_prefix)

         if (!nosfx)
         {
-            InitSfxModule(use_sfx_prefix);
+            InitSfxModule(mission);
         }

         if (!nomusic)
diff --git a/src/i_sound.h b/src/i_sound.h
index 21dc8cb1..376e1bb9 100644
--- a/src/i_sound.h
+++ b/src/i_sound.h
@@ -21,6 +21,7 @@
 #define __I_SOUND__

 #include "doomtype.h"
+#include "d_mode.h"

 // so that the individual game logic and sound driver code agree
 #define NORM_PITCH 127
@@ -115,7 +116,7 @@ typedef struct
     // Initialise sound module
     // Returns true if successfully initialised

-    boolean (*Init)(boolean use_sfx_prefix);
+    boolean (*Init)(GameMission_t mission);

     // Shutdown sound module

@@ -152,7 +153,7 @@ typedef struct

 } sound_module_t;

-void I_InitSound(boolean use_sfx_prefix);
+void I_InitSound(GameMission_t mission);
 void I_ShutdownSound(void);
 int I_GetSfxLumpNum(sfxinfo_t *sfxinfo);
 void I_UpdateSound(void);
diff --git a/src/setup/sound.c b/src/setup/sound.c
index 6f5de1f7..b0eff044 100644
--- a/src/setup/sound.c
+++ b/src/setup/sound.c
@@ -265,7 +265,7 @@ void ConfigSound(TXT_UNCAST_ARG(widget), void *user_data)
     TXT_AddWidgets(window,
         TXT_NewSeparator("Sound effects"),
         TXT_NewRadioButton("Disabled", &snd_sfxdevice, SNDDEVICE_NONE),
-        TXT_If(gamemission == doom,
+        TXT_If(gamemission == doom || gamemission == strife,
             TXT_NewRadioButton("PC speaker effects", &snd_sfxdevice,
                                SNDDEVICE_PCSPEAKER)),
         TXT_NewRadioButton("Digital sound effects",
diff --git a/src/strife/d_main.c b/src/strife/d_main.c
index 876fe74a..f8adeb49 100644
--- a/src/strife/d_main.c
+++ b/src/strife/d_main.c
@@ -1860,7 +1860,7 @@ void D_DoomMain (void)
     // fraggle 20130405: I_InitTimer is needed here for the netgame
     // startup. Start low-level sound init here too.
     I_InitTimer();
-    I_InitSound(true);
+    I_InitSound(strife);
     I_InitMusic();

     if(devparm) // [STRIFE]