From 3b2fcb3ef6f00d026f06ca154060b29ded3eb3fc Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Mon, 2 Jun 2014 19:19:22 -0700 Subject: Avoid a loop when updating the source position variables --- Alc/ALu.c | 12 ++++++++---- Alc/mixer.c | 10 ++++------ OpenAL32/Include/alu.h | 2 ++ 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/Alc/ALu.c b/Alc/ALu.c index 82932cf3..e661af1d 100644 --- a/Alc/ALu.c +++ b/Alc/ALu.c @@ -34,12 +34,16 @@ #include "alu.h" #include "bs2b.h" #include "hrtf.h" +#include "static_assert.h" #include "mixer_defs.h" #include "midi/base.h" +static_assert((INT_MAX>>FRACTIONBITS)/MAX_PITCH > BUFFERSIZE, + "MAX_PITCH and/or BUFFERSIZE are too large for FRACTIONBITS!"); + struct ChanMap { enum Channel channel; ALfloat angle; @@ -330,8 +334,8 @@ ALvoid CalcNonAttnSourceParams(ALactivesource *src, const ALCcontext *ALContext) if((ALBuffer=BufferListItem->buffer) != NULL) { Pitch = Pitch * ALBuffer->Frequency / Frequency; - if(Pitch > 10.0f) - src->Step = 10< (ALfloat)MAX_PITCH) + src->Step = MAX_PITCH<Step = fastf2i(Pitch*FRACTIONONE); @@ -955,8 +959,8 @@ ALvoid CalcSourceParams(ALactivesource *src, const ALCcontext *ALContext) /* Calculate fixed-point stepping value, based on the pitch, buffer * frequency, and output frequency. */ Pitch = Pitch * ALBuffer->Frequency / Frequency; - if(Pitch > 10.0f) - src->Step = 10< (ALfloat)MAX_PITCH) + src->Step = MAX_PITCH<Step = fastf2i(Pitch*FRACTIONONE); diff --git a/Alc/mixer.c b/Alc/mixer.c index ef1517b3..8830a3fe 100644 --- a/Alc/mixer.c +++ b/Alc/mixer.c @@ -383,12 +383,10 @@ ALvoid MixSource(ALactivesource *src, ALCdevice *Device, ALuint SamplesToDo) } } /* Update positions */ - for(j = 0;j < DstBufferSize;j++) - { - DataPosFrac += increment; - DataPosInt += DataPosFrac>>FRACTIONBITS; - DataPosFrac &= FRACTIONMASK; - } + DataPosFrac += increment*DstBufferSize; + DataPosInt += DataPosFrac>>FRACTIONBITS; + DataPosFrac &= FRACTIONMASK; + OutPos += DstBufferSize; src->Offset += DstBufferSize; src->Direct.Counter = maxu(src->Direct.Counter, DstBufferSize) - DstBufferSize; diff --git a/OpenAL32/Include/alu.h b/OpenAL32/Include/alu.h index 98663c7d..c4b4d674 100644 --- a/OpenAL32/Include/alu.h +++ b/OpenAL32/Include/alu.h @@ -34,6 +34,8 @@ #define SRC_HISTORY_LENGTH (1<