Properly pause sounds when entering menu, fixes #330

Otherwise especially looped sounds continue playing while the menu
is open, especially noticeable when opening the menu while firing
the chaingun (the whirring sound continues playing).
This commit is contained in:
Daniel Gibson 2021-04-08 03:28:16 +02:00
parent 1b61053c53
commit 954ff88759
4 changed files with 70 additions and 0 deletions

View file

@ -186,6 +186,7 @@ void idSoundChannel::Clear( void ) {
memset( &parms, 0, sizeof(parms) );
triggered = false;
paused = false;
openalSource = 0;
openalStreamingOffset = 0;
openalStreamingBuffer[0] = openalStreamingBuffer[1] = openalStreamingBuffer[2] = 0;
@ -962,6 +963,49 @@ void idSoundEmitterLocal::StopSound( const s_channelType channel ) {
Sys_LeaveCriticalSection();
}
// DG: to pause active OpenAL sources when entering menu etc
void idSoundEmitterLocal::PauseAll( void ) {
Sys_EnterCriticalSection();
for( int i = 0; i < SOUND_MAX_CHANNELS; i++ ) {
idSoundChannel *chan = &channels[i];
if ( !chan->triggerState ) {
continue;
}
if ( alIsSource( chan->openalSource ) ) {
alSourcePause( chan->openalSource );
chan->paused = true;
}
}
Sys_LeaveCriticalSection();
}
// DG: to resume active OpenAL sources when leaving menu etc
void idSoundEmitterLocal::UnPauseAll( void ) {
Sys_EnterCriticalSection();
for( int i = 0; i < SOUND_MAX_CHANNELS; i++ ) {
idSoundChannel *chan = &channels[i];
if ( !chan->triggerState ) {
continue;
}
if ( alIsSource( chan->openalSource ) && chan->paused ) {
alSourcePlay( chan->openalSource );
chan->paused = false;
}
}
Sys_LeaveCriticalSection();
}
/*
===================
idSoundEmitterLocal::FadeSound

View file

@ -387,6 +387,8 @@ public:
ALuint lastopenalStreamingBuffer[3];
bool stopped;
bool paused; // DG: currently paused, but generally still playing - for when menu is open etc
bool disallowSlow;
};
@ -429,6 +431,9 @@ public:
void Clear( void );
void PauseAll( void ); // DG: to pause active OpenAL sources when entering menu etc
void UnPauseAll( void ); // DG: to resume active OpenAL sources when leaving menu etc
void OverrideParms( const soundShaderParms_t *base, const soundShaderParms_t *over, soundShaderParms_t *out );
void CheckForCompletion( int current44kHzTime );
void Spatialize( idVec3 listenerPos, int listenerArea, idRenderWorld *rw );

View file

@ -1482,6 +1482,16 @@ void idSoundWorldLocal::Pause( void ) {
}
pause44kHz = soundSystemLocal.GetCurrent44kHzTime();
for ( int i = 0; i < emitters.Num(); i++ ) {
idSoundEmitterLocal * emitter = emitters[i];
// if no channels are active, do nothing
if ( emitter == NULL || !emitter->playing ) {
continue;
}
emitter->PauseAll();
}
}
/*
@ -1501,6 +1511,16 @@ void idSoundWorldLocal::UnPause( void ) {
OffsetSoundTime( offset44kHz );
pause44kHz = -1;
for ( int i = 0; i < emitters.Num(); i++ ) {
idSoundEmitterLocal * emitter = emitters[i];
// if no channels are active, do nothing
if ( emitter == NULL || !emitter->playing ) {
continue;
}
emitter->UnPauseAll();
}
}
/*

View file

@ -143,5 +143,6 @@ AL_API void AL_APIENTRY alSourcef( ALuint sid, ALenum param, ALfloat value ) { }
AL_API void AL_APIENTRY alSourceUnqueueBuffers( ALuint sid, ALsizei numEntries, ALuint *bids ) { }
AL_API void AL_APIENTRY alSourcePlay( ALuint sid ) { }
AL_API void AL_APIENTRY alSourcePause( ALuint source ) {}
} // extern "C"