Find a valid source buffer before updating the voice

This commit is contained in:
Chris Robinson 2016-05-09 14:22:26 -07:00
parent c2611f10ab
commit 182c0cb61a
4 changed files with 63 additions and 53 deletions

View File

@ -2106,11 +2106,22 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList)
{
ALvoice *voice = &context->Voices[pos];
ALsource *source = voice->Source;
ALbufferlistitem *BufferListItem;
if(source)
if(!source)
continue;
BufferListItem = ATOMIC_LOAD(&source->queue);
while(BufferListItem != NULL)
{
ATOMIC_STORE(&source->NeedsUpdate, AL_FALSE);
voice->Update(voice, source, context);
ALbuffer *buffer;
if((buffer=BufferListItem->buffer) != NULL)
{
ATOMIC_STORE(&source->NeedsUpdate, AL_FALSE);
voice->Update(voice, source, buffer, context);
break;
}
BufferListItem = BufferListItem->next;
}
}

View File

@ -306,7 +306,7 @@ static ALvoid CalcListenerParams(ALCcontext *Context)
Listener->Params.SpeedOfSound = Context->SpeedOfSound * Context->DopplerVelocity;
}
ALvoid CalcNonAttnSourceParams(ALvoice *voice, const ALsource *ALSource, const ALCcontext *ALContext)
ALvoid CalcNonAttnSourceParams(ALvoice *voice, const ALsource *ALSource, const ALbuffer *ALBuffer, const ALCcontext *ALContext)
{
static const struct ChanMap MonoMap[1] = {
{ FrontCenter, 0.0f, 0.0f }
@ -347,8 +347,6 @@ ALvoid CalcNonAttnSourceParams(ALvoice *voice, const ALsource *ALSource, const A
const ALCdevice *Device = ALContext->Device;
const ALlistener *Listener = ALContext->Listener;
ALfloat SourceVolume,ListenerGain,MinVolume,MaxVolume;
ALbufferlistitem *BufferListItem;
enum FmtChannels Channels;
ALfloat DryGain, DryGainHF, DryGainLF;
ALfloat WetGain[MAX_SENDS];
ALfloat WetGainHF[MAX_SENDS];
@ -407,25 +405,12 @@ ALvoid CalcNonAttnSourceParams(ALvoice *voice, const ALsource *ALSource, const A
}
/* Calculate the stepping value */
Channels = FmtMono;
BufferListItem = ATOMIC_LOAD(&ALSource->queue);
while(BufferListItem != NULL)
{
ALbuffer *ALBuffer;
if((ALBuffer=BufferListItem->buffer) != NULL)
{
Pitch = Pitch * ALBuffer->Frequency / Frequency;
if(Pitch > (ALfloat)MAX_PITCH)
voice->Step = MAX_PITCH<<FRACTIONBITS;
else
voice->Step = maxi(fastf2i(Pitch*FRACTIONONE + 0.5f), 1);
BsincPrepare(voice->Step, &voice->SincState);
Channels = ALBuffer->FmtChannels;
break;
}
BufferListItem = BufferListItem->next;
}
Pitch *= (ALfloat)ALBuffer->Frequency / Frequency;
if(Pitch > (ALfloat)MAX_PITCH)
voice->Step = MAX_PITCH<<FRACTIONBITS;
else
voice->Step = maxi(fastf2i(Pitch*FRACTIONONE + 0.5f), 1);
BsincPrepare(voice->Step, &voice->SincState);
/* Calculate gains */
DryGain = clampf(SourceVolume, MinVolume, MaxVolume);
@ -440,7 +425,7 @@ ALvoid CalcNonAttnSourceParams(ALvoice *voice, const ALsource *ALSource, const A
WetGainLF[i] = ALSource->Send[i].GainLF;
}
switch(Channels)
switch(ALBuffer->FmtChannels)
{
case FmtMono:
chans = MonoMap;
@ -761,7 +746,7 @@ ALvoid CalcNonAttnSourceParams(ALvoice *voice, const ALsource *ALSource, const A
}
}
ALvoid CalcSourceParams(ALvoice *voice, const ALsource *ALSource, const ALCcontext *ALContext)
ALvoid CalcSourceParams(ALvoice *voice, const ALsource *ALSource, const ALbuffer *ALBuffer, const ALCcontext *ALContext)
{
const ALCdevice *Device = ALContext->Device;
const ALlistener *Listener = ALContext->Listener;
@ -772,7 +757,6 @@ ALvoid CalcSourceParams(ALvoice *voice, const ALsource *ALSource, const ALCconte
ALfloat DopplerFactor, SpeedOfSound;
ALfloat AirAbsorptionFactor;
ALfloat RoomAirAbsorption[MAX_SENDS];
ALbufferlistitem *BufferListItem;
ALeffectslot *SendSlots[MAX_SENDS];
ALfloat Attenuation;
ALfloat RoomAttenuation[MAX_SENDS];
@ -1072,25 +1056,15 @@ ALvoid CalcSourceParams(ALvoice *voice, const ALsource *ALSource, const ALCconte
clampf(SpeedOfSound-VSS, 1.0f, SpeedOfSound*2.0f - 1.0f);
}
BufferListItem = ATOMIC_LOAD(&ALSource->queue);
while(BufferListItem != NULL)
{
ALbuffer *ALBuffer;
if((ALBuffer=BufferListItem->buffer) != NULL)
{
/* Calculate fixed-point stepping value, based on the pitch, buffer
* frequency, and output frequency. */
Pitch = Pitch * ALBuffer->Frequency / Frequency;
if(Pitch > (ALfloat)MAX_PITCH)
voice->Step = MAX_PITCH<<FRACTIONBITS;
else
voice->Step = maxi(fastf2i(Pitch*FRACTIONONE + 0.5f), 1);
BsincPrepare(voice->Step, &voice->SincState);
break;
}
BufferListItem = BufferListItem->next;
}
/* Calculate fixed-point stepping value, based on the pitch, buffer
* frequency, and output frequency.
*/
Pitch *= (ALfloat)ALBuffer->Frequency / Frequency;
if(Pitch > (ALfloat)MAX_PITCH)
voice->Step = MAX_PITCH<<FRACTIONBITS;
else
voice->Step = maxi(fastf2i(Pitch*FRACTIONONE + 0.5f), 1);
BsincPrepare(voice->Step, &voice->SincState);
if(Device->Render_Mode == HrtfRender)
{
@ -1262,8 +1236,19 @@ void UpdateContextSources(ALCcontext *ctx)
voice->Source = NULL;
else
{
ATOMIC_STORE(&source->NeedsUpdate, AL_FALSE);
voice->Update(voice, source, ctx);
ALbufferlistitem *BufferListItem;
BufferListItem = ATOMIC_LOAD(&source->queue);
while(BufferListItem != NULL)
{
ALbuffer *buffer;
if((buffer=BufferListItem->buffer) != NULL)
{
ATOMIC_STORE(&source->NeedsUpdate, AL_FALSE);
voice->Update(voice, source, buffer, ctx);
break;
}
BufferListItem = BufferListItem->next;
}
}
}
}
@ -1277,7 +1262,20 @@ void UpdateContextSources(ALCcontext *ctx)
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);
{
ALbufferlistitem *BufferListItem;
BufferListItem = ATOMIC_LOAD(&source->queue);
while(BufferListItem != NULL)
{
ALbuffer *buffer;
if((buffer=BufferListItem->buffer) != NULL)
{
voice->Update(voice, source, buffer, ctx);
break;
}
BufferListItem = BufferListItem->next;
}
}
}
}
}

View File

@ -25,7 +25,7 @@ typedef struct ALvoice {
struct ALsource *volatile Source;
/** Method to update mixing parameters. */
ALvoid (*Update)(struct ALvoice *self, const struct ALsource *source, const ALCcontext *context);
ALvoid (*Update)(struct ALvoice *self, const struct ALsource *source, const struct ALbuffer *ALBuffer, const ALCcontext *context);
/** Current target parameters used for mixing. */
ALint Step;

View File

@ -36,6 +36,7 @@ extern "C" {
struct ALsource;
struct ALvoice;
struct ALeffectslot;
struct ALbuffer;
/* The number of distinct scale and phase intervals within the filter table. */
@ -374,8 +375,8 @@ void ComputeFirstOrderGainsBF(const BFChannelConfig *chanmap, ALuint numchans, c
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);
ALvoid CalcSourceParams(struct ALvoice *voice, const struct ALsource *source, const struct ALbuffer *buffer, const ALCcontext *ALContext);
ALvoid CalcNonAttnSourceParams(struct ALvoice *voice, const struct ALsource *source, const struct ALbuffer *buffer, const ALCcontext *ALContext);
ALvoid MixSource(struct ALvoice *voice, struct ALsource *source, ALCdevice *Device, ALuint SamplesToDo);