shithub: choc

Download patch

ref: b6938d1533d624a5815660c40aeda9125090f55e
parent: ed820d4af6710f94a5674cebcca855686b2ad57a
author: James Haley <haleyjd@hotmail.com>
date: Sat Sep 11 14:06:16 EDT 2010

Voice API implemented.

Subversion-branch: /branches/strife-branch
Subversion-revision: 2063

--- a/src/strife/info.c
+++ b/src/strife/info.c
@@ -198,7 +198,7 @@
 state_t states[NUMSTATES] =
 {
 
-/*S_NULL*/      { SPR_PLAY, 0, -1, { NULL }, S_NULL },      //00
+/*S_NULL*/          { SPR_PLAY, 0, -1, { NULL }, S_NULL },      //00
 /*S_PNCH_00*/       { SPR_PNCH, 0, 0, { A_Light0 }, S_NULL },       //01
 /*S_WAVE_00*/       { SPR_WAVE, 32768, 3, { NULL }, S_WAVE_01 },        //02
 /*S_WAVE_01*/       { SPR_WAVE, 32769, 3, { NULL }, S_WAVE_02 },        //03
--- a/src/strife/s_sound.c
+++ b/src/strife/s_sound.c
@@ -97,7 +97,7 @@
 int musicVolume = 8;
 
 // haleyjd 08/29/10: [STRIFE] New global variable
-// Maximum volume of voice channel.
+// Volume of voice channel.
 
 int voiceVolume = 15;
 
@@ -105,6 +105,10 @@
 
 static int snd_SfxVolume;
 
+// haleyjd 09/11/10: [STRIFE] Internal voice volume level
+
+static int snd_VoiceVolume;
+
 // Whether songs are mus_paused
 
 static boolean mus_paused;        
@@ -117,6 +121,17 @@
 
 int snd_channels = 8;
 
+// haleyjd 09/11/10: [STRIFE] Handle of current voice channel.
+// This has been implemented at a higher level than it was implemented
+// in strife1.exe, as there it relied on a priority system which was
+// implicit in the SFX_PlayPatch API of DMX. Here we'll just ignore
+// the current voice channel when doing normal sound playing.
+
+static int i_voicehandle = -1;
+
+// haleyjd 09/11/10: [STRIFE] whether to play voices or not
+int disable_voices = 0;
+
 //
 // Initializes sound stuff, including volume
 // Sets channels, SFX and music volume,
@@ -171,6 +186,10 @@
 
     c = &channels[cnum];
 
+    // haleyjd: [STRIFE] If stopping the voice channel, set i_voicehandle to -1
+    if (cnum == i_voicehandle)
+        i_voicehandle = -1;
+
     if (c->sfxinfo)
     {
         // stop the sound playing
@@ -250,8 +269,10 @@
 // S_GetChannel :
 //   If none available, return -1.  Otherwise channel #.
 //
-
-static int S_GetChannel(mobj_t *origin, sfxinfo_t *sfxinfo)
+// haleyjd 09/11/10: [STRIFE] Added an "isvoice" parameter for supporting
+// voice playing.
+//
+static int S_GetChannel(mobj_t *origin, sfxinfo_t *sfxinfo, boolean isvoice)
 {
     // channel number to use
     int                cnum;
@@ -264,8 +285,9 @@
         if (!channels[cnum].sfxinfo)
         {
             break;
-        }
-        else if (origin && channels[cnum].origin == origin)
+        } 
+        else if (origin && channels[cnum].origin == origin &&
+                 (isvoice || cnum != i_voicehandle)) // haleyjd
         {
             S_StopChannel(cnum);
             break;
@@ -280,7 +302,9 @@
         {
             if (channels[cnum].sfxinfo->priority >= sfxinfo->priority)
             {
-                break;
+                // haleyjd 09/11/10: [STRIFE] voice has absolute priority
+                if (isvoice || cnum != i_voicehandle)
+                    break;
             }
         }
 
@@ -452,7 +476,7 @@
     S_StopSound(origin);
 
     // try to find a channel
-    cnum = S_GetChannel(origin, sfx);
+    cnum = S_GetChannel(origin, sfx, false); // haleyjd: not a voice.
 
     if (cnum < 0)
     {
@@ -474,6 +498,54 @@
 }        
 
 //
+// I_StartVoice
+//
+// haleyjd 09/11/10: [STRIFE] New function
+// Note this was in i_sound.c in Strife itself, but relied on DMX-specific
+// features to ensure voice channels had absolute priority. Here we must
+// populate a fake sfxinfo_t and send the sound through some of the normal
+// routines. But in the end, it still works the same.
+//
+void I_StartVoice(const char *lumpname)
+{
+    static sfxinfo_t voicesfx; // a static "fake" sfxinfo for voices.
+    int lumpnum;
+
+    // no voices in deathmatch mode.
+    if(netgame)
+        return;
+
+    // TODO: checks if sfx_SndDevice == 83
+    // This is probably turning off voice if using PC speaker...
+
+    // user has disabled voices?
+    if(disable_voices)
+        return;
+
+    // have a voice playing already? stop it.
+    if (i_voicehandle > 0)
+        S_StopChannel(i_voicehandle);
+
+    // haleyjd: Choco-specific: initialize the voicesfx structure
+    memset(&voicesfx, 0, sizeof(sfxinfo_t));
+    strncpy(voicesfx.name, lumpname, 8);
+    voicesfx.priority = INT_MIN; // make highest possible priority
+    voicesfx.pitch = -1;
+    voicesfx.volume = -1;
+    voicesfx.numchannels = -1;
+    voicesfx.usefulness = -1;
+
+    if((lumpnum = W_CheckNumForName(lumpname)) != -1)
+    {
+        // get a channel for the voice
+        i_voicehandle = S_GetChannel(NULL, &voicesfx, true);
+        voicesfx.lumpnum = lumpnum;
+        channels[i_voicehandle].handle 
+            = I_StartSound(&voicesfx, i_voicehandle, snd_VoiceVolume, NORM_SEP);
+    }
+}
+
+//
 // Stop and resume music, during game PAUSE.
 //
 
@@ -583,6 +655,22 @@
     }
 
     snd_SfxVolume = volume;
+}
+
+//
+// S_SetVoiceVolume
+//
+// haleyjd 09/11/10: [STRIFE]
+// Set the internal voice volume level.
+//
+void S_SetVoiceVolume(int volume)
+{
+    if (volume < 0 || volume > 127)
+    {
+        I_Error("Attempt to set voice volume at %d", volume);
+    }
+
+    snd_VoiceVolume = volume;
 }
 
 //
--- a/src/strife/s_sound.h
+++ b/src/strife/s_sound.h
@@ -61,6 +61,9 @@
 
 void S_StartSound(void *origin, int sound_id);
 
+// haleyjd 09/11/10: [STRIFE] Start a voice.
+void I_StartVoice(const char *lumpname);
+
 // Stop sound for thing at <origin>
 void S_StopSound(mobj_t *origin);
 
@@ -90,6 +93,7 @@
 
 void S_SetMusicVolume(int volume);
 void S_SetSfxVolume(int volume);
+void S_SetVoiceVolume(int volume); // haleyjd 09/11/10: [STRIFE]
 
 extern int snd_channels;