=================
*/
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 * snd_speakerlayout.listeners[0].ambientvolume * sqrt(0.5), 65536);
+ chan->listener_volume[1] = (int)bound(0, chan->master_vol * ambient_level.value * snd_speakerlayout.listeners[1].ambientvolume * sqrt(0.5), 65536);
for (i = 2;i < SND_LISTENERS;i++)
chan->listener_volume[i] = 0;
}