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 /Alc | |
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.
Diffstat (limited to 'Alc')
-rw-r--r-- | Alc/ALc.c | 29 | ||||
-rw-r--r-- | Alc/ALu.c | 26 |
2 files changed, 53 insertions, 2 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 |