[quake3-commits] r1747 - trunk/code/client

DONOTREPLY at icculus.org DONOTREPLY at icculus.org
Mon Nov 9 20:08:16 EST 2009


Author: thilo
Date: 2009-11-09 20:08:15 -0500 (Mon, 09 Nov 2009)
New Revision: 1747

Modified:
   trunk/code/client/snd_dma.c
   trunk/code/client/snd_local.h
   trunk/code/client/snd_main.c
   trunk/code/client/snd_mix.c
   trunk/code/client/snd_openal.c
Log:
Mute sounds with 0 volume when game is minimized/unfocused instead of Stopping all sounds. Fixes (#4336)


Modified: trunk/code/client/snd_dma.c
===================================================================
--- trunk/code/client/snd_dma.c	2009-11-10 00:25:48 UTC (rev 1746)
+++ trunk/code/client/snd_dma.c	2009-11-10 01:08:15 UTC (rev 1747)
@@ -937,7 +937,10 @@
 	}
 	rawsamples = s_rawsamples[stream];
 
-	intVolume = 256 * volume * s_volume->value;
+	if(s_muted->integer)
+		intVolume = 0;
+	else
+		intVolume = 256 * volume * s_volume->value;
 
 	if ( s_rawend[stream] < s_soundtime ) {
 		Com_DPrintf( "S_Base_RawSamples: resetting minimum: %i < %i\n", s_rawend[stream], s_soundtime );

Modified: trunk/code/client/snd_local.h
===================================================================
--- trunk/code/client/snd_local.h	2009-11-10 00:25:48 UTC (rev 1746)
+++ trunk/code/client/snd_local.h	2009-11-10 01:08:15 UTC (rev 1747)
@@ -192,6 +192,7 @@
 
 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;

Modified: trunk/code/client/snd_main.c
===================================================================
--- trunk/code/client/snd_main.c	2009-11-10 00:25:48 UTC (rev 1746)
+++ trunk/code/client/snd_main.c	2009-11-10 01:08:15 UTC (rev 1747)
@@ -27,6 +27,7 @@
 #include "snd_public.h"
 
 cvar_t *s_volume;
+cvar_t *s_muted;
 cvar_t *s_musicVolume;
 cvar_t *s_doppler;
 cvar_t *s_backend;
@@ -229,12 +230,25 @@
 */
 void S_Update( void )
 {
-	if( ( s_muteWhenMinimized->integer && com_minimized->integer ) || 
-		( s_muteWhenUnfocused->integer && com_unfocused->integer ) ) {
-		S_StopAllSounds( );
-		return;
+	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_muted->integer = qtrue;
+			s_muted->modified = qtrue;
+		}
+	}
+	
 	if( si.Update ) {
 		si.Update( );
 	}
@@ -450,6 +464,7 @@
 
 	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 );

Modified: trunk/code/client/snd_mix.c
===================================================================
--- trunk/code/client/snd_mix.c	2009-11-10 00:25:48 UTC (rev 1746)
+++ trunk/code/client/snd_mix.c	2009-11-10 01:08:15 UTC (rev 1747)
@@ -637,7 +637,10 @@
 	int		ltime, count;
 	int		sampleOffset;
 
-	snd_vol = s_volume->value*255;
+	if(s_muted->integer)
+		snd_vol = 0;
+	else
+		snd_vol = s_volume->value*255;
 
 //Com_Printf ("%i to %i\n", s_paintedtime, endtime);
 	while ( s_paintedtime < endtime ) {

Modified: trunk/code/client/snd_openal.c
===================================================================
--- trunk/code/client/snd_openal.c	2009-11-10 00:25:48 UTC (rev 1746)
+++ trunk/code/client/snd_openal.c	2009-11-10 01:08:15 UTC (rev 1747)
@@ -557,6 +557,21 @@
 
 /*
 =================
+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
 Adapt the gain if necessary to get a quicker fadeout when the source is too far away.
 =================
@@ -585,13 +600,13 @@
 		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 @@
 	// 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 @@
 	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 @@
 	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 @@
 	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 @@
 	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 @@
 	}
 
 	// 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 @@
 {
 	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();
 



More information about the quake3-commits mailing list