AL_API ALvoid AL_APIENTRY alDeferUpdatesSOFT(void) { ALCcontext *Context; Context = GetContextRef(); if(!Context) return; if(!Context->DeferUpdates) { ALboolean UpdateSources; ALsource **src, **src_end; ALeffectslot **slot, **slot_end; FPUCtl oldMode; SetMixerFPUMode(&oldMode); LockContext(Context); Context->DeferUpdates = AL_TRUE; /* Make sure all pending updates are performed */ UpdateSources = ExchangeInt(&Context->UpdateSources, AL_FALSE); src = Context->ActiveSources; src_end = src + Context->ActiveSourceCount; while(src != src_end) { if((*src)->state != AL_PLAYING) { Context->ActiveSourceCount--; *src = *(--src_end); continue; } if(ExchangeInt(&(*src)->NeedsUpdate, AL_FALSE) || UpdateSources) ALsource_Update(*src, Context); src++; } slot = Context->ActiveEffectSlots; slot_end = slot + Context->ActiveEffectSlotCount; while(slot != slot_end) { if(ExchangeInt(&(*slot)->NeedsUpdate, AL_FALSE)) ALeffectState_Update((*slot)->EffectState, Context->Device, *slot); slot++; } UnlockContext(Context); RestoreFPUMode(&oldMode); } ALCcontext_DecRef(Context); }
ALenum InitializeEffect(ALCdevice *Device, ALeffectslot *EffectSlot, ALeffect *effect) { ALenum newtype = (effect ? effect->type : AL_EFFECT_NULL); ALeffectState *State = NULL; ALenum err = AL_NO_ERROR; LockDevice(Device); if(newtype == AL_EFFECT_NULL && EffectSlot->effect.type != AL_EFFECT_NULL) { State = NoneCreate(); if(!State) err = AL_OUT_OF_MEMORY; } else if(newtype == AL_EFFECT_EAXREVERB || newtype == AL_EFFECT_REVERB) { if(EffectSlot->effect.type != AL_EFFECT_EAXREVERB && EffectSlot->effect.type != AL_EFFECT_REVERB) { State = ReverbCreate(); if(!State) err = AL_OUT_OF_MEMORY; } } else if(newtype == AL_EFFECT_ECHO && EffectSlot->effect.type != AL_EFFECT_ECHO) { State = EchoCreate(); if(!State) err = AL_OUT_OF_MEMORY; } else if(newtype == AL_EFFECT_RING_MODULATOR && EffectSlot->effect.type != AL_EFFECT_RING_MODULATOR) { State = ModulatorCreate(); if(!State) err = AL_OUT_OF_MEMORY; } else if(newtype == AL_EFFECT_DEDICATED_DIALOGUE || newtype == AL_EFFECT_DEDICATED_LOW_FREQUENCY_EFFECT) { if(EffectSlot->effect.type != AL_EFFECT_DEDICATED_DIALOGUE && EffectSlot->effect.type != AL_EFFECT_DEDICATED_LOW_FREQUENCY_EFFECT) { State = DedicatedCreate(); if(!State) err = AL_OUT_OF_MEMORY; } } if(err != AL_NO_ERROR) { UnlockDevice(Device); return err; } if(State) { int oldMode; oldMode = SetMixerFPUMode(); if(ALeffectState_DeviceUpdate(State, Device) == AL_FALSE) { RestoreFPUMode(oldMode); UnlockDevice(Device); ALeffectState_Destroy(State); return AL_OUT_OF_MEMORY; } State = ExchangePtr((XchgPtr*)&EffectSlot->EffectState, State); if(!effect) memset(&EffectSlot->effect, 0, sizeof(EffectSlot->effect)); else memcpy(&EffectSlot->effect, effect, sizeof(*effect)); /* FIXME: This should be done asynchronously, but since the EffectState * object was changed, it needs an update before its Process method can * be called. */ EffectSlot->NeedsUpdate = AL_FALSE; ALeffectState_Update(EffectSlot->EffectState, Device, EffectSlot); UnlockDevice(Device); RestoreFPUMode(oldMode); ALeffectState_Destroy(State); State = NULL; } else { if(!effect) memset(&EffectSlot->effect, 0, sizeof(EffectSlot->effect)); else memcpy(&EffectSlot->effect, effect, sizeof(*effect)); UnlockDevice(Device); EffectSlot->NeedsUpdate = AL_TRUE; } return AL_NO_ERROR; }