Port the D3XP environment suit effect to EFX

Use a AL_LOWPASS_GAINHF filter to muffle sfx.
This commit is contained in:
dhewg 2012-01-10 17:37:04 +01:00
parent 8ea0f8f0d5
commit d8acc43aca
3 changed files with 52 additions and 18 deletions

View file

@ -600,6 +600,7 @@ public:
idStr listenerAreaName;
ALuint listenerEffect;
ALuint listenerSlot;
ALuint listenerFilter;
int gameMsec;
int game44kHz;
@ -736,6 +737,11 @@ public:
LPALEFFECTI alEffecti;
LPALEFFECTF alEffectf;
LPALEFFECTFV alEffectfv;
LPALGENFILTERS alGenFilters;
LPALDELETEFILTERS alDeleteFilters;
LPALISFILTER alIsFilter;
LPALFILTERI alFilteri;
LPALFILTERF alFilterf;
LPALGENAUXILIARYEFFECTSLOTS alGenAuxiliaryEffectSlots;
LPALDELETEAUXILIARYEFFECTSLOTS alDeleteAuxiliaryEffectSlots;
LPALISAUXILIARYEFFECTSLOT alIsAuxiliaryEffectSlot;

View file

@ -349,6 +349,11 @@ void idSoundSystemLocal::Init() {
alEffecti = (LPALEFFECTI)alGetProcAddress("alEffecti");
alEffectf = (LPALEFFECTF)alGetProcAddress("alEffectf");
alEffectfv = (LPALEFFECTFV)alGetProcAddress("alEffectfv");
alGenFilters = (LPALGENFILTERS)alGetProcAddress("alGenFilters");
alDeleteFilters = (LPALDELETEFILTERS)alGetProcAddress("alDeleteFilters");
alIsFilter = (LPALISFILTER)alGetProcAddress("alIsFilter");
alFilteri = (LPALFILTERI)alGetProcAddress("alFilteri");
alFilterf = (LPALFILTERF)alGetProcAddress("alFilterf");
alGenAuxiliaryEffectSlots = (LPALGENAUXILIARYEFFECTSLOTS)alGetProcAddress("alGenAuxiliaryEffectSlots");
alDeleteAuxiliaryEffectSlots = (LPALDELETEAUXILIARYEFFECTSLOTS)alGetProcAddress("alDeleteAuxiliaryEffectSlots");
alIsAuxiliaryEffectSlot = (LPALISAUXILIARYEFFECTSLOT)alGetProcAddress("alIsAuxiliaryEffectSlot");;
@ -364,6 +369,11 @@ void idSoundSystemLocal::Init() {
alEffecti = NULL;
alEffectf = NULL;
alEffectfv = NULL;
alGenFilters = NULL;
alDeleteFilters = NULL;
alIsFilter = NULL;
alFilteri = NULL;
alFilterf = NULL;
alGenAuxiliaryEffectSlots = NULL;
alDeleteAuxiliaryEffectSlots = NULL;
alIsAuxiliaryEffectSlot = NULL;

View file

@ -49,14 +49,31 @@ void idSoundWorldLocal::Init( idRenderWorld *renderWorld ) {
listenerArea = 0;
listenerAreaName = "Undefined";
if (idSoundSystemLocal::useEFXReverb && !soundSystemLocal.alIsAuxiliaryEffectSlot(listenerSlot)) {
alGetError();
if (idSoundSystemLocal::useEFXReverb) {
if (!soundSystemLocal.alIsAuxiliaryEffectSlot(listenerSlot)) {
alGetError();
soundSystemLocal.alGenAuxiliaryEffectSlots(1, &listenerSlot);
ALuint e = alGetError();
if (e != AL_NO_ERROR) {
common->Warning("idSoundWorldLocal::Init: alGenAuxiliaryEffectSlots failed: 0x%x", e);
listenerSlot = AL_EFFECTSLOT_NULL;
soundSystemLocal.alGenAuxiliaryEffectSlots(1, &listenerSlot);
ALuint e = alGetError();
if (e != AL_NO_ERROR) {
common->Warning("idSoundWorldLocal::Init: alGenAuxiliaryEffectSlots failed: 0x%x", e);
listenerSlot = AL_EFFECTSLOT_NULL;
}
}
if (!soundSystemLocal.alIsFilter(listenerFilter)) {
alGetError();
soundSystemLocal.alGenFilters(1, &listenerFilter);
ALuint e = alGetError();
if (e != AL_NO_ERROR) {
common->Warning("idSoundWorldLocal::Init: alGenFilters failed: 0x%x", e);
listenerFilter = AL_FILTER_NULL;
} else {
soundSystemLocal.alFilteri(listenerFilter, AL_FILTER_TYPE, AL_FILTER_LOWPASS);
// EAX occusion value was -1150; pow(10.0, -1150/2000.0)
soundSystemLocal.alFilterf(listenerFilter, AL_LOWPASS_GAINHF, 0.266073f);
}
}
}
@ -118,10 +135,17 @@ void idSoundWorldLocal::Shutdown() {
AVIClose();
if (idSoundSystemLocal::useEFXReverb && soundSystemLocal.alIsAuxiliaryEffectSlot(listenerSlot)) {
soundSystemLocal.alAuxiliaryEffectSloti(listenerSlot, AL_EFFECTSLOT_EFFECT, AL_EFFECTSLOT_NULL);
soundSystemLocal.alDeleteAuxiliaryEffectSlots(1, &listenerSlot);
listenerSlot = AL_EFFECTSLOT_NULL;
if (idSoundSystemLocal::useEFXReverb) {
if (soundSystemLocal.alIsAuxiliaryEffectSlot(listenerSlot)) {
soundSystemLocal.alAuxiliaryEffectSloti(listenerSlot, AL_EFFECTSLOT_EFFECT, AL_EFFECTSLOT_NULL);
soundSystemLocal.alDeleteAuxiliaryEffectSlots(1, &listenerSlot);
listenerSlot = AL_EFFECTSLOT_NULL;
}
if (soundSystemLocal.alIsFilter(listenerFilter)) {
soundSystemLocal.alDeleteFilters(1, &listenerFilter);
listenerFilter = AL_FILTER_NULL;
}
}
for ( i = 0; i < emitters.Num(); i++ ) {
@ -1752,14 +1776,8 @@ void idSoundWorldLocal::AddChannelContribution( idSoundEmitterLocal *sound, idSo
alSourcef( chan->openalSource, AL_PITCH, ( slowmoActive && !chan->disallowSlow ) ? ( slowmoSpeed ) : ( 1.0f ) );
if (idSoundSystemLocal::useEFXReverb)
alSource3i(chan->openalSource, AL_AUXILIARY_SEND_FILTER, listenerSlot, 0, AL_FILTER_NULL);
alSource3i(chan->openalSource, AL_AUXILIARY_SEND_FILTER, listenerSlot, 0, enviroSuitActive ? listenerFilter : AL_FILTER_NULL);
#if 0 // TODO how to port this to efx?
long lOcclusion = ( enviroSuitActive ? -1150 : 0);
if ( soundSystemLocal.alEAXSet ) {
soundSystemLocal.alEAXSet( &EAXPROPERTYID_EAX_Source, EAXSOURCE_OCCLUSION, chan->openalSource, &lOcclusion, sizeof(lOcclusion) );
}
#endif
if ( ( !looping && chan->leadinSample->hardwareBuffer ) || ( looping && chan->soundShader->entries[0]->hardwareBuffer ) ) {
// handle uncompressed (non streaming) single shot and looping sounds
if ( chan->triggered ) {