From 18f9793732cff44fecec3d066c8ffa6dc99f999d Mon Sep 17 00:00:00 2001 From: dhewg Date: Wed, 14 Dec 2011 17:28:29 +0100 Subject: [PATCH] Get rid of the intenal useOpenAL Useless now, there is only OpenAL. --- neo/sound/snd_cache.cpp | 98 ++++++++++++++++++--------------------- neo/sound/snd_emitter.cpp | 37 +++++++-------- neo/sound/snd_local.h | 1 - neo/sound/snd_system.cpp | 4 +- neo/sound/snd_world.cpp | 86 +++++++++++++++++----------------- 5 files changed, 107 insertions(+), 119 deletions(-) diff --git a/neo/sound/snd_cache.cpp b/neo/sound/snd_cache.cpp index ec356a51..2c246571 100644 --- a/neo/sound/snd_cache.cpp +++ b/neo/sound/snd_cache.cpp @@ -355,20 +355,18 @@ void idSoundSample::MakeDefault( void ) { ncd[i*2+1] = sample; } - if ( idSoundSystemLocal::useOpenAL ) { - alGetError(); - alGenBuffers( 1, &openalBuffer ); - if ( alGetError() != AL_NO_ERROR ) { - common->Error( "idSoundCache: error generating OpenAL hardware buffer" ); - } + alGetError(); + alGenBuffers( 1, &openalBuffer ); + if ( alGetError() != AL_NO_ERROR ) { + common->Error( "idSoundCache: error generating OpenAL hardware buffer" ); + } - alGetError(); - alBufferData( openalBuffer, objectInfo.nChannels==1?AL_FORMAT_MONO16:AL_FORMAT_STEREO16, nonCacheData, objectMemSize, objectInfo.nSamplesPerSec ); - if ( alGetError() != AL_NO_ERROR ) { - common->Error( "idSoundCache: error loading data into OpenAL hardware buffer" ); - } else { - hardwareBuffer = true; - } + alGetError(); + alBufferData( openalBuffer, objectInfo.nChannels==1?AL_FORMAT_MONO16:AL_FORMAT_STEREO16, nonCacheData, objectMemSize, objectInfo.nSamplesPerSec ); + if ( alGetError() != AL_NO_ERROR ) { + common->Error( "idSoundCache: error loading data into OpenAL hardware buffer" ); + } else { + hardwareBuffer = true; } defaultSound = true; @@ -486,43 +484,41 @@ void idSoundSample::Load( void ) { CheckForDownSample(); // create hardware audio buffers - if ( idSoundSystemLocal::useOpenAL ) { - // PCM loads directly - if ( objectInfo.wFormatTag == WAVE_FORMAT_TAG_PCM ) { + // PCM loads directly + if ( objectInfo.wFormatTag == WAVE_FORMAT_TAG_PCM ) { + alGetError(); + alGenBuffers( 1, &openalBuffer ); + if ( alGetError() != AL_NO_ERROR ) + common->Error( "idSoundCache: error generating OpenAL hardware buffer" ); + if ( alIsBuffer( openalBuffer ) ) { alGetError(); - alGenBuffers( 1, &openalBuffer ); - if ( alGetError() != AL_NO_ERROR ) - common->Error( "idSoundCache: error generating OpenAL hardware buffer" ); - if ( alIsBuffer( openalBuffer ) ) { - alGetError(); - alBufferData( openalBuffer, objectInfo.nChannels==1?AL_FORMAT_MONO16:AL_FORMAT_STEREO16, nonCacheData, objectMemSize, objectInfo.nSamplesPerSec ); - if ( alGetError() != AL_NO_ERROR ) { - common->Error( "idSoundCache: error loading data into OpenAL hardware buffer" ); - } else { - // Compute amplitude block size - int blockSize = 512 * objectInfo.nSamplesPerSec / 44100 ; + alBufferData( openalBuffer, objectInfo.nChannels==1?AL_FORMAT_MONO16:AL_FORMAT_STEREO16, nonCacheData, objectMemSize, objectInfo.nSamplesPerSec ); + if ( alGetError() != AL_NO_ERROR ) { + common->Error( "idSoundCache: error loading data into OpenAL hardware buffer" ); + } else { + // Compute amplitude block size + int blockSize = 512 * objectInfo.nSamplesPerSec / 44100 ; - // Allocate amplitude data array - amplitudeData = (byte *)soundCacheAllocator.Alloc( ( objectSize / blockSize + 1 ) * 2 * sizeof( short) ); + // Allocate amplitude data array + amplitudeData = (byte *)soundCacheAllocator.Alloc( ( objectSize / blockSize + 1 ) * 2 * sizeof( short) ); - // Creating array of min/max amplitude pairs per blockSize samples - int i; - for ( i = 0; i < objectSize; i+=blockSize ) { - short min = 32767; - short max = -32768; + // Creating array of min/max amplitude pairs per blockSize samples + int i; + for ( i = 0; i < objectSize; i+=blockSize ) { + short min = 32767; + short max = -32768; - int j; - for ( j = 0; j < Min( objectSize - i, blockSize ); j++ ) { - min = ((short *)nonCacheData)[ i + j ] < min ? ((short *)nonCacheData)[ i + j ] : min; - max = ((short *)nonCacheData)[ i + j ] > max ? ((short *)nonCacheData)[ i + j ] : max; - } - - ((short *)amplitudeData)[ ( i / blockSize ) * 2 ] = min; - ((short *)amplitudeData)[ ( i / blockSize ) * 2 + 1 ] = max; + int j; + for ( j = 0; j < Min( objectSize - i, blockSize ); j++ ) { + min = ((short *)nonCacheData)[ i + j ] < min ? ((short *)nonCacheData)[ i + j ] : min; + max = ((short *)nonCacheData)[ i + j ] > max ? ((short *)nonCacheData)[ i + j ] : max; } - hardwareBuffer = true; + ((short *)amplitudeData)[ ( i / blockSize ) * 2 ] = min; + ((short *)amplitudeData)[ ( i / blockSize ) * 2 + 1 ] = max; } + + hardwareBuffer = true; } } @@ -628,15 +624,13 @@ idSoundSample::PurgeSoundSample void idSoundSample::PurgeSoundSample() { purged = true; - if ( hardwareBuffer && idSoundSystemLocal::useOpenAL ) { - alGetError(); - alDeleteBuffers( 1, &openalBuffer ); - if ( alGetError() != AL_NO_ERROR ) { - common->Error( "idSoundCache: error unloading data from OpenAL hardware buffer" ); - } else { - openalBuffer = 0; - hardwareBuffer = false; - } + alGetError(); + alDeleteBuffers( 1, &openalBuffer ); + if ( alGetError() != AL_NO_ERROR ) { + common->Error( "idSoundCache: error unloading data from OpenAL hardware buffer" ); + } else { + openalBuffer = 0; + hardwareBuffer = false; } if ( amplitudeData ) { diff --git a/neo/sound/snd_emitter.cpp b/neo/sound/snd_emitter.cpp index ee48a574..a6050258 100644 --- a/neo/sound/snd_emitter.cpp +++ b/neo/sound/snd_emitter.cpp @@ -222,28 +222,25 @@ idSoundChannel::ALStop =================== */ void idSoundChannel::ALStop( void ) { - if ( idSoundSystemLocal::useOpenAL ) { + if ( alIsSource( openalSource ) ) { + alSourceStop( openalSource ); + alSourcei( openalSource, AL_BUFFER, 0 ); + soundSystemLocal.FreeOpenALSource( openalSource ); + } - if ( alIsSource( openalSource ) ) { - alSourceStop( openalSource ); - alSourcei( openalSource, AL_BUFFER, 0 ); - soundSystemLocal.FreeOpenALSource( openalSource ); + if ( openalStreamingBuffer[0] && openalStreamingBuffer[1] && openalStreamingBuffer[2] ) { + alGetError(); + alDeleteBuffers( 3, &openalStreamingBuffer[0] ); + if ( alGetError() == AL_NO_ERROR ) { + openalStreamingBuffer[0] = openalStreamingBuffer[1] = openalStreamingBuffer[2] = 0; } + } - if ( openalStreamingBuffer[0] && openalStreamingBuffer[1] && openalStreamingBuffer[2] ) { - alGetError(); - alDeleteBuffers( 3, &openalStreamingBuffer[0] ); - if ( alGetError() == AL_NO_ERROR ) { - openalStreamingBuffer[0] = openalStreamingBuffer[1] = openalStreamingBuffer[2] = 0; - } - } - - if ( lastopenalStreamingBuffer[0] && lastopenalStreamingBuffer[1] && lastopenalStreamingBuffer[2] ) { - alGetError(); - alDeleteBuffers( 3, &lastopenalStreamingBuffer[0] ); - if ( alGetError() == AL_NO_ERROR ) { - lastopenalStreamingBuffer[0] = lastopenalStreamingBuffer[1] = lastopenalStreamingBuffer[2] = 0; - } + if ( lastopenalStreamingBuffer[0] && lastopenalStreamingBuffer[1] && lastopenalStreamingBuffer[2] ) { + alGetError(); + alDeleteBuffers( 3, &lastopenalStreamingBuffer[0] ); + if ( alGetError() == AL_NO_ERROR ) { + lastopenalStreamingBuffer[0] = lastopenalStreamingBuffer[1] = lastopenalStreamingBuffer[2] = 0; } } } @@ -452,7 +449,7 @@ void idSoundEmitterLocal::CheckForCompletion( int current44kHzTime ) { if ( !( chan->parms.soundShaderFlags & SSF_LOOPING ) ) { ALint state = AL_PLAYING; - if ( idSoundSystemLocal::useOpenAL && alIsSource( chan->openalSource ) ) { + if ( alIsSource( chan->openalSource ) ) { alGetSourcei( chan->openalSource, AL_SOURCE_STATE, &state ); } idSlowChannel slow = GetSlowChannel( chan ); diff --git a/neo/sound/snd_local.h b/neo/sound/snd_local.h index f1af12a0..552de9e4 100644 --- a/neo/sound/snd_local.h +++ b/neo/sound/snd_local.h @@ -770,7 +770,6 @@ public: idEFXFile EFXDatabase; bool efxloaded; // latches - static bool useOpenAL; static bool useEAXReverb; // mark available during initialization, or through an explicit test static int EAXAvailable; diff --git a/neo/sound/snd_system.cpp b/neo/sound/snd_system.cpp index ab2fc5fb..cee1747b 100644 --- a/neo/sound/snd_system.cpp +++ b/neo/sound/snd_system.cpp @@ -84,7 +84,6 @@ idCVar idSoundSystemLocal::s_muteEAXReverb( "s_muteEAXReverb", "0", CVAR_SOUND | idCVar idSoundSystemLocal::s_decompressionLimit( "s_decompressionLimit", "6", CVAR_SOUND | CVAR_INTEGER | CVAR_ROM, "specifies maximum uncompressed sample length in seconds" ); #endif -bool idSoundSystemLocal::useOpenAL = true; bool idSoundSystemLocal::useEAXReverb = false; int idSoundSystemLocal::EAXAvailable = -1; @@ -1223,7 +1222,8 @@ void idSoundSystemLocal::DoEnviroSuit( float* samples, int numSamples, int numSp float out[10000], *out_p = out + 2; float in[10000], *in_p = in + 2; - assert( !idSoundSystemLocal::useOpenAL ); + // TODO port to OpenAL + assert( false ); if ( !fxList.Num() ) { for ( int i = 0; i < 6; i++ ) { diff --git a/neo/sound/snd_world.cpp b/neo/sound/snd_world.cpp index d56a6e64..ba5c07f2 100644 --- a/neo/sound/snd_world.cpp +++ b/neo/sound/snd_world.cpp @@ -423,67 +423,64 @@ void idSoundWorldLocal::MixLoop( int current44kHz, int numSpeakers, float *final // if noclip flying outside the world, leave silence if ( listenerArea == -1 ) { - if ( idSoundSystemLocal::useOpenAL ) - alListenerf( AL_GAIN, 0.0f ); + alListenerf( AL_GAIN, 0.0f ); return; } // update the listener position and orientation - if ( idSoundSystemLocal::useOpenAL ) { - ALfloat listenerPosition[3]; + ALfloat listenerPosition[3]; - listenerPosition[0] = -listenerPos.y; - listenerPosition[1] = listenerPos.z; - listenerPosition[2] = -listenerPos.x; + listenerPosition[0] = -listenerPos.y; + listenerPosition[1] = listenerPos.z; + listenerPosition[2] = -listenerPos.x; - ALfloat listenerOrientation[6]; + ALfloat listenerOrientation[6]; - listenerOrientation[0] = -listenerAxis[0].y; - listenerOrientation[1] = listenerAxis[0].z; - listenerOrientation[2] = -listenerAxis[0].x; + listenerOrientation[0] = -listenerAxis[0].y; + listenerOrientation[1] = listenerAxis[0].z; + listenerOrientation[2] = -listenerAxis[0].x; - listenerOrientation[3] = -listenerAxis[2].y; - listenerOrientation[4] = listenerAxis[2].z; - listenerOrientation[5] = -listenerAxis[2].x; + listenerOrientation[3] = -listenerAxis[2].y; + listenerOrientation[4] = listenerAxis[2].z; + listenerOrientation[5] = -listenerAxis[2].x; - alListenerf( AL_GAIN, 1.0f ); - alListenerfv( AL_POSITION, listenerPosition ); - alListenerfv( AL_ORIENTATION, listenerOrientation ); + alListenerf( AL_GAIN, 1.0f ); + alListenerfv( AL_POSITION, listenerPosition ); + alListenerfv( AL_ORIENTATION, listenerOrientation ); #if ID_OPENAL_EAX - if ( soundSystemLocal.s_useEAXReverb.GetBool() ) { - if ( soundSystemLocal.efxloaded ) { - idSoundEffect *effect = NULL; - int EnvironmentID = -1; - idStr defaultStr( "default" ); - idStr listenerAreaStr( listenerArea ); + if ( soundSystemLocal.s_useEAXReverb.GetBool() ) { + if ( soundSystemLocal.efxloaded ) { + idSoundEffect *effect = NULL; + int EnvironmentID = -1; + idStr defaultStr( "default" ); + idStr listenerAreaStr( listenerArea ); - soundSystemLocal.EFXDatabase.FindEffect( listenerAreaStr, &effect, &EnvironmentID ); - if (!effect) - soundSystemLocal.EFXDatabase.FindEffect( listenerAreaName, &effect, &EnvironmentID ); - if (!effect) - soundSystemLocal.EFXDatabase.FindEffect( defaultStr, &effect, &EnvironmentID ); + soundSystemLocal.EFXDatabase.FindEffect( listenerAreaStr, &effect, &EnvironmentID ); + if (!effect) + soundSystemLocal.EFXDatabase.FindEffect( listenerAreaName, &effect, &EnvironmentID ); + if (!effect) + soundSystemLocal.EFXDatabase.FindEffect( defaultStr, &effect, &EnvironmentID ); - // only update if change in settings - if ( soundSystemLocal.s_muteEAXReverb.GetBool() || ( listenerEnvironmentID != EnvironmentID ) ) { - EAXREVERBPROPERTIES EnvironmentParameters; + // only update if change in settings + if ( soundSystemLocal.s_muteEAXReverb.GetBool() || ( listenerEnvironmentID != EnvironmentID ) ) { + EAXREVERBPROPERTIES EnvironmentParameters; - // get area reverb setting from EAX Manager - if ( ( effect ) && ( effect->data) && ( memcpy( &EnvironmentParameters, effect->data, effect->datasize ) ) ) { - if ( soundSystemLocal.s_muteEAXReverb.GetBool() ) { - EnvironmentParameters.lRoom = -10000; - EnvironmentID = -2; - } - if ( soundSystemLocal.alEAXSet ) { - soundSystemLocal.alEAXSet( &EAXPROPERTYID_EAX_FXSlot0, EAXREVERB_ALLPARAMETERS, 0, &EnvironmentParameters, sizeof( EnvironmentParameters ) ); - } + // get area reverb setting from EAX Manager + if ( ( effect ) && ( effect->data) && ( memcpy( &EnvironmentParameters, effect->data, effect->datasize ) ) ) { + if ( soundSystemLocal.s_muteEAXReverb.GetBool() ) { + EnvironmentParameters.lRoom = -10000; + EnvironmentID = -2; + } + if ( soundSystemLocal.alEAXSet ) { + soundSystemLocal.alEAXSet( &EAXPROPERTYID_EAX_FXSlot0, EAXREVERB_ALLPARAMETERS, 0, &EnvironmentParameters, sizeof( EnvironmentParameters ) ); } - listenerEnvironmentID = EnvironmentID; } + listenerEnvironmentID = EnvironmentID; } } -#endif } +#endif // debugging option to mute all but a single soundEmitter if ( idSoundSystemLocal::s_singleEmitter.GetInteger() > 0 && idSoundSystemLocal::s_singleEmitter.GetInteger() < emitters.Num() ) { @@ -530,7 +527,8 @@ void idSoundWorldLocal::MixLoop( int current44kHz, int numSpeakers, float *final } } - if ( !idSoundSystemLocal::useOpenAL && enviroSuitActive ) { + // TODO port to OpenAL + if ( false && enviroSuitActive ) { soundSystemLocal.DoEnviroSuit( finalMixBuffer, MIXBUFFER_SAMPLES, numSpeakers ); } } @@ -1718,7 +1716,7 @@ void idSoundWorldLocal::AddChannelContribution( idSoundEmitterLocal *sound, idSo // // allocate and initialize hardware source // - if ( idSoundSystemLocal::useOpenAL && sound->removeStatus < REMOVE_STATUS_SAMPLEFINISHED ) { + if ( sound->removeStatus < REMOVE_STATUS_SAMPLEFINISHED ) { if ( !alIsSource( chan->openalSource ) ) { chan->openalSource = soundSystemLocal.AllocOpenALSource( chan, !chan->leadinSample->hardwareBuffer || !chan->soundShader->entries[0]->hardwareBuffer || looping, chan->leadinSample->objectInfo.nChannels == 2 ); }