diff options
author | Chris Robinson <[email protected]> | 2012-01-19 19:30:03 -0800 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2012-01-19 19:30:03 -0800 |
commit | 51e81f4867a02001f390222b6ce86bf212a38bd6 (patch) | |
tree | 8391b8f6dee8924223a80140a67f644a53b5fa7d | |
parent | ae7b61b040059f7112ad6fb38340b8c25d3393b7 (diff) |
Add a global option to apply a reverb effect on source send 0
A special slot on the device is created and processed, so it can be shared
across all contexts on the device. Sources that don't have a slot set on send 0
will use this special slot instead.
-rw-r--r-- | Alc/ALc.c | 29 | ||||
-rw-r--r-- | Alc/ALu.c | 26 | ||||
-rw-r--r-- | OpenAL32/Include/alAuxEffectSlot.h | 1 | ||||
-rw-r--r-- | OpenAL32/Include/alEffect.h | 1 | ||||
-rw-r--r-- | OpenAL32/Include/alMain.h | 3 | ||||
-rw-r--r-- | OpenAL32/alAuxEffectSlot.c | 3 | ||||
-rw-r--r-- | OpenAL32/alEffect.c | 6 |
7 files changed, 65 insertions, 4 deletions
@@ -399,6 +399,9 @@ static ALCboolean TrapALCError = ALC_FALSE; /* One-time configuration init control */ static pthread_once_t alc_config_once = PTHREAD_ONCE_INIT; +/* Forced effect that applies to sources that don't have an effect on send 0 */ +static ALeffect ForcedEffect; + /////////////////////////////////////////////////////// @@ -718,6 +721,10 @@ static void alc_initconfig(void) } } while(next++); } + + str = getenv("__ALSOFT_FORCE_REVERB"); + if(str && str[0]) + GetReverbEffect(&ForcedEffect); } @@ -1296,6 +1303,9 @@ static ALCvoid FreeDevice(ALCdevice *device) { TRACE("%p\n", device); + ALeffectState_Destroy(device->DefaultSlot->EffectState); + device->DefaultSlot->EffectState = NULL; + if(device->BufferMap.size > 0) { WARN("(%p) Deleting %d Buffer(s)\n", device, device->BufferMap.size); @@ -2236,6 +2246,8 @@ ALC_API ALCcontext* ALC_APIENTRY alcCreateContext(ALCdevice *device, const ALCin } while(!CompExchangePtr((XchgPtr*)&device->ContextList, ALContext->next, ALContext)); UnlockLists(); + InitializeEffect(ALContext, device->DefaultSlot, &ForcedEffect); + ALCdevice_DecRef(device); TRACE("Created context %p\n", ALContext); @@ -2414,6 +2426,7 @@ ALC_API ALCdevice* ALC_APIENTRY alcOpenDevice(const ALCchar *deviceName) const ALCchar *fmt; ALCdevice *device; ALCenum err; + ALCint i; DO_INITCONFIG(); @@ -2426,7 +2439,7 @@ ALC_API ALCdevice* ALC_APIENTRY alcOpenDevice(const ALCchar *deviceName) if(deviceName && (!deviceName[0] || strcasecmp(deviceName, "openal soft") == 0 || strcasecmp(deviceName, "openal-soft") == 0)) deviceName = NULL; - device = calloc(1, sizeof(ALCdevice)); + device = calloc(1, sizeof(ALCdevice)+sizeof(ALeffectslot)); if(!device) { alcSetError(NULL, ALC_OUT_OF_MEMORY); @@ -2491,6 +2504,20 @@ ALC_API ALCdevice* ALC_APIENTRY alcOpenDevice(const ALCchar *deviceName) device->NumStereoSources = 1; device->NumMonoSources = device->MaxNoOfSources - device->NumStereoSources; + device->DefaultSlot = (ALeffectslot*)(device+1); + device->DefaultSlot->EffectState = NoneCreate(); + device->DefaultSlot->Gain = 1.0; + device->DefaultSlot->AuxSendAuto = AL_TRUE; + device->DefaultSlot->NeedsUpdate = AL_FALSE; + for(i = 0;i < BUFFERSIZE;i++) + device->DefaultSlot->WetBuffer[i] = 0.0f; + for(i = 0;i < 1;i++) + { + device->DefaultSlot->ClickRemoval[i] = 0.0f; + device->DefaultSlot->PendingClicks[i] = 0.0f; + } + device->DefaultSlot->ref = 0; + // Find a playback device to open LockLists(); if((err=ALCdevice_OpenPlayback(device, deviceName)) != ALC_NO_ERROR) @@ -293,7 +293,11 @@ ALvoid CalcNonAttnSourceParams(ALsource *ALSource, const ALCcontext *ALContext) } for(i = 0;i < NumSends;i++) { - ALSource->Params.Send[i].Slot = ALSource->Send[i].Slot; + ALeffectslot *Slot = ALSource->Send[i].Slot; + + if(!Slot && i == 0) + Slot = Device->DefaultSlot; + ALSource->Params.Send[i].Slot = Slot; ALSource->Params.Send[i].WetGain = WetGain[i] * ListenerGain; } @@ -392,6 +396,8 @@ ALvoid CalcSourceParams(ALsource *ALSource, const ALCcontext *ALContext) { ALeffectslot *Slot = ALSource->Send[i].Slot; + if(!Slot && i == 0) + Slot = Device->DefaultSlot; if(!Slot || Slot->effect.type == AL_EFFECT_NULL) { RoomRolloff[i] = 0.0f; @@ -978,6 +984,24 @@ ALvoid aluMixData(ALCdevice *device, ALvoid *buffer, ALsizei size) ctx = ctx->next; } + + slot = &device->DefaultSlot; + for(c = 0;c < SamplesToDo;c++) + { + (*slot)->WetBuffer[c] += (*slot)->ClickRemoval[0]; + (*slot)->ClickRemoval[0] -= (*slot)->ClickRemoval[0] * (1.0f/256.0f); + } + (*slot)->ClickRemoval[0] += (*slot)->PendingClicks[0]; + (*slot)->PendingClicks[0] = 0.0f; + + if(ExchangeInt(&(*slot)->NeedsUpdate, AL_FALSE)) + ALeffectState_Update((*slot)->EffectState, ctx, *slot); + + ALeffectState_Process((*slot)->EffectState, SamplesToDo, + (*slot)->WetBuffer, device->DryBuffer); + + for(i = 0;i < SamplesToDo;i++) + (*slot)->WetBuffer[i] = 0.0f; UnlockDevice(device); //Post processing loop diff --git a/OpenAL32/Include/alAuxEffectSlot.h b/OpenAL32/Include/alAuxEffectSlot.h index cdff330f..1646031c 100644 --- a/OpenAL32/Include/alAuxEffectSlot.h +++ b/OpenAL32/Include/alAuxEffectSlot.h @@ -35,6 +35,7 @@ typedef struct ALeffectslot } ALeffectslot; +ALvoid InitializeEffect(ALCcontext *Context, ALeffectslot *EffectSlot, ALeffect *effect); ALvoid ReleaseALAuxiliaryEffectSlots(ALCcontext *Context); diff --git a/OpenAL32/Include/alEffect.h b/OpenAL32/Include/alEffect.h index 566458c6..264ada0d 100644 --- a/OpenAL32/Include/alEffect.h +++ b/OpenAL32/Include/alEffect.h @@ -102,6 +102,7 @@ typedef struct ALeffect static __inline ALboolean IsReverbEffect(ALenum type) { return type == AL_EFFECT_REVERB || type == AL_EFFECT_EAXREVERB; } +ALvoid GetReverbEffect(ALeffect *effect); ALvoid ReleaseALEffects(ALCdevice *device); #ifdef __cplusplus diff --git a/OpenAL32/Include/alMain.h b/OpenAL32/Include/alMain.h index c0ffbe5a..fa88a4e4 100644 --- a/OpenAL32/Include/alMain.h +++ b/OpenAL32/Include/alMain.h @@ -598,6 +598,9 @@ struct ALCdevice_struct ALfloat ClickRemoval[MAXCHANNELS]; ALfloat PendingClicks[MAXCHANNELS]; + /* Default effect slot */ + struct ALeffectslot *DefaultSlot; + // Contexts created on this device ALCcontext *volatile ContextList; diff --git a/OpenAL32/alAuxEffectSlot.c b/OpenAL32/alAuxEffectSlot.c index 03a6218b..6c4a31f2 100644 --- a/OpenAL32/alAuxEffectSlot.c +++ b/OpenAL32/alAuxEffectSlot.c @@ -32,7 +32,6 @@ #include "alSource.h" -static ALvoid InitializeEffect(ALCcontext *Context, ALeffectslot *EffectSlot, ALeffect *effect); static ALenum ResizeEffectSlotArray(ALCcontext *Context, ALsizei count); static ALvoid RemoveEffectSlotArray(ALCcontext *Context, ALeffectslot *val); @@ -512,7 +511,7 @@ static ALenum ResizeEffectSlotArray(ALCcontext *Context, ALsizei count) return AL_NO_ERROR; } -static ALvoid InitializeEffect(ALCcontext *Context, ALeffectslot *EffectSlot, ALeffect *effect) +ALvoid InitializeEffect(ALCcontext *Context, ALeffectslot *EffectSlot, ALeffect *effect) { ALenum newtype = (effect ? effect->type : AL_EFFECT_NULL); ALeffectState *State = NULL; diff --git a/OpenAL32/alEffect.c b/OpenAL32/alEffect.c index 11212009..d7f7c3c1 100644 --- a/OpenAL32/alEffect.c +++ b/OpenAL32/alEffect.c @@ -1306,3 +1306,9 @@ static void InitEffectParams(ALeffect *effect, ALenum type) } effect->type = type; } + + +ALvoid GetReverbEffect(ALeffect *effect) +{ + InitEffectParams(effect, AL_EFFECT_EAXREVERB); +} |