diff options
author | Chris Robinson <[email protected]> | 2014-06-02 19:19:22 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2014-06-02 19:19:22 -0700 |
commit | 3b2fcb3ef6f00d026f06ca154060b29ded3eb3fc (patch) | |
tree | 11f8a60f859cb32986993326b797096e8b8f3364 | |
parent | d2c0a43498bf128462859d1a4bd5913b30179aa7 (diff) |
Avoid a loop when updating the source position variables
-rw-r--r-- | Alc/ALu.c | 12 | ||||
-rw-r--r-- | Alc/mixer.c | 10 | ||||
-rw-r--r-- | OpenAL32/Include/alu.h | 2 |
3 files changed, 14 insertions, 10 deletions
@@ -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<<FRACTIONBITS; + if(Pitch > (ALfloat)MAX_PITCH) + src->Step = MAX_PITCH<<FRACTIONBITS; else { src->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<<FRACTIONBITS; + if(Pitch > (ALfloat)MAX_PITCH) + src->Step = MAX_PITCH<<FRACTIONBITS; else { src->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<<SRC_HISTORY_BITS) #define SRC_HISTORY_MASK (SRC_HISTORY_LENGTH-1) +#define MAX_PITCH (10) + #ifdef __cplusplus extern "C" { |