From b6938d1533d624a5815660c40aeda9125090f55e Mon Sep 17 00:00:00 2001 From: James Haley Date: Sat, 11 Sep 2010 18:06:16 +0000 Subject: Voice API implemented. Subversion-branch: /branches/strife-branch Subversion-revision: 2063 --- src/strife/info.c | 2 +- src/strife/s_sound.c | 102 +++++++++++++++++++++++++++++++++++++++++++++++---- src/strife/s_sound.h | 4 ++ 3 files changed, 100 insertions(+), 8 deletions(-) (limited to 'src/strife') diff --git a/src/strife/info.c b/src/strife/info.c index af62a5cf..1d4f4c48 100644 --- a/src/strife/info.c +++ b/src/strife/info.c @@ -198,7 +198,7 @@ void A_MaulerSound(); 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 diff --git a/src/strife/s_sound.c b/src/strife/s_sound.c index 6ea28afe..52751e10 100644 --- a/src/strife/s_sound.c +++ b/src/strife/s_sound.c @@ -97,7 +97,7 @@ int sfxVolume = 8; 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 @@ int voiceVolume = 15; 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 @@ static musicinfo_t *mus_playing = NULL; 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 @@ static void S_StopChannel(int cnum) 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 @@ void S_StopSound(mobj_t *origin) // 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 @@ static int S_GetChannel(mobj_t *origin, sfxinfo_t *sfxinfo) 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 @@ static int S_GetChannel(mobj_t *origin, sfxinfo_t *sfxinfo) { 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 @@ void S_StartSound(void *origin_p, int sfx_id) 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) { @@ -473,6 +497,54 @@ void S_StartSound(void *origin_p, int sfx_id) channels[cnum].handle = I_StartSound(sfx, cnum, volume, sep); } +// +// 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. // @@ -585,6 +657,22 @@ void S_SetSfxVolume(int volume) 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; +} + // // Starts some music with the music id found in sounds.h. // diff --git a/src/strife/s_sound.h b/src/strife/s_sound.h index 7bb0a605..1cb70fa0 100644 --- a/src/strife/s_sound.h +++ b/src/strife/s_sound.h @@ -61,6 +61,9 @@ void S_Start(void); 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 void S_StopSound(mobj_t *origin); @@ -90,6 +93,7 @@ void S_UpdateSounds(mobj_t *listener); void S_SetMusicVolume(int volume); void S_SetSfxVolume(int volume); +void S_SetVoiceVolume(int volume); // haleyjd 09/11/10: [STRIFE] extern int snd_channels; -- cgit v1.2.3