aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2017-07-13 21:30:05 -0700
committerChris Robinson <[email protected]>2017-07-13 21:44:25 -0700
commit22d77b87a3f103eeceec004cd9d053c17bf1b883 (patch)
tree3586ee67ee3800c4df97ebc93164271b7d122dc9
parent67ab9ec4662a8d47a163426193eb962772aca23f (diff)
Store the default effect slot in the context
-rw-r--r--Alc/ALc.c105
-rw-r--r--Alc/ALu.c36
-rw-r--r--OpenAL32/Include/alListener.h2
-rw-r--r--OpenAL32/Include/alMain.h11
4 files changed, 87 insertions, 67 deletions
diff --git a/Alc/ALc.c b/Alc/ALc.c
index 8983025a..107d4ef2 100644
--- a/Alc/ALc.c
+++ b/Alc/ALc.c
@@ -2245,24 +2245,24 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList)
*/
update_failed = AL_FALSE;
SetMixerFPUMode(&oldMode);
- if(device->DefaultSlot)
- {
- ALeffectslot *slot = device->DefaultSlot;
- ALeffectState *state = slot->Effect.State;
-
- state->OutBuffer = device->Dry.Buffer;
- state->OutChannels = device->Dry.NumChannels;
- if(V(state,deviceUpdate)(device) == AL_FALSE)
- update_failed = AL_TRUE;
- else
- UpdateEffectSlotProps(slot);
- }
-
context = ATOMIC_LOAD_SEQ(&device->ContextList);
while(context)
{
ALsizei pos;
+ if(context->DefaultSlot)
+ {
+ ALeffectslot *slot = context->DefaultSlot;
+ ALeffectState *state = slot->Effect.State;
+
+ state->OutBuffer = device->Dry.Buffer;
+ state->OutChannels = device->Dry.NumChannels;
+ if(V(state,deviceUpdate)(device) == AL_FALSE)
+ update_failed = AL_TRUE;
+ else
+ UpdateEffectSlotProps(slot);
+ }
+
WriteLock(&context->PropLock);
LockUIntMapRead(&context->EffectSlotMap);
for(pos = 0;pos < context->EffectSlotMap.size;pos++)
@@ -2390,12 +2390,6 @@ static ALCvoid FreeDevice(ALCdevice *device)
almtx_destroy(&device->BackendLock);
- if(device->DefaultSlot)
- {
- DeinitEffectSlot(device->DefaultSlot);
- device->DefaultSlot = NULL;
- }
-
if(device->BufferMap.size > 0)
{
WARN("(%p) Deleting %d Buffer%s\n", device, device->BufferMap.size,
@@ -2587,6 +2581,12 @@ static void FreeContext(ALCcontext *context)
TRACE("%p\n", context);
+ if(context->DefaultSlot)
+ {
+ DeinitEffectSlot(context->DefaultSlot);
+ context->DefaultSlot = NULL;
+ }
+
auxslots = ATOMIC_EXCHANGE_PTR(&context->ActiveAuxSlots, NULL, almemory_order_relaxed);
al_free(auxslots);
@@ -3595,7 +3595,10 @@ ALC_API ALCcontext* ALC_APIENTRY alcCreateContext(ALCdevice *device, const ALCin
ATOMIC_STORE_SEQ(&device->LastError, ALC_NO_ERROR);
- ALContext = al_calloc(16, sizeof(ALCcontext)+sizeof(ALlistener));
+ if(device->Type == Playback && DefaultEffect.type != AL_EFFECT_NULL)
+ ALContext = al_calloc(16, sizeof(ALCcontext)+sizeof(ALlistener)+sizeof(ALeffectslot));
+ else
+ ALContext = al_calloc(16, sizeof(ALCcontext)+sizeof(ALlistener));
if(!ALContext)
{
almtx_unlock(&device->BackendLock);
@@ -3607,6 +3610,7 @@ ALC_API ALCcontext* ALC_APIENTRY alcCreateContext(ALCdevice *device, const ALCin
InitRef(&ALContext->ref, 1);
ALContext->Listener = (ALlistener*)ALContext->_listener_mem;
+ ALContext->DefaultSlot = NULL;
ALContext->Voices = NULL;
ALContext->VoiceCount = 0;
@@ -3614,6 +3618,26 @@ ALC_API ALCcontext* ALC_APIENTRY alcCreateContext(ALCdevice *device, const ALCin
ATOMIC_INIT(&ALContext->ActiveAuxSlots, NULL);
ALContext->Device = device;
+ if(DefaultEffect.type != AL_EFFECT_NULL)
+ {
+ ALContext->DefaultSlot = (ALeffectslot*)(ALContext->_listener_mem + sizeof(ALlistener));
+ if(InitEffectSlot(ALContext->DefaultSlot) != AL_NO_ERROR)
+ {
+ ALContext->DefaultSlot = NULL;
+ ERR("Failed to initialize the default effect slot\n");
+ }
+ else
+ {
+ aluInitEffectPanning(ALContext->DefaultSlot);
+ if(InitializeEffect(device, ALContext->DefaultSlot, &DefaultEffect) != AL_NO_ERROR)
+ {
+ DeinitEffectSlot(ALContext->DefaultSlot);
+ ALContext->DefaultSlot = NULL;
+ ERR("Failed to initialize the default effect\n");
+ }
+ }
+ }
+
if((err=UpdateDeviceParams(device, attrList)) != ALC_NO_ERROR)
{
almtx_unlock(&device->BackendLock);
@@ -3636,6 +3660,25 @@ ALC_API ALCcontext* ALC_APIENTRY alcCreateContext(ALCdevice *device, const ALCin
}
AllocateVoices(ALContext, 256, device->NumAuxSends);
+ if(ALContext->DefaultSlot)
+ {
+ FPUCtl oldMode;
+ ALeffectslot *slot = ALContext->DefaultSlot;
+ ALeffectState *state = slot->Effect.State;
+
+ SetMixerFPUMode(&oldMode);
+ state->OutBuffer = device->Dry.Buffer;
+ state->OutChannels = device->Dry.NumChannels;
+ if(V(state,deviceUpdate)(device) != AL_FALSE)
+ UpdateEffectSlotProps(slot);
+ else
+ {
+ DeinitEffectSlot(ALContext->DefaultSlot);
+ ALContext->DefaultSlot = NULL;
+ }
+ RestoreFPUMode(&oldMode);
+ }
+
ALCdevice_IncRef(ALContext->Device);
InitContext(ALContext);
@@ -3824,7 +3867,7 @@ ALC_API ALCdevice* ALC_APIENTRY alcOpenDevice(const ALCchar *deviceName)
))
deviceName = NULL;
- device = al_calloc(16, sizeof(ALCdevice)+sizeof(ALeffectslot));
+ device = al_calloc(16, sizeof(ALCdevice));
if(!device)
{
alcSetError(NULL, ALC_OUT_OF_MEMORY);
@@ -4020,26 +4063,6 @@ ALC_API ALCdevice* ALC_APIENTRY alcOpenDevice(const ALCchar *deviceName)
device->Limiter = CreateDeviceLimiter(device);
- if(DefaultEffect.type != AL_EFFECT_NULL)
- {
- device->DefaultSlot = (ALeffectslot*)device->_slot_mem;
- if(InitEffectSlot(device->DefaultSlot) != AL_NO_ERROR)
- {
- device->DefaultSlot = NULL;
- ERR("Failed to initialize the default effect slot\n");
- }
- else
- {
- aluInitEffectPanning(device->DefaultSlot);
- if(InitializeEffect(device, device->DefaultSlot, &DefaultEffect) != AL_NO_ERROR)
- {
- DeinitEffectSlot(device->DefaultSlot);
- device->DefaultSlot = NULL;
- ERR("Failed to initialize the default effect\n");
- }
- }
- }
-
{
ALCdevice *head = ATOMIC_LOAD_SEQ(&DeviceList);
do {
diff --git a/Alc/ALu.c b/Alc/ALu.c
index 35b1061e..e44c6c2c 100644
--- a/Alc/ALu.c
+++ b/Alc/ALu.c
@@ -1030,7 +1030,7 @@ static void CalcNonAttnSourceParams(ALvoice *voice, const struct ALvoiceProps *p
{
SendSlots[i] = props->Send[i].Slot;
if(!SendSlots[i] && i == 0)
- SendSlots[i] = Device->DefaultSlot;
+ SendSlots[i] = ALContext->DefaultSlot;
if(!SendSlots[i] || SendSlots[i]->Params.EffectType == AL_EFFECT_NULL)
{
SendSlots[i] = NULL;
@@ -1100,7 +1100,7 @@ static void CalcAttnSourceParams(ALvoice *voice, const struct ALvoiceProps *prop
{
SendSlots[i] = props->Send[i].Slot;
if(!SendSlots[i] && i == 0)
- SendSlots[i] = Device->DefaultSlot;
+ SendSlots[i] = ALContext->DefaultSlot;
if(!SendSlots[i] || SendSlots[i]->Params.EffectType == AL_EFFECT_NULL)
{
SendSlots[i] = NULL;
@@ -1630,19 +1630,19 @@ void aluMixData(ALCdevice *device, ALvoid *buffer, ALsizei size)
IncrementRef(&device->MixCount);
- if(device->DefaultSlot != NULL)
- {
- ALeffectslot *slot = device->DefaultSlot;
- CalcEffectSlotParams(slot, device);
- for(c = 0;c < slot->NumChannels;c++)
- memset(slot->WetBuffer[c], 0, SamplesToDo*sizeof(ALfloat));
- }
-
ctx = ATOMIC_LOAD(&device->ContextList, almemory_order_acquire);
while(ctx)
{
const struct ALeffectslotArray *auxslots;
+ if(ctx->DefaultSlot != NULL)
+ {
+ ALeffectslot *slot = ctx->DefaultSlot;
+ CalcEffectSlotParams(slot, device);
+ for(c = 0;c < slot->NumChannels;c++)
+ memset(slot->WetBuffer[c], 0, SamplesToDo*sizeof(ALfloat));
+ }
+
auxslots = ATOMIC_LOAD(&ctx->ActiveAuxSlots, almemory_order_acquire);
UpdateContextSources(ctx, auxslots);
@@ -1678,15 +1678,15 @@ void aluMixData(ALCdevice *device, ALvoid *buffer, ALsizei size)
state->OutChannels);
}
- ctx = ctx->next;
- }
+ if(ctx->DefaultSlot != NULL)
+ {
+ const ALeffectslot *slot = ctx->DefaultSlot;
+ ALeffectState *state = slot->Params.EffectState;
+ V(state,process)(SamplesToDo, slot->WetBuffer, state->OutBuffer,
+ state->OutChannels);
+ }
- if(device->DefaultSlot != NULL)
- {
- const ALeffectslot *slot = device->DefaultSlot;
- ALeffectState *state = slot->Params.EffectState;
- V(state,process)(SamplesToDo, slot->WetBuffer, state->OutBuffer,
- state->OutChannels);
+ ctx = ctx->next;
}
/* Increment the clock time. Every second's worth of samples is
diff --git a/OpenAL32/Include/alListener.h b/OpenAL32/Include/alListener.h
index 9a7f9d49..f1a92b0d 100644
--- a/OpenAL32/Include/alListener.h
+++ b/OpenAL32/Include/alListener.h
@@ -26,7 +26,7 @@ struct ALlistenerProps {
};
typedef struct ALlistener {
- ALfloat Position[3];
+ alignas(16) ALfloat Position[3];
ALfloat Velocity[3];
ALfloat Forward[3];
ALfloat Up[3];
diff --git a/OpenAL32/Include/alMain.h b/OpenAL32/Include/alMain.h
index 6bb328e1..4081508e 100644
--- a/OpenAL32/Include/alMain.h
+++ b/OpenAL32/Include/alMain.h
@@ -798,9 +798,6 @@ struct ALCdevice_struct
*/
RefCount MixCount;
- /* Default effect slot */
- struct ALeffectslot *DefaultSlot;
-
// Contexts created on this device
ATOMIC(ALCcontext*) ContextList;
@@ -808,9 +805,6 @@ struct ALCdevice_struct
struct ALCbackend *Backend;
ALCdevice *volatile next;
-
- /* Memory space used by the default slot (Playback devices only) */
- alignas(16) ALCbyte _slot_mem[];
};
// Frequency was requested by the app or config file
@@ -872,12 +866,15 @@ struct ALCcontext_struct {
ATOMIC(struct ALeffectslotArray*) ActiveAuxSlots;
+ /* Default effect slot */
+ struct ALeffectslot *DefaultSlot;
+
ALCdevice *Device;
const ALCchar *ExtensionList;
ALCcontext *volatile next;
- /* Memory space used by the listener */
+ /* Memory space used by the listener (and possibly default effect slot) */
alignas(16) ALCbyte _listener_mem[];
};