cvar_t volume = {CVAR_SAVE, "volume", "0.7", "volume of sound effects"};
cvar_t snd_initialized = { CVAR_READONLY, "snd_initialized", "0", "indicates the sound subsystem is active"};
cvar_t snd_staticvolume = {CVAR_SAVE, "snd_staticvolume", "1", "volume of ambient sound effects (such as swampy sounds at the start of e1m2)"};
-cvar_t snd_soundradius = {CVAR_SAVE, "snd_soundradius", "2000", "radius of weapon sounds and other standard sound effects (monster idle noises are half this radius and flickering light noises are one third of this radius)"};
+cvar_t snd_soundradius = {CVAR_SAVE, "snd_soundradius", "1200", "radius of weapon sounds and other standard sound effects (monster idle noises are half this radius and flickering light noises are one third of this radius)"};
cvar_t snd_spatialization_min_radius = {CVAR_SAVE, "snd_spatialization_min_radius", "10000", "use minimum spatialization above to this radius"};
cvar_t snd_spatialization_max_radius = {CVAR_SAVE, "snd_spatialization_max_radius", "100", "use maximum spatialization below this radius"};
cvar_t snd_spatialization_min = {CVAR_SAVE, "snd_spatialization_min", "0.70", "minimum spatializazion of sounds"};
// (48KHz because a lot of onboard sound cards sucks at any other speed)
static cvar_t snd_speed = {CVAR_SAVE, "snd_speed", "48000", "sound output frequency, in hertz"};
static cvar_t snd_width = {CVAR_SAVE, "snd_width", "2", "sound output precision, in bytes (1 and 2 supported)"};
-static cvar_t snd_channels = {CVAR_SAVE, "snd_channels", "2", "number of channels for the sound ouput (2 for stereo; up to 8 supported for 3D sound)"};
+static cvar_t snd_channels = {CVAR_SAVE, "snd_channels", "2", "number of channels for the sound output (2 for stereo; up to 8 supported for 3D sound)"};
// Ambient sounds
static sfx_t* ambient_sfxs [2] = { NULL, NULL };
=================
*/
extern cvar_t cl_gameplayfix_soundsmovewithentities;
-void SND_Spatialize(channel_t *ch, qboolean isstatic)
+void SND_Spatialize_WithSfx(channel_t *ch, qboolean isstatic, sfx_t *sfx)
{
int i;
double f;
mastervol = ch->master_vol;
- // always apply "master"
- mastervol *= mastervolume.value;
-
- // If this channel does not manage its own volume (like CD tracks)
- if (!(ch->flags & CHANNELFLAG_FULLVOLUME))
- mastervol *= volume.value;
-
// Adjust volume of static sounds
if (isstatic)
mastervol *= snd_staticvolume.value;
}
}
+ // If this channel does not manage its own volume (like CD tracks)
+ if (!(ch->flags & CHANNELFLAG_FULLVOLUME))
+ mastervol *= volume.value;
+
+ // clamp HERE to allow to go at most 10dB past mastervolume (before clamping), when mastervolume < -10dB (so relative volumes don't get too messy)
+ mastervol = bound(0, mastervol, 655360);
+
+ // always apply "master"
+ mastervol *= mastervolume.value;
+
+ // add in ReplayGain very late; prevent clipping when close
+ if(sfx)
+ if(sfx->volume_peak > 0)
+ {
+ // Replaygain support
+ // Con_DPrintf("Setting volume on ReplayGain-enabled track... %f -> ", fvol);
+ mastervol *= sfx->volume_mult;
+ if(mastervol * sfx->volume_peak > 65536)
+ mastervol = 65536 / sfx->volume_peak;
+ // Con_DPrintf("%f\n", fvol);
+ }
+
// clamp HERE to keep relative volumes of the channels correct
mastervol = bound(0, mastervol, 65536);
ch->listener_volume[i] = 0;
}
}
+void SND_Spatialize(channel_t *ch, qboolean isstatic)
+{
+ sfx_t *sfx = ch->sfx;
+ SND_Spatialize_WithSfx(ch, isstatic, sfx);
+}
// =======================================================================
// Start a sound effect
// =======================================================================
-static void S_SetChannelVolume_WithSfx (unsigned int ch_ind, float fvol, sfx_t *sfx);
void S_PlaySfxOnChannel (sfx_t *sfx, channel_t *target_chan, unsigned int flags, vec3_t origin, float fvol, float attenuation, qboolean isstatic, int entnum, int entchannel, int startpos)
{
if (!sfx)
else
target_chan->dist_mult = attenuation / snd_soundradius.value;
- // we have to set the channel volume AFTER the sfx because the function
- // needs it for replaygain support
- S_SetChannelVolume_WithSfx(target_chan - channels, fvol, sfx);
-
// set the listener volumes
- SND_Spatialize (target_chan, isstatic);
+ S_SetChannelVolume(target_chan - channels, fvol);
+ SND_Spatialize_WithSfx (target_chan, isstatic, sfx);
// Lock the SFX during play
S_LockSfx (sfx);
}
}
-static void S_SetChannelVolume_WithSfx (unsigned int ch_ind, float fvol, sfx_t *sfx)
-{
- if(sfx->volume_peak > 0)
- {
- // Replaygain support
- // Con_DPrintf("Setting volume on ReplayGain-enabled track... %f -> ", fvol);
- fvol *= sfx->volume_mult;
- if(fvol * sfx->volume_peak > 1)
- fvol = 1 / sfx->volume_peak;
- // Con_DPrintf("%f\n", fvol);
- }
- channels[ch_ind].master_vol = (int)(fvol * 65536.0f);
-}
-
void S_SetChannelVolume(unsigned int ch_ind, float fvol)
{
- sfx_t *sfx = channels[ch_ind].sfx;
- if(sfx)
- S_SetChannelVolume_WithSfx(ch_ind, fvol, sfx);
+ channels[ch_ind].master_vol = (int)(fvol * 65536.0f);
}
float S_GetChannelPosition (unsigned int ch_ind)
if (snd_spatialization_prologic.integer != 0)
{
- chan->listener_volume[0] = chan->listener_volume[1] = (int)bound(0, chan->master_vol * ambient_level.value * snd_speakerlayout.listeners[i].ambientvolume * sqrt(0.5), 65536);
+ chan->listener_volume[0] = (int)bound(0, chan->master_vol * ambient_level.value * volume.value * mastervolume.value * snd_speakerlayout.listeners[0].ambientvolume * sqrt(0.5), 65536);
+ chan->listener_volume[1] = (int)bound(0, chan->master_vol * ambient_level.value * volume.value * mastervolume.value * snd_speakerlayout.listeners[1].ambientvolume * sqrt(0.5), 65536);
for (i = 2;i < SND_LISTENERS;i++)
chan->listener_volume[i] = 0;
}
else
{
for (i = 0;i < SND_LISTENERS;i++)
- chan->listener_volume[i] = (int)bound(0, chan->master_vol * ambient_level.value * snd_speakerlayout.listeners[i].ambientvolume, 65536);
+ chan->listener_volume[i] = (int)bound(0, chan->master_vol * ambient_level.value * volume.value * mastervolume.value * snd_speakerlayout.listeners[i].ambientvolume, 65536);
}
}
}