Avoid a loop when updating the source position variables

This commit is contained in:
Chris Robinson
2014-06-02 19:19:22 -07:00
parent d2c0a43498
commit 3b2fcb3ef6
3 changed files with 14 additions and 10 deletions
+8 -4
View File
@@ -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);
+4 -6
View File
@@ -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;
+2
View File
@@ -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" {