mirror of
https://github.com/dhewm/dhewm3.git
synced 2025-03-22 18:51:05 +00:00
Split EAX usage off OpenAL
New define ID_OPENAL_EAX to enable the deprecated EAX on top of OpenAL. OpenAL Soft can now be used.
This commit is contained in:
parent
f4406290d1
commit
690967c276
9 changed files with 60 additions and 49 deletions
|
@ -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
|
||||
|
|
|
@ -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 );
|
||||
}
|
||||
|
|
|
@ -4,7 +4,9 @@
|
|||
#ifndef __EFXLIBH
|
||||
#define __EFXLIBH
|
||||
|
||||
#if ID_OPENAL_EAX
|
||||
#include "../openal/include/eax4.h"
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -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() ) ) ) {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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];
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue