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.
This commit is contained in:
Yamagi Burmeister 2013-01-19 09:16:58 +01:00
parent 1f5012aec3
commit bc5c308684
2 changed files with 8 additions and 3 deletions

4
README
View file

@ -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 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 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!
=============================================================================== ===============================================================================

View file

@ -55,13 +55,12 @@ static ALuint underwaterFilter;
static ALuint s_srcnums[MAX_CHANNELS - 1]; static ALuint s_srcnums[MAX_CHANNELS - 1];
static int s_framecount; static int s_framecount;
cvar_t *s_openal_maxgain;
/* Forward Declarations */ /* Forward Declarations */
static void S_AL_StreamUpdate(void); static void S_AL_StreamUpdate(void);
static void S_AL_StreamDie(void); static void S_AL_StreamDie(void);
/* /Forward Declarations */
static void static void
AL_InitStreamSource() AL_InitStreamSource()
{ {
@ -115,6 +114,8 @@ AL_Init(void)
return false; return false;
} }
s_openal_maxgain = Cvar_Get("s_openal_maxgain", "1.0", CVAR_ARCHIVE);
/* check for linear distance extension */ /* check for linear distance extension */
if (!qalIsExtensionPresent("AL_EXT_LINEAR_DISTANCE")) 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_BUFFER, sc->bufnum);
qalSourcei(ch->srcnum, AL_LOOPING, ch->autosound ? AL_TRUE : AL_FALSE); qalSourcei(ch->srcnum, AL_LOOPING, ch->autosound ? AL_TRUE : AL_FALSE);
qalSourcef(ch->srcnum, AL_GAIN, ch->oal_vol); 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_REFERENCE_DISTANCE, SOUND_FULLVOLUME);
qalSourcef(ch->srcnum, AL_MAX_DISTANCE, 8192); qalSourcef(ch->srcnum, AL_MAX_DISTANCE, 8192);
qalSourcef(ch->srcnum, AL_ROLLOFF_FACTOR, ch->dist_mult * (8192 - SOUND_FULLVOLUME)); 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 */ /* set volume */
qalSourcef(streamSource, AL_GAIN, volume); qalSourcef(streamSource, AL_GAIN, volume);
qalSourcef(streamSource, AL_MAX_GAIN, s_openal_maxgain->value);
/* Shove the data onto the streamSource */ /* Shove the data onto the streamSource */
qalSourceQueueBuffers(streamSource, 1, &buffer); qalSourceQueueBuffers(streamSource, 1, &buffer);