diff options
Diffstat (limited to 'Alc')
-rw-r--r-- | Alc/ALc.c | 105 | ||||
-rw-r--r-- | Alc/ALu.c | 36 |
2 files changed, 82 insertions, 59 deletions
@@ -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 { @@ -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 |