mirror of
https://github.com/ioquake/ioq3.git
synced 2025-05-31 00:51:17 +00:00
Mute sounds with 0 volume when game is minimized/unfocused instead of Stopping all sounds. Fixes (#4336)
This commit is contained in:
parent
e8ae8f5d3a
commit
2a0812bc06
5 changed files with 70 additions and 13 deletions
|
@ -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();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue