aboutsummaryrefslogtreecommitdiffstats
path: root/Alc
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2014-06-02 19:19:22 -0700
committerChris Robinson <[email protected]>2014-06-02 19:19:22 -0700
commit3b2fcb3ef6f00d026f06ca154060b29ded3eb3fc (patch)
tree11f8a60f859cb32986993326b797096e8b8f3364 /Alc
parentd2c0a43498bf128462859d1a4bd5913b30179aa7 (diff)
Avoid a loop when updating the source position variables
Diffstat (limited to 'Alc')
-rw-r--r--Alc/ALu.c12
-rw-r--r--Alc/mixer.c10
2 files changed, 12 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<<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;