Skip to content

Commit

Permalink
Fix updating listener params when forcing updates
Browse files Browse the repository at this point in the history
  • Loading branch information
kcat committed Sep 18, 2015
1 parent 2f1bfb5 commit db0f29f
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 65 deletions.
40 changes: 7 additions & 33 deletions Alc/ALc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1620,42 +1620,16 @@ void ALCcontext_DeferUpdates(ALCcontext *context)
V0(device->Backend,lock)();
if(!context->DeferUpdates)
{
ALboolean UpdateSources;
ALvoice *voice, *voice_end;
ALeffectslot **slot, **slot_end;

context->DeferUpdates = AL_TRUE;

/* Make sure all pending updates are performed */
UpdateSources = ATOMIC_EXCHANGE(ALenum, &context->UpdateSources, AL_FALSE);

voice = context->Voices;
voice_end = voice + context->VoiceCount;
while(voice != voice_end)
{
ALsource *source = voice->Source;
if(!source) goto next;

if(source->state != AL_PLAYING && source->state != AL_PAUSED)
{
voice->Source = NULL;
goto next;
}

if(ATOMIC_EXCHANGE(ALenum, &source->NeedsUpdate, AL_FALSE) || UpdateSources)
voice->Update(voice, source, context);
next:
voice++;
}

slot = VECTOR_ITER_BEGIN(context->ActiveAuxSlots);
slot_end = VECTOR_ITER_END(context->ActiveAuxSlots);
while(slot != slot_end)
{
if(ATOMIC_EXCHANGE(ALenum, &(*slot)->NeedsUpdate, AL_FALSE))
V((*slot)->EffectState,update)(context->Device, *slot);
slot++;
}
UpdateContextSources(context);
#define UPDATE_SLOT(iter) do { \
if(ATOMIC_EXCHANGE(ALenum, &(*iter)->NeedsUpdate, AL_FALSE)) \
V((*iter)->EffectState,update)(device, *iter); \
} while(0)
VECTOR_FOR_EACH(ALeffectslot*, context->ActiveAuxSlots, UPDATE_SLOT);
#undef UPDATE_SLOT
}
V0(device->Backend,unlock)();

Expand Down
72 changes: 40 additions & 32 deletions Alc/ALu.c
Original file line number Diff line number Diff line change
Expand Up @@ -1153,6 +1153,45 @@ ALvoid CalcSourceParams(ALvoice *voice, const ALsource *ALSource, const ALCconte
}


void UpdateContextSources(ALCcontext *ctx)
{
ALvoice *voice, *voice_end;
ALsource *source;

if(ATOMIC_EXCHANGE(ALenum, &ctx->UpdateSources, AL_FALSE))
{
CalcListenerParams(ctx->Listener);

voice = ctx->Voices;
voice_end = voice + ctx->VoiceCount;
for(;voice != voice_end;++voice)
{
if(!(source=voice->Source)) continue;
if(source->state != AL_PLAYING && source->state != AL_PAUSED)
voice->Source = NULL;
else
{
ATOMIC_STORE(&source->NeedsUpdate, AL_FALSE);
voice->Update(voice, source, ctx);
}
}
}
else
{
voice = ctx->Voices;
voice_end = voice + ctx->VoiceCount;
for(;voice != voice_end;++voice)
{
if(!(source=voice->Source)) continue;
if(source->state != AL_PLAYING && source->state != AL_PAUSED)
voice->Source = NULL;
else if(ATOMIC_EXCHANGE(ALenum, &source->NeedsUpdate, AL_FALSE))
voice->Update(voice, source, ctx);
}
}
}


/* Specialized function to clamp to [-1, +1] with only one branch. This also
* converts NaN to 0. */
static inline ALfloat aluClampf(ALfloat val)
Expand Down Expand Up @@ -1258,38 +1297,7 @@ ALvoid aluMixData(ALCdevice *device, ALvoid *buffer, ALsizei size)
{
if(!ctx->DeferUpdates)
{
if(ATOMIC_EXCHANGE(ALenum, &ctx->UpdateSources, AL_FALSE))
{
CalcListenerParams(ctx->Listener);

voice = ctx->Voices;
voice_end = voice + ctx->VoiceCount;
for(;voice != voice_end;++voice)
{
if(!(source=voice->Source)) continue;
if(source->state != AL_PLAYING && source->state != AL_PAUSED)
voice->Source = NULL;
else
{
ATOMIC_STORE(&source->NeedsUpdate, AL_FALSE);
voice->Update(voice, source, ctx);
}
}
}
else
{
voice = ctx->Voices;
voice_end = voice + ctx->VoiceCount;
for(;voice != voice_end;++voice)
{
if(!(source=voice->Source)) continue;
if(source->state != AL_PLAYING && source->state != AL_PAUSED)
voice->Source = NULL;
else if(ATOMIC_EXCHANGE(ALenum, &source->NeedsUpdate, AL_FALSE))
voice->Update(voice, source, ctx);
}
}

UpdateContextSources(ctx);
#define UPDATE_SLOT(iter) do { \
if(ATOMIC_EXCHANGE(ALenum, &(*iter)->NeedsUpdate, AL_FALSE)) \
V((*iter)->EffectState,update)(device, *iter); \
Expand Down
2 changes: 2 additions & 0 deletions OpenAL32/Include/alu.h
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,8 @@ void ComputeAmbientGains(const ALCdevice *device, ALfloat ingain, ALfloat gains[
void ComputeBFormatGains(const ALCdevice *device, const ALfloat mtx[4], ALfloat ingain, ALfloat gains[MAX_OUTPUT_CHANNELS]);


ALvoid UpdateContextSources(ALCcontext *context);

ALvoid CalcSourceParams(struct ALvoice *voice, const struct ALsource *source, const ALCcontext *ALContext);
ALvoid CalcNonAttnSourceParams(struct ALvoice *voice, const struct ALsource *source, const ALCcontext *ALContext);

Expand Down

0 comments on commit db0f29f

Please sign in to comment.