diff --git a/neo/framework/BuildDefines.h b/neo/framework/BuildDefines.h index 835711fe..ce72b7d4 100644 --- a/neo/framework/BuildDefines.h +++ b/neo/framework/BuildDefines.h @@ -125,6 +125,10 @@ If you have questions concerning this license or the applicable additional terms # endif #endif +#ifndef ID_OPENAL_EAX +# define ID_OPENAL_EAX 0 +#endif + #ifndef ID_ALLOW_D3XP # if defined( MACOS_X ) # define ID_ALLOW_D3XP 0 diff --git a/neo/framework/Session_menu.cpp b/neo/framework/Session_menu.cpp index a73c3e71..5906d6ef 100644 --- a/neo/framework/Session_menu.cpp +++ b/neo/framework/Session_menu.cpp @@ -889,6 +889,7 @@ void idSessionLocal::HandleMainMenuCommands( const char *menuCommand ) { int eax = soundSystem->IsEAXAvailable(); switch ( eax ) { case 2: + cvarSystem->SetCVarBool( "s_useOpenAL", false ); // OpenAL subsystem load failed MessageBox( MSG_OK, common->GetLanguageDict()->GetString( "#str_07238" ), common->GetLanguageDict()->GetString( "#str_07231" ), true ); break; @@ -908,8 +909,6 @@ void idSessionLocal::HandleMainMenuCommands( const char *menuCommand ) { break; } } else { - // also turn off OpenAL so we fully go back to legacy mixer - cvarSystem->SetCVarBool( "s_useOpenAL", false ); // when you restart MessageBox( MSG_OK, common->GetLanguageDict()->GetString( "#str_04137" ), common->GetLanguageDict()->GetString( "#str_07231" ), true ); } diff --git a/neo/sound/efxlib.h b/neo/sound/efxlib.h index c6ec9e95..97de084c 100644 --- a/neo/sound/efxlib.h +++ b/neo/sound/efxlib.h @@ -4,7 +4,9 @@ #ifndef __EFXLIBH #define __EFXLIBH +#if ID_OPENAL_EAX #include "../openal/include/eax4.h" +#endif diff --git a/neo/sound/snd_cache.cpp b/neo/sound/snd_cache.cpp index 5c1b7049..ec356a51 100644 --- a/neo/sound/snd_cache.cpp +++ b/neo/sound/snd_cache.cpp @@ -528,7 +528,7 @@ void idSoundSample::Load( void ) { // OGG decompressed at load time (when smaller than s_decompressionLimit seconds, 6 seconds by default) if ( objectInfo.wFormatTag == WAVE_FORMAT_TAG_OGG ) { -#if defined(MACOS_X) +#if !ID_OPENAL_EAX if ( ( objectSize < ( ( int ) objectInfo.nSamplesPerSec * idSoundSystemLocal::s_decompressionLimit.GetInteger() ) ) ) { #else if ( ( alIsExtensionPresent( ID_ALCHAR "EAX-RAM" ) == AL_TRUE ) && ( objectSize < ( ( int ) objectInfo.nSamplesPerSec * idSoundSystemLocal::s_decompressionLimit.GetInteger() ) ) ) { diff --git a/neo/sound/snd_efxfile.cpp b/neo/sound/snd_efxfile.cpp index 3ce98d5f..01387814 100644 --- a/neo/sound/snd_efxfile.cpp +++ b/neo/sound/snd_efxfile.cpp @@ -79,6 +79,7 @@ idEFXFile::ReadEffect =============== */ bool idEFXFile::ReadEffect( idLexer &src, idSoundEffect *effect ) { +#if ID_OPENAL_EAX idToken name, token; if ( !src.ReadToken( &token ) ) @@ -183,6 +184,7 @@ bool idEFXFile::ReadEffect( idLexer &src, idSoundEffect *effect ) { // other effect (not supported at the moment) src.Error( "idEFXFile::ReadEffect: Unknown effect definition" ); } +#endif return false; } diff --git a/neo/sound/snd_local.h b/neo/sound/snd_local.h index b4e10644..a2a45543 100644 --- a/neo/sound/snd_local.h +++ b/neo/sound/snd_local.h @@ -765,10 +765,12 @@ public: ALCcontext *openalContext; ALsizei openalSourceCount; openalSource_t openalSources[256]; +#if ID_OPENAL_EAX EAXSet alEAXSet; EAXGet alEAXGet; EAXSetBufferMode alEAXSetBufferMode; EAXGetBufferMode alEAXGetBufferMode; +#endif idEFXFile EFXDatabase; bool efxloaded; // latches diff --git a/neo/sound/snd_system.cpp b/neo/sound/snd_system.cpp index 69389ac3..58f42f88 100644 --- a/neo/sound/snd_system.cpp +++ b/neo/sound/snd_system.cpp @@ -164,7 +164,7 @@ void ListSounds_f( const idCmdArgs &args ) { common->Printf( "%8d total samples loaded\n", totalSamples ); common->Printf( "%8d kB total system memory used\n", totalMemory >> 10 ); #if ID_OPENAL - common->Printf( "%8d kB total OpenAL audio memory used\n", ( alGetInteger( alGetEnumValue( (ALubyte*)"AL_EAX_RAM_SIZE" ) ) - alGetInteger( alGetEnumValue( (ALubyte*)"AL_EAX_RAM_FREE" ) ) ) >> 10 ); + common->Printf( "%8d kB total OpenAL audio memory used\n", ( alGetInteger( alGetEnumValue( "AL_EAX_RAM_SIZE" ) ) - alGetInteger( alGetEnumValue( "AL_EAX_RAM_FREE" ) ) ) >> 10 ); #endif } @@ -344,19 +344,28 @@ void idSoundSystemLocal::Init() { alcMakeContextCurrent( openalContext ); common->Printf( "Done.\n" ); +#if ID_OPENAL_EAX // try to obtain EAX extensions if ( idSoundSystemLocal::s_useEAXReverb.GetBool() && alIsExtensionPresent( ID_ALCHAR "EAX4.0" ) ) { idSoundSystemLocal::s_useOpenAL.SetBool( true ); // EAX presence causes AL enable alEAXSet = (EAXSet)alGetProcAddress( ID_ALCHAR "EAXSet" ); alEAXGet = (EAXGet)alGetProcAddress( ID_ALCHAR "EAXGet" ); common->Printf( "OpenAL: found EAX 4.0 extension\n" ); + EAXAvailable = 1; } else { common->Printf( "OpenAL: EAX 4.0 extension not found\n" ); idSoundSystemLocal::s_useEAXReverb.SetBool( false ); alEAXSet = (EAXSet)NULL; alEAXGet = (EAXGet)NULL; + EAXAvailable = 0; } +#else + common->Printf("OpenAL: EAX 4.0 not supported in this build\n"); + idSoundSystemLocal::s_useEAXReverb.SetBool( false ); + EAXAvailable = 0; +#endif +#if ID_OPENAL_EAX // try to obtain EAX-RAM extension - not required for operation if ( alIsExtensionPresent( ID_ALCHAR "EAX-RAM" ) == AL_TRUE ) { alEAXSetBufferMode = (EAXSetBufferMode)alGetProcAddress( ID_ALCHAR "EAXSetBufferMode" ); @@ -367,51 +376,37 @@ void idSoundSystemLocal::Init() { alEAXGetBufferMode = (EAXGetBufferMode)NULL; common->Printf( "OpenAL: no EAX-RAM extension\n" ); } +#endif - if ( !idSoundSystemLocal::s_useOpenAL.GetBool() ) { - common->Printf( "OpenAL: disabling ( no EAX ). Using legacy mixer.\n" ); + ALuint handle; + openalSourceCount = 0; - alcMakeContextCurrent( NULL ); + while ( openalSourceCount < 256 ) { + alGetError(); + alGenSources( 1, &handle ); + if ( alGetError() != AL_NO_ERROR ) { + break; + } else { + // store in source array + openalSources[openalSourceCount].handle = handle; + openalSources[openalSourceCount].startTime = 0; + openalSources[openalSourceCount].chan = NULL; + openalSources[openalSourceCount].inUse = false; + openalSources[openalSourceCount].looping = false; - alcDestroyContext( openalContext ); - openalContext = NULL; + // initialise sources + alSourcef( handle, AL_ROLLOFF_FACTOR, 0.0f ); - alcCloseDevice( openalDevice ); - openalDevice = NULL; - } else { - - ALuint handle; - openalSourceCount = 0; - - while ( openalSourceCount < 256 ) { - alGetError(); - alGenSources( 1, &handle ); - if ( alGetError() != AL_NO_ERROR ) { - break; - } else { - // store in source array - openalSources[openalSourceCount].handle = handle; - openalSources[openalSourceCount].startTime = 0; - openalSources[openalSourceCount].chan = NULL; - openalSources[openalSourceCount].inUse = false; - openalSources[openalSourceCount].looping = false; - - // initialise sources - alSourcef( handle, AL_ROLLOFF_FACTOR, 0.0f ); - - // found one source - openalSourceCount++; - } + // found one source + openalSourceCount++; } - - common->Printf( "OpenAL: found %s\n", alcGetString( openalDevice, ALC_DEVICE_SPECIFIER ) ); - common->Printf( "OpenAL: found %d hardware voices\n", openalSourceCount ); - - // adjust source count to allow for at least eight stereo sounds to play - openalSourceCount -= 8; - - EAXAvailable = 1; } + + common->Printf( "OpenAL: found %s\n", alcGetString( openalDevice, ALC_DEVICE_SPECIFIER ) ); + common->Printf( "OpenAL: found %d hardware voices\n", openalSourceCount ); + + // adjust source count to allow for at least eight stereo sounds to play + openalSourceCount -= 8; } } @@ -1244,7 +1239,7 @@ void idSoundSystemLocal::FreeOpenALSource( ALuint handle ) { if ( openalSources[i].chan ) { openalSources[i].chan->openalSource = 0; } -#if ID_OPENAL +#if ID_OPENAL_EAX // Reset source EAX ROOM level when freeing stereo source if ( openalSources[i].stereo && alEAXSet ) { long Room = EAXSOURCE_DEFAULTROOM; @@ -1423,11 +1418,11 @@ void idSoundSystemLocal::PrintMemInfo( MemInfo_t *mi ) { /* =============== -idSoundSystemLocal::EAXAvailable +idSoundSystemLocal::IsEAXAvailable =============== */ int idSoundSystemLocal::IsEAXAvailable( void ) { -#if !ID_OPENAL +#if !ID_OPENAL || !ID_OPENAL_EAX return -1; #else ALCdevice *device; diff --git a/neo/sound/snd_world.cpp b/neo/sound/snd_world.cpp index c4fcf6e0..66f50d2c 100644 --- a/neo/sound/snd_world.cpp +++ b/neo/sound/snd_world.cpp @@ -450,7 +450,7 @@ void idSoundWorldLocal::MixLoop( int current44kHz, int numSpeakers, float *final alListenerfv( AL_POSITION, listenerPosition ); alListenerfv( AL_ORIENTATION, listenerOrientation ); -#if ID_OPENAL +#if ID_OPENAL_EAX if ( soundSystemLocal.s_useEAXReverb.GetBool() ) { if ( soundSystemLocal.efxloaded ) { idSoundEffect *effect = NULL; @@ -1745,12 +1745,13 @@ void idSoundWorldLocal::AddChannelContribution( idSoundEmitterLocal *sound, idSo alSourcef( chan->openalSource, AL_GAIN, ( volume ) < ( 1.0f ) ? ( volume ) : ( 1.0f ) ); } alSourcei( chan->openalSource, AL_LOOPING, ( looping && chan->soundShader->entries[0]->hardwareBuffer ) ? AL_TRUE : AL_FALSE ); -#if !defined(MACOS_X) +// TODO is this correct? (was: "!defined(MACOS_X)") +#if ID_OPENAL_EAX alSourcef( chan->openalSource, AL_REFERENCE_DISTANCE, mind ); alSourcef( chan->openalSource, AL_MAX_DISTANCE, maxd ); #endif alSourcef( chan->openalSource, AL_PITCH, ( slowmoActive && !chan->disallowSlow ) ? ( slowmoSpeed ) : ( 1.0f ) ); -#if ID_OPENAL +#if ID_OPENAL_EAX long lOcclusion = ( enviroSuitActive ? -1150 : 0); if ( soundSystemLocal.alEAXSet ) { soundSystemLocal.alEAXSet( &EAXPROPERTYID_EAX_Source, EAXSOURCE_OCCLUSION, chan->openalSource, &lOcclusion, sizeof(lOcclusion) ); @@ -1773,9 +1774,11 @@ void idSoundWorldLocal::AddChannelContribution( idSoundEmitterLocal *sound, idSo chan->lastopenalStreamingBuffer[1] = chan->openalStreamingBuffer[1]; chan->lastopenalStreamingBuffer[2] = chan->openalStreamingBuffer[2]; alGenBuffers( 3, &chan->openalStreamingBuffer[0] ); +#if ID_OPENAL_EAX if ( soundSystemLocal.alEAXSetBufferMode ) { soundSystemLocal.alEAXSetBufferMode( 3, &chan->openalStreamingBuffer[0], alGetEnumValue( ID_ALCHAR "AL_STORAGE_ACCESSIBLE" ) ); } +#endif buffers[0] = chan->openalStreamingBuffer[0]; buffers[1] = chan->openalStreamingBuffer[1]; buffers[2] = chan->openalStreamingBuffer[2]; diff --git a/neo/sys/osx/macosx_sound.cpp b/neo/sys/osx/macosx_sound.cpp index 1fbb4be4..0ab0dcbd 100644 --- a/neo/sys/osx/macosx_sound.cpp +++ b/neo/sys/osx/macosx_sound.cpp @@ -438,6 +438,7 @@ int idAudioHardwareOSX::GetNumberOfSpeakers() { =============== */ bool Sys_LoadOpenAL( void ) { +#if ID_OPENAL OSErr err; long gestaltOSVersion; err = Gestalt(gestaltSystemVersion, &gestaltOSVersion); @@ -445,4 +446,7 @@ bool Sys_LoadOpenAL( void ) { return false; } return true; +#else + return false; +#endif }