Mute sounds with 0 volume when game is minimized/unfocused instead of Stopping all sounds. Fixes (#4336)

This commit is contained in:
Thilo Schulz 2009-11-10 01:08:15 +00:00
parent e8ae8f5d3a
commit 2a0812bc06
5 changed files with 70 additions and 13 deletions

View file

@ -937,6 +937,9 @@ void S_Base_RawSamples( int stream, int samples, int rate, int width, int s_chan
}
rawsamples = s_rawsamples[stream];
if(s_muted->integer)
intVolume = 0;
else
intVolume = 256 * volume * s_volume->value;
if ( s_rawend[stream] < s_soundtime ) {

View file

@ -192,6 +192,7 @@ extern int s_rawend[MAX_RAW_STREAMS];
extern cvar_t *s_volume;
extern cvar_t *s_musicVolume;
extern cvar_t *s_muted;
extern cvar_t *s_doppler;
extern cvar_t *s_testsound;

View file

@ -27,6 +27,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#include "snd_public.h"
cvar_t *s_volume;
cvar_t *s_muted;
cvar_t *s_musicVolume;
cvar_t *s_doppler;
cvar_t *s_backend;
@ -228,11 +229,24 @@ S_Update
=================
*/
void S_Update( void )
{
if(s_muted->integer)
{
if(!(s_muteWhenMinimized->integer && com_minimized->integer) &&
!(s_muteWhenUnfocused->integer && com_unfocused->integer))
{
s_muted->integer = qfalse;
s_muted->modified = qtrue;
}
}
else
{
if((s_muteWhenMinimized->integer && com_minimized->integer) ||
( s_muteWhenUnfocused->integer && com_unfocused->integer ) ) {
S_StopAllSounds( );
return;
(s_muteWhenUnfocused->integer && com_unfocused->integer))
{
s_muted->integer = qtrue;
s_muted->modified = qtrue;
}
}
if( si.Update ) {
@ -450,6 +464,7 @@ void S_Init( void )
s_volume = Cvar_Get( "s_volume", "0.8", CVAR_ARCHIVE );
s_musicVolume = Cvar_Get( "s_musicvolume", "0.25", CVAR_ARCHIVE );
s_muted = Cvar_Get("s_muted", "0", CVAR_TEMP);
s_doppler = Cvar_Get( "s_doppler", "1", CVAR_ARCHIVE );
s_backend = Cvar_Get( "s_backend", "", CVAR_ROM );
s_muteWhenMinimized = Cvar_Get( "s_muteWhenMinimized", "0", CVAR_ARCHIVE );

View file

@ -637,6 +637,9 @@ void S_PaintChannels( int endtime ) {
int ltime, count;
int sampleOffset;
if(s_muted->integer)
snd_vol = 0;
else
snd_vol = s_volume->value*255;
//Com_Printf ("%i to %i\n", s_paintedtime, endtime);

View file

@ -555,6 +555,21 @@ static void _S_AL_SanitiseVector( vec3_t v, int line )
#define AL_THIRD_PERSON_THRESHOLD_SQ (48.0f*48.0f)
/*
=================
S_AL_Gain
Set gain to 0 if muted, otherwise set it to given value.
=================
*/
static void S_AL_Gain(ALuint source, float gainval)
{
if(s_muted->integer)
qalSourcef(source, AL_GAIN, 0.0f);
else
qalSourcef(source, AL_GAIN, gainval);
}
/*
=================
S_AL_ScaleGain
@ -585,13 +600,13 @@ static void S_AL_ScaleGain(src_t *chksrc, vec3_t origin)
if(chksrc->scaleGain != scaleFactor);
{
chksrc->scaleGain = scaleFactor;
qalSourcef(chksrc->alSource, AL_GAIN, chksrc->scaleGain);
S_AL_Gain(chksrc->alSource, chksrc->scaleGain);
}
}
else if(chksrc->scaleGain != chksrc->curGain)
{
chksrc->scaleGain = chksrc->curGain;
qalSourcef(chksrc->alSource, AL_GAIN, chksrc->scaleGain);
S_AL_Gain(chksrc->alSource, chksrc->scaleGain);
}
}
@ -733,7 +748,7 @@ static void S_AL_SrcSetup(srcHandle_t src, sfxHandle_t sfx, alSrcPriority_t prio
// Set up OpenAL source
qalSourcei(curSource->alSource, AL_BUFFER, buffer);
qalSourcef(curSource->alSource, AL_PITCH, 1.0f);
qalSourcef(curSource->alSource, AL_GAIN, curSource->curGain);
S_AL_Gain(curSource->alSource, curSource->curGain);
qalSourcefv(curSource->alSource, AL_POSITION, vec3_origin);
qalSourcefv(curSource->alSource, AL_VELOCITY, vec3_origin);
qalSourcei(curSource->alSource, AL_LOOPING, AL_FALSE);
@ -1591,6 +1606,10 @@ static void S_AL_AllocateStreamChannel( int stream )
S_AL_SrcLock(streamSourceHandles[stream]);
streamSources[stream] = S_AL_SrcGet(streamSourceHandles[stream]);
// make sure that after unmuting the S_AL_Gain in S_Update() does not turn
// volume up prematurely for this source
srcList[streamSourceHandles[stream]].scaleGain = 0.0f;
// Set some streamSource parameters
qalSourcei (streamSources[stream], AL_BUFFER, 0 );
qalSourcei (streamSources[stream], AL_LOOPING, AL_FALSE );
@ -1654,7 +1673,7 @@ void S_AL_RawSamples(int stream, int samples, int rate, int width, int channels,
qalSourceQueueBuffers(streamSources[stream], 1, &buffer);
// Volume
qalSourcef (streamSources[stream], AL_GAIN, volume * s_volume->value * s_alGain->value);
S_AL_Gain (streamSources[stream], volume * s_volume->value * s_alGain->value);
}
/*
@ -1768,6 +1787,10 @@ static void S_AL_MusicSourceGet( void )
S_AL_SrcLock(musicSourceHandle);
musicSource = S_AL_SrcGet(musicSourceHandle);
// make sure that after unmuting the S_AL_Gain in S_Update() does not turn
// volume up prematurely for this source
srcList[musicSourceHandle].scaleGain = 0.0f;
// Set some musicSource parameters
qalSource3f(musicSource, AL_POSITION, 0.0, 0.0, 0.0);
qalSource3f(musicSource, AL_VELOCITY, 0.0, 0.0, 0.0);
@ -1971,7 +1994,7 @@ void S_AL_StartBackgroundTrack( const char *intro, const char *loop )
qalSourceQueueBuffers(musicSource, NUM_MUSIC_BUFFERS, musicBuffers);
// Set the initial gain property
qalSourcef(musicSource, AL_GAIN, s_alGain->value * s_musicVolume->value);
S_AL_Gain(musicSource, s_alGain->value * s_musicVolume->value);
// Start playing
qalSourcePlay(musicSource);
@ -2014,7 +2037,7 @@ void S_AL_MusicUpdate( void )
}
// Set the gain property
qalSourcef(musicSource, AL_GAIN, s_alGain->value * s_musicVolume->value);
S_AL_Gain(musicSource, s_alGain->value * s_musicVolume->value);
}
@ -2093,6 +2116,18 @@ void S_AL_Update( void )
{
int i;
if(s_muted->modified)
{
// muted state changed. Let S_AL_Gain turn up all sources again.
for(i = 0; i < srcCount; i++)
{
if(srcList[i].isActive)
S_AL_Gain(srcList[i].alSource, srcList[i].scaleGain);
}
s_muted->modified = qfalse;
}
// Update SFX channels
S_AL_SrcUpdate();