ref: bf67262a1fa5a49fbf384a2c08f74d930080308b
parent: 79ffc9dbd24613e9f200db4ed9a66f2383048097
author: Jonathan Dowland <jon+github@alcopop.org>
date: Tue Jun 23 17:43:26 EDT 2015
update I_StartSound, S_StartSound with pitch Re-introduce removed code for pitch shifting. In the case of Doom, bring back the code from the linux doom sources. In the case of Heretic and Hexen, uncomment existing code. The original implementation passed a pitch value around through several of the sound routines, including I_StartSound and I_UpdateSoundParams, likely because DMX required it. We won't need it in I_UpdateSoundParams, so I haven't brought those bits back. Adjust the sound driver prototypes for the pitch variable.
--- a/src/doom/s_sound.c
+++ b/src/doom/s_sound.c
@@ -73,6 +73,8 @@
// handle of the sound being played
int handle;
+ int pitch;
+
} channel_t;
// The set of channels available
@@ -389,6 +391,21 @@
return (*vol > 0);
}
+// clamp supplied integer to the range 0 <= x <= 255.
+
+static int Clamp(int x)
+{
+ if (x < 0)
+ {
+ return 0;
+ }
+ else if (x > 255)
+ {
+ return 255;
+ }
+ return x;
+}
+
void S_StartSound(void *origin_p, int sfx_id)
{
sfxinfo_t *sfx;
@@ -395,6 +412,7 @@
mobj_t *origin;
int rc;
int sep;
+ int pitch;
int cnum;
int volume;
@@ -410,9 +428,11 @@
sfx = &S_sfx[sfx_id];
// Initialize sound parameters
+ pitch = NORM_PITCH;
if (sfx->link)
{
volume += sfx->volume;
+ pitch = sfx->pitch;
if (volume < 1)
{
@@ -451,6 +471,17 @@
sep = NORM_SEP;
}
+ // hacks to vary the sfx pitches
+ if (sfx_id >= sfx_sawup && sfx_id <= sfx_sawhit)
+ {
+ pitch += 8 - (M_Random()&15);
+ }
+ else if (sfx_id != sfx_itemup && sfx_id != sfx_tink)
+ {
+ pitch += 16 - (M_Random()&31);
+ }
+ pitch = Clamp(pitch);
+
// kill old sound
S_StopSound(origin);
@@ -473,7 +504,8 @@
sfx->lumpnum = I_GetSfxLumpNum(sfx);
}
- channels[cnum].handle = I_StartSound(sfx, cnum, volume, sep);
+ channels[cnum].pitch = pitch;
+ channels[cnum].handle = I_StartSound(sfx, cnum, volume, sep, channels[cnum].pitch);
}
//
--- a/src/heretic/s_sound.c
+++ b/src/heretic/s_sound.c
@@ -268,10 +268,8 @@
sep = 512 - sep;
}
- // TODO: Play pitch-shifted sounds as in Vanilla Heretic
-
channel[i].pitch = (byte) (NORM_PITCH + (M_Random() & 7) - (M_Random() & 7));
- channel[i].handle = I_StartSound(&S_sfx[sound_id], i, vol, sep);
+ channel[i].handle = I_StartSound(&S_sfx[sound_id], i, vol, sep, channel[i].pitch);
channel[i].mo = origin;
channel[i].sound_id = sound_id;
channel[i].priority = priority;
@@ -327,9 +325,8 @@
S_sfx[sound_id].lumpnum = I_GetSfxLumpNum(&S_sfx[sound_id]);
}
- // TODO: Pitch shifting.
channel[i].pitch = (byte) (NORM_PITCH - (M_Random() & 3) + (M_Random() & 3));
- channel[i].handle = I_StartSound(&S_sfx[sound_id], i, volume, 128);
+ channel[i].handle = I_StartSound(&S_sfx[sound_id], i, volume, 128, channel[i].pitch);
channel[i].mo = origin;
channel[i].sound_id = sound_id;
channel[i].priority = 1; //super low priority.
--- a/src/hexen/s_sound.c
+++ b/src/hexen/s_sound.c
@@ -517,7 +517,8 @@
Channel[i].handle = I_StartSound(&S_sfx[sound_id],
i,
vol,
- sep /* , Channel[i].pitch] */);
+ sep,
+ NORM_PITCH);
Channel[i].sound_id = sound_id;
Channel[i].priority = priority;
Channel[i].volume = volume;
--- a/src/i_pcsound.c
+++ b/src/i_pcsound.c
@@ -174,7 +174,8 @@
static int I_PCS_StartSound(sfxinfo_t *sfxinfo,
int channel,
int vol,
- int sep)
+ int sep,
+ int pitch)
{
int result;
--- a/src/i_sdlsound.c
+++ b/src/i_sdlsound.c
@@ -858,7 +858,7 @@
// is set, but currently not used by mixing.
//
-static int I_SDL_StartSound(sfxinfo_t *sfxinfo, int channel, int vol, int sep)
+static int I_SDL_StartSound(sfxinfo_t *sfxinfo, int channel, int vol, int sep, int pitch)
{
allocated_sound_t *snd;
--- a/src/i_sound.c
+++ b/src/i_sound.c
@@ -308,12 +308,12 @@
}
}
-int I_StartSound(sfxinfo_t *sfxinfo, int channel, int vol, int sep)
+int I_StartSound(sfxinfo_t *sfxinfo, int channel, int vol, int sep, int pitch)
{
if (sound_module != NULL)
{
CheckVolumeSeparation(&vol, &sep);
- return sound_module->StartSound(sfxinfo, channel, vol, sep);
+ return sound_module->StartSound(sfxinfo, channel, vol, sep, pitch);
}
else
{
--- a/src/i_sound.h
+++ b/src/i_sound.h
@@ -135,7 +135,7 @@
// Start a sound on a given channel. Returns the channel id
// or -1 on failure.
- int (*StartSound)(sfxinfo_t *sfxinfo, int channel, int vol, int sep);
+ int (*StartSound)(sfxinfo_t *sfxinfo, int channel, int vol, int sep, int pitch);
// Stop the sound playing on the given channel.
@@ -156,7 +156,7 @@
int I_GetSfxLumpNum(sfxinfo_t *sfxinfo);
void I_UpdateSound(void);
void I_UpdateSoundParams(int channel, int vol, int sep);
-int I_StartSound(sfxinfo_t *sfxinfo, int channel, int vol, int sep);
+int I_StartSound(sfxinfo_t *sfxinfo, int channel, int vol, int sep, int pitch);
void I_StopSound(int channel);
boolean I_SoundIsPlaying(int channel);
void I_PrecacheSounds(sfxinfo_t *sounds, int num_sounds);
--- a/src/strife/s_sound.c
+++ b/src/strife/s_sound.c
@@ -73,6 +73,8 @@
// handle of the sound being played
int handle;
+
+ int pitch;
} channel_t;
@@ -407,6 +409,7 @@
mobj_t *origin;
int rc;
int sep;
+ int pitch;
int cnum;
int volume;
@@ -466,6 +469,7 @@
{
sep = NORM_SEP;
}
+ pitch = NORM_PITCH;
// kill old sound [STRIFE] - nope!
//S_StopSound(origin);
@@ -489,7 +493,7 @@
sfx->lumpnum = I_GetSfxLumpNum(sfx);
}
- channels[cnum].handle = I_StartSound(sfx, cnum, volume, sep);
+ channels[cnum].handle = I_StartSound(sfx, cnum, volume, sep, pitch);
}
@@ -616,7 +620,7 @@
i_voicehandle = S_GetChannel(NULL, &voice->sfx, true);
channels[i_voicehandle].handle
- = I_StartSound(&voice->sfx, i_voicehandle, snd_VoiceVolume, NORM_SEP);
+ = I_StartSound(&voice->sfx, i_voicehandle, snd_VoiceVolume, NORM_SEP, NORM_PITCH);
}
}