From bc5c3086842afacf847eb1d4104957ddc896031f Mon Sep 17 00:00:00 2001 From: Yamagi Burmeister Date: Sat, 19 Jan 2013 09:16:58 +0100 Subject: [PATCH] Add a cvar "s_openal_maxgain" to clamp AL_GAIN This cvar is a last resort if all other measures to prevent overdriven preamplifation fail. Setting it to lower value than 1.0 limits the overall dynamic range, so sound quality is lost. This is especially hearable when low volume samples are encountered, like the shotgun combined with the silencer. --- README | 4 +++- src/client/sound/snd_al.c | 7 +++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/README b/README index ca60b23f..89427d96 100644 --- a/README +++ b/README @@ -620,7 +620,9 @@ vary). The most important options (tested with OpenAL Soft 1.14) are: If the sound is distorted and cracking, most likely the ingame volume is set too high. Lower it by setting the "s_volume" CVAR to 0.3 or even less and use the -system mixer instead! +system mixer instead! If everything failes set s_openal_maxgain to a lower value +like 0.3 to clamp the maximum preamplification gain. But beware! The side effect +is a limited dynamic range! =============================================================================== diff --git a/src/client/sound/snd_al.c b/src/client/sound/snd_al.c index 0a53b300..be269a4f 100644 --- a/src/client/sound/snd_al.c +++ b/src/client/sound/snd_al.c @@ -55,13 +55,12 @@ static ALuint underwaterFilter; static ALuint s_srcnums[MAX_CHANNELS - 1]; static int s_framecount; +cvar_t *s_openal_maxgain; /* Forward Declarations */ static void S_AL_StreamUpdate(void); static void S_AL_StreamDie(void); -/* /Forward Declarations */ - static void AL_InitStreamSource() { @@ -115,6 +114,8 @@ AL_Init(void) return false; } + s_openal_maxgain = Cvar_Get("s_openal_maxgain", "1.0", CVAR_ARCHIVE); + /* check for linear distance extension */ if (!qalIsExtensionPresent("AL_EXT_LINEAR_DISTANCE")) { @@ -293,6 +294,7 @@ AL_PlayChannel(channel_t *ch) qalSourcei(ch->srcnum, AL_BUFFER, sc->bufnum); qalSourcei(ch->srcnum, AL_LOOPING, ch->autosound ? AL_TRUE : AL_FALSE); qalSourcef(ch->srcnum, AL_GAIN, ch->oal_vol); + qalSourcef(ch->srcnum, AL_MAX_GAIN, s_openal_maxgain->value); qalSourcef(ch->srcnum, AL_REFERENCE_DISTANCE, SOUND_FULLVOLUME); qalSourcef(ch->srcnum, AL_MAX_DISTANCE, 8192); qalSourcef(ch->srcnum, AL_ROLLOFF_FACTOR, ch->dist_mult * (8192 - SOUND_FULLVOLUME)); @@ -671,6 +673,7 @@ AL_RawSamples(int samples, int rate, int width, int channels, /* set volume */ qalSourcef(streamSource, AL_GAIN, volume); + qalSourcef(streamSource, AL_MAX_GAIN, s_openal_maxgain->value); /* Shove the data onto the streamSource */ qalSourceQueueBuffers(streamSource, 1, &buffer);