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.
This commit is contained in:
Chris Robinson
2012-01-19 19:30:03 -08:00
parent ae7b61b040
commit 51e81f4867
7 changed files with 65 additions and 4 deletions
+28 -1
View File
@@ -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)
+25 -1
View File
@@ -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
+1
View File
@@ -35,6 +35,7 @@ typedef struct ALeffectslot
} ALeffectslot;
ALvoid InitializeEffect(ALCcontext *Context, ALeffectslot *EffectSlot, ALeffect *effect);
ALvoid ReleaseALAuxiliaryEffectSlots(ALCcontext *Context);
+1
View File
@@ -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
+3
View File
@@ -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;
+1 -2
View File
@@ -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;
+6
View File
@@ -1306,3 +1306,9 @@ static void InitEffectParams(ALeffect *effect, ALenum type)
}
effect->type = type;
}
ALvoid GetReverbEffect(ALeffect *effect)
{
InitEffectParams(effect, AL_EFFECT_EAXREVERB);
}