summaryrefslogtreecommitdiffstats
path: root/Alc
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2014-08-20 21:35:18 -0700
committerChris Robinson <[email protected]>2014-08-21 00:29:42 -0700
commitb92e643e9742765acd364bcbe30ebaedbe50400f (patch)
treee65318fdffb9105d9b247f425e09b283c855552d /Alc
parent3a6baab495d92afd17fccd61b87ae526235fce88 (diff)
Use a NULL source for inactive activesources
Also only access the activesource's source field once per update.
Diffstat (limited to 'Alc')
-rw-r--r--Alc/ALc.c8
-rw-r--r--Alc/ALu.c24
-rw-r--r--Alc/mixer.c3
3 files changed, 19 insertions, 16 deletions
diff --git a/Alc/ALc.c b/Alc/ALc.c
index e03e3655..53295fa0 100644
--- a/Alc/ALc.c
+++ b/Alc/ALc.c
@@ -1927,6 +1927,7 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList)
ALactivesource *src = context->ActiveSources[pos];
ALsource *source = src->Source;
ALuint s = device->NumAuxSends;
+
while(s < MAX_SENDS)
{
src->Send[s].Moving = AL_FALSE;
@@ -1934,8 +1935,11 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList)
s++;
}
- src->Update(src, context);
- ATOMIC_STORE(&source->NeedsUpdate, AL_FALSE);
+ if(source)
+ {
+ src->Update(src, source, context);
+ ATOMIC_STORE(&source->NeedsUpdate, AL_FALSE);
+ }
}
context = context->next;
diff --git a/Alc/ALu.c b/Alc/ALu.c
index 86c21cd2..c4a03fec 100644
--- a/Alc/ALu.c
+++ b/Alc/ALu.c
@@ -166,7 +166,7 @@ static ALvoid CalcListenerParams(ALlistener *Listener)
aluMatrixVector(Listener->Params.Velocity, 0.0f, Listener->Params.Matrix);
}
-ALvoid CalcNonAttnSourceParams(ALactivesource *src, const ALCcontext *ALContext)
+ALvoid CalcNonAttnSourceParams(ALactivesource *src, const ALsource *ALSource, const ALCcontext *ALContext)
{
static const struct ChanMap MonoMap[1] = { { FrontCenter, 0.0f } };
static const struct ChanMap StereoMap[2] = {
@@ -216,7 +216,6 @@ ALvoid CalcNonAttnSourceParams(ALactivesource *src, const ALCcontext *ALContext)
};
ALCdevice *Device = ALContext->Device;
- const ALsource *ALSource = src->Source;
ALfloat SourceVolume,ListenerGain,MinVolume,MaxVolume;
ALbufferlistitem *BufferListItem;
enum FmtChannels Channels;
@@ -563,10 +562,9 @@ ALvoid CalcNonAttnSourceParams(ALactivesource *src, const ALCcontext *ALContext)
}
}
-ALvoid CalcSourceParams(ALactivesource *src, const ALCcontext *ALContext)
+ALvoid CalcSourceParams(ALactivesource *src, const ALsource *ALSource, const ALCcontext *ALContext)
{
ALCdevice *Device = ALContext->Device;
- const ALsource *ALSource = src->Source;
ALfloat Velocity[3],Direction[3],Position[3],SourceToListener[3];
ALfloat InnerAngle,OuterAngle,Angle,Distance,ClampedDist;
ALfloat MinVolume,MaxVolume,MinDist,MaxDist,Rolloff;
@@ -1178,22 +1176,21 @@ ALvoid aluMixData(ALCdevice *device, ALvoid *buffer, ALsizei size)
while(src != src_end)
{
ALsource *source = (*src)->Source;
+ if(!source) goto next;
if(source->state != AL_PLAYING && source->state != AL_PAUSED)
{
- ALactivesource *temp = *(--src_end);
- *src_end = *src;
- *src = temp;
- --(ctx->ActiveSourceCount);
- continue;
+ (*src)->Source = NULL;
+ goto next;
}
if(!DeferUpdates && (ATOMIC_EXCHANGE(ALenum, &source->NeedsUpdate, AL_FALSE) ||
UpdateSources))
- (*src)->Update(*src, ctx);
+ (*src)->Update(*src, source, ctx);
if(source->state != AL_PAUSED)
- MixSource(*src, device, SamplesToDo);
+ MixSource(*src, source, device, SamplesToDo);
+ next:
src++;
}
@@ -1305,13 +1302,16 @@ ALvoid aluHandleDisconnect(ALCdevice *device)
while(src != src_end)
{
ALsource *source = (*src)->Source;
- if(source->state == AL_PLAYING)
+ (*src)->Source = NULL;
+
+ if(source && source->state == AL_PLAYING)
{
source->state = AL_STOPPED;
ATOMIC_STORE(&source->current_buffer, NULL);
source->position = 0;
source->position_fraction = 0;
}
+
src++;
}
Context->ActiveSourceCount = 0;
diff --git a/Alc/mixer.c b/Alc/mixer.c
index 1ca4d664..e4c7a39e 100644
--- a/Alc/mixer.c
+++ b/Alc/mixer.c
@@ -178,12 +178,11 @@ static const ALfloat *DoFilters(ALfilterState *lpfilter, ALfilterState *hpfilter
}
-ALvoid MixSource(ALactivesource *src, ALCdevice *Device, ALuint SamplesToDo)
+ALvoid MixSource(ALactivesource *src, ALsource *Source, ALCdevice *Device, ALuint SamplesToDo)
{
MixerFunc Mix;
HrtfMixerFunc HrtfMix;
ResamplerFunc Resample;
- ALsource *Source = src->Source;
ALbufferlistitem *BufferListItem;
ALuint DataPosInt, DataPosFrac;
ALboolean Looping;