mirror of
https://github.com/id-Software/DOOM-3-BFG.git
synced 2025-03-13 22:22:05 +00:00
Fix Cinematic Audio OpenAL error handling and Classic Doom OpenAL API mistakes
This commit is contained in:
parent
15be4c61ff
commit
210b294246
2 changed files with 31 additions and 19 deletions
|
@ -613,6 +613,9 @@ void I_ShutdownSound( void )
|
|||
}
|
||||
|
||||
I_StopSound( sound->id, 0 );
|
||||
|
||||
// SRS - Detach buffers before freeing memory to allow reallocation in I_InitSound()
|
||||
alSourcei( sound->alSourceVoice, AL_BUFFER, 0 );
|
||||
}
|
||||
|
||||
// Free allocated sound memory
|
||||
|
@ -683,7 +686,7 @@ void I_ShutdownSoundHardware()
|
|||
continue;
|
||||
}
|
||||
|
||||
if( sound->alSourceVoice )
|
||||
if( alIsSource( sound->alSourceVoice ) )
|
||||
{
|
||||
alSourceStop( sound->alSourceVoice );
|
||||
alSourcei( sound->alSourceVoice, AL_BUFFER, 0 );
|
||||
|
@ -694,7 +697,10 @@ void I_ShutdownSoundHardware()
|
|||
// Delete OpenAL buffers for all sounds
|
||||
for( int i = 0; i < NUMSFX; i++ )
|
||||
{
|
||||
alDeleteBuffers( 1, &alBuffers[i] );
|
||||
if( alIsBuffer( alBuffers[i] ) )
|
||||
{
|
||||
alDeleteBuffers( 1, &alBuffers[i] );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -710,7 +716,7 @@ void I_InitSoundChannel( int channel, int numOutputChannels_ )
|
|||
alGenSources( ( ALuint )1, &soundchannel->alSourceVoice );
|
||||
|
||||
alSource3f( soundchannel->alSourceVoice, AL_VELOCITY, 0.f, 0.f, 0.f );
|
||||
alSourcef( soundchannel->alSourceVoice, AL_LOOPING, AL_FALSE );
|
||||
alSourcei( soundchannel->alSourceVoice, AL_LOOPING, AL_FALSE );
|
||||
alSourcef( soundchannel->alSourceVoice, AL_MAX_DISTANCE, SFX_MAX_DISTANCE );
|
||||
alSourcef( soundchannel->alSourceVoice, AL_REFERENCE_DISTANCE, SFX_REFERENCE_DISTANCE );
|
||||
alSourcef( soundchannel->alSourceVoice, AL_ROLLOFF_FACTOR, SFX_ROLLOFF_FACTOR );
|
||||
|
@ -819,7 +825,7 @@ void I_InitMusic( void )
|
|||
alGenSources( ( ALuint )1, &alMusicSourceVoice );
|
||||
|
||||
alSourcef( alMusicSourceVoice, AL_PITCH, 1.f );
|
||||
alSourcef( alMusicSourceVoice, AL_LOOPING, AL_TRUE );
|
||||
alSourcei( alMusicSourceVoice, AL_LOOPING, AL_TRUE );
|
||||
|
||||
alGenBuffers( ( ALuint )1, &alMusicBuffer );
|
||||
|
||||
|
@ -836,14 +842,14 @@ void I_ShutdownMusic( void )
|
|||
{
|
||||
if( Music_initialized )
|
||||
{
|
||||
if( alMusicSourceVoice )
|
||||
if( alIsSource( alMusicSourceVoice ) )
|
||||
{
|
||||
I_StopSong( 0 );
|
||||
alSourcei( alMusicSourceVoice, AL_BUFFER, 0 );
|
||||
alDeleteSources( 1, &alMusicSourceVoice );
|
||||
}
|
||||
|
||||
if( alMusicBuffer )
|
||||
if( alIsBuffer( alMusicBuffer ) )
|
||||
{
|
||||
alDeleteBuffers( 1, &alMusicBuffer );
|
||||
}
|
||||
|
|
|
@ -153,11 +153,11 @@ void CinematicAudio_OpenAL::PlayAudio( uint8_t* data, int size )
|
|||
#elif defined(USE_BINKDEC)
|
||||
Mem_Free( tempdata );
|
||||
#endif
|
||||
CheckALErrors();
|
||||
alSourceQueueBuffers( alMusicSourceVoicecin, 1, &bufid );
|
||||
ALenum error = alGetError();
|
||||
if( error != AL_NO_ERROR )
|
||||
if( CheckALErrors() != AL_NO_ERROR )
|
||||
{
|
||||
common->Warning( "OpenAL Cinematic: %s\n", alGetString( error ) );
|
||||
common->Warning( "CinematicAudio_OpenAL::PlayAudio: error queueing OpenAL hardware buffers" );
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -183,11 +183,11 @@ void CinematicAudio_OpenAL::PlayAudio( uint8_t* data, int size )
|
|||
// SRS - Initiate playback trigger once we have MIN_BUFFERS filled: limit startup latency
|
||||
if( offset == MIN_BUFFERS )
|
||||
{
|
||||
CheckALErrors();
|
||||
alSourceQueueBuffers( alMusicSourceVoicecin, MIN_BUFFERS, &alMusicBuffercin[0] );
|
||||
ALenum error = alGetError();
|
||||
if( error != AL_NO_ERROR )
|
||||
if( CheckALErrors() != AL_NO_ERROR )
|
||||
{
|
||||
common->Warning( "OpenAL Cinematic: %s\n", alGetString( error ) );
|
||||
common->Warning( "CinematicAudio_OpenAL::PlayAudio: error queueing OpenAL hardware buffers" );
|
||||
return;
|
||||
}
|
||||
// SRS - Prepare additional free buffers to handle variable packet rate codecs (e.g. webm vorbis)
|
||||
|
@ -209,11 +209,11 @@ void CinematicAudio_OpenAL::PlayAudio( uint8_t* data, int size )
|
|||
{
|
||||
return;
|
||||
}
|
||||
CheckALErrors();
|
||||
alSourcePlay( alMusicSourceVoicecin );
|
||||
ALenum error = alGetError();
|
||||
if( error != AL_NO_ERROR )
|
||||
if( CheckALErrors() != AL_NO_ERROR )
|
||||
{
|
||||
common->Warning( "OpenAL Cinematic: %s\n", alGetString( error ) );
|
||||
common->Warning( "CinematicAudio_OpenAL::PlayAudio: error playing OpenAL streaming source" );
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -259,6 +259,8 @@ void CinematicAudio_OpenAL::ShutdownAudio()
|
|||
{
|
||||
alSourceStop( alMusicSourceVoicecin );
|
||||
alSourcei( alMusicSourceVoicecin, AL_BUFFER, 0 );
|
||||
|
||||
CheckALErrors();
|
||||
alDeleteSources( 1, &alMusicSourceVoicecin );
|
||||
if( CheckALErrors() == AL_NO_ERROR )
|
||||
{
|
||||
|
@ -266,12 +268,16 @@ void CinematicAudio_OpenAL::ShutdownAudio()
|
|||
}
|
||||
}
|
||||
|
||||
alDeleteBuffers( NUM_BUFFERS, &alMusicBuffercin[0] );
|
||||
if( CheckALErrors() == AL_NO_ERROR )
|
||||
for( int i = 0; i < NUM_BUFFERS; i++ )
|
||||
{
|
||||
for( int i = 0; i < NUM_BUFFERS; i++ )
|
||||
if( alIsBuffer( alMusicBuffercin[i] ) )
|
||||
{
|
||||
alMusicBuffercin[ i ] = 0;
|
||||
CheckALErrors();
|
||||
alDeleteBuffers( 1, &alMusicBuffercin[i] );
|
||||
if( CheckALErrors() == AL_NO_ERROR )
|
||||
{
|
||||
alMusicBuffercin[i] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue