From 6ebcafd7003cce44d1edd1115e737f1aa826ba1c Mon Sep 17 00:00:00 2001 From: Simon Howard Date: Thu, 25 Sep 2008 18:14:46 +0000 Subject: Add option to low-level sound API to disable the DS prefix for sound effects, for Heretic. Fix sound links. Subversion-branch: /branches/raven-branch Subversion-revision: 1281 --- src/doom/s_sound.c | 2 +- src/heretic/s_sound.c | 2 +- src/i_pcsound.c | 16 +++++++++++++--- src/i_sdlsound.c | 34 +++++++++++++++++++++++++++++----- src/i_sound.c | 8 ++++---- src/i_sound.h | 4 ++-- 6 files changed, 50 insertions(+), 16 deletions(-) diff --git a/src/doom/s_sound.c b/src/doom/s_sound.c index 19d76a6b..f829956c 100644 --- a/src/doom/s_sound.c +++ b/src/doom/s_sound.c @@ -122,7 +122,7 @@ void S_Init(int sfxVolume, int musicVolume) { int i; - I_InitSound(); + I_InitSound(true); I_InitMusic(); I_PrecacheSounds(S_sfx, NUMSFX); diff --git a/src/heretic/s_sound.c b/src/heretic/s_sound.c index a67a56c8..86483402 100644 --- a/src/heretic/s_sound.c +++ b/src/heretic/s_sound.c @@ -493,7 +493,7 @@ void S_UpdateSounds(mobj_t * listener) void S_Init(void) { soundCurve = Z_Malloc(MAX_SND_DIST, PU_STATIC, NULL); - I_InitSound(); + I_InitSound(false); if (snd_Channels > 8) { snd_Channels = 8; diff --git a/src/i_pcsound.c b/src/i_pcsound.c index 7ea545c4..7f8e8996 100644 --- a/src/i_pcsound.c +++ b/src/i_pcsound.c @@ -38,6 +38,7 @@ static boolean pcs_initialised = false; static SDL_mutex *sound_lock; +static boolean use_sfx_prefix; static uint8_t *current_sound_lump = NULL; static uint8_t *current_sound_pos = NULL; @@ -241,8 +242,15 @@ static int I_PCS_GetSfxLumpNum(sfxinfo_t* sfx) { char namebuf[9]; - sprintf(namebuf, "dp%s", DEH_String(sfx->name)); - + if (use_sfx_prefix) + { + sprintf(namebuf, "dp%s", DEH_String(sfx->name)); + } + else + { + strcpy(namebuf, DEH_String(sfx->name)); + } + return W_GetNumForName(namebuf); } @@ -262,8 +270,10 @@ static boolean I_PCS_SoundIsPlaying(int handle) return current_sound_lump != NULL && current_sound_remaining > 0; } -static boolean I_PCS_InitSound(void) +static boolean I_PCS_InitSound(boolean _use_sfx_prefix) { + use_sfx_prefix = _use_sfx_prefix; + // Use the sample rate from the configuration file PCSound_SetSampleRate(snd_samplerate); diff --git a/src/i_sdlsound.c b/src/i_sdlsound.c index 242fcb1c..1586ef18 100644 --- a/src/i_sdlsound.c +++ b/src/i_sdlsound.c @@ -57,6 +57,7 @@ static sfxinfo_t *channels_playing[NUM_CHANNELS]; static int mixer_freq; static Uint16 mixer_format; static int mixer_channels; +static boolean use_sfx_prefix; static void (*ExpandSoundData)(sfxinfo_t *sfxinfo, byte *data, int samplerate, @@ -462,7 +463,7 @@ static void I_SDL_PrecacheSounds(sfxinfo_t *sounds, int num_sounds) fflush(stdout); } - sprintf(namebuf, "ds%s", DEH_String(sounds[i].name)); + GetSfxLumpName(&sounds[i], namebuf); sounds[i].lumpnum = W_CheckNumForName(namebuf); @@ -512,18 +513,39 @@ static boolean LockSound(sfxinfo_t *sfxinfo) return true; } +static void GetSfxLumpName(sfxinfo_t *sfx, char *buf) +{ + // Linked sfx lumps? Get the lump number for the sound linked to. + + if (sfx->link != NULL) + { + sfx = sfx->link; + } + + // Doom adds a DS* prefix to sound lumps; Heretic and Hexen don't + // do this. + + if (use_sfx_prefix) + { + sprintf(buf, "ds%s", DEH_String(sfx->name)); + } + else + { + strcpy(buf, DEH_String(sfx->name)); + } +} // // Retrieve the raw data lump index // for a given SFX name. // -static int I_SDL_GetSfxLumpNum(sfxinfo_t* sfx) +static int I_SDL_GetSfxLumpNum(sfxinfo_t *sfx) { char namebuf[9]; - sprintf(namebuf, "ds%s", DEH_String(sfx->name)); - + GetSfxLumpName(sfx, namebuf); + return W_GetNumForName(namebuf); } @@ -654,10 +676,12 @@ static void I_SDL_ShutdownSound(void) } -static boolean I_SDL_InitSound(void) +static boolean I_SDL_InitSound(boolean _use_sfx_prefix) { int i; + use_sfx_prefix = _use_sfx_prefix; + // No sounds yet for (i=0; iInit()) + if (sound_modules[i]->Init(use_sfx_prefix)) { sound_module = sound_modules[i]; return; @@ -172,7 +172,7 @@ static void InitMusicModule(void) // allocates channel buffer, sets S_sfx lookup. // -void I_InitSound(void) +void I_InitSound(boolean use_sfx_prefix) { boolean nosound, nosfx, nomusic; @@ -206,7 +206,7 @@ void I_InitSound(void) { if (!nosfx) { - InitSfxModule(); + InitSfxModule(use_sfx_prefix); } if (!nomusic) diff --git a/src/i_sound.h b/src/i_sound.h index 6737e8cb..a8562ae1 100644 --- a/src/i_sound.h +++ b/src/i_sound.h @@ -114,7 +114,7 @@ typedef struct // Initialise sound module // Returns true if successfully initialised - boolean (*Init)(void); + boolean (*Init)(boolean use_sfx_prefix); // Shutdown sound module @@ -151,7 +151,7 @@ typedef struct } sound_module_t; -void I_InitSound(void); +void I_InitSound(boolean use_sfx_prefix); void I_ShutdownSound(void); int I_GetSfxLumpNum(sfxinfo_t *sfxinfo); void I_UpdateSound(void); -- cgit v1.2.3