Make the buffer padding size dependent on the resampler

This commit is contained in:
Chris Robinson 2010-11-26 02:53:15 -08:00
parent 0692cf304d
commit 7287b5cd3c
3 changed files with 31 additions and 18 deletions

View File

@ -626,6 +626,7 @@ ALvoid MixSource(ALsource *Source, ALCdevice *Device, ALuint SamplesToDo)
ALuint BuffersPlayed; ALuint BuffersPlayed;
ALboolean Looping; ALboolean Looping;
ALuint increment; ALuint increment;
resampler_t Resampler;
ALenum State; ALenum State;
ALuint i, j; ALuint i, j;
ALint64 DataSize64; ALint64 DataSize64;
@ -637,6 +638,8 @@ ALvoid MixSource(ALsource *Source, ALCdevice *Device, ALuint SamplesToDo)
DataPosFrac = Source->position_fraction; DataPosFrac = Source->position_fraction;
Looping = Source->bLooping; Looping = Source->bLooping;
increment = Source->Params.Step; increment = Source->Params.Step;
Resampler = (increment == FRACTIONONE) ? POINT_RESAMPLER :
Source->Resampler;
/* Get buffer info */ /* Get buffer info */
FrameSize = Channels = Bytes = 0; FrameSize = Channels = Bytes = 0;
@ -661,6 +664,8 @@ ALvoid MixSource(ALsource *Source, ALCdevice *Device, ALuint SamplesToDo)
j = 0; j = 0;
do { do {
const ALuint BufferPrePadding = ResamplerPrePadding[Resampler];
const ALuint BufferPadding = ResamplerPadding[Resampler];
ALubyte StackData[STACK_DATA_SIZE]; ALubyte StackData[STACK_DATA_SIZE];
ALubyte *SrcData = StackData; ALubyte *SrcData = StackData;
ALuint SrcDataSize = 0; ALuint SrcDataSize = 0;
@ -671,7 +676,7 @@ ALvoid MixSource(ALsource *Source, ALCdevice *Device, ALuint SamplesToDo)
DataSize64 *= increment; DataSize64 *= increment;
DataSize64 += DataPosFrac+FRACTIONMASK; DataSize64 += DataPosFrac+FRACTIONMASK;
DataSize64 >>= FRACTIONBITS; DataSize64 >>= FRACTIONBITS;
DataSize64 += BUFFER_PADDING+BUFFER_PREPADDING; DataSize64 += BufferPadding+BufferPrePadding;
DataSize64 *= FrameSize; DataSize64 *= FrameSize;
BufferSize = min(DataSize64, STACK_DATA_SIZE); BufferSize = min(DataSize64, STACK_DATA_SIZE);
@ -689,11 +694,11 @@ ALvoid MixSource(ALsource *Source, ALCdevice *Device, ALuint SamplesToDo)
{ {
Looping = AL_FALSE; Looping = AL_FALSE;
if(DataPosInt >= BUFFER_PREPADDING) if(DataPosInt >= BufferPrePadding)
pos = (DataPosInt-BUFFER_PREPADDING)*FrameSize; pos = (DataPosInt-BufferPrePadding)*FrameSize;
else else
{ {
DataSize = (BUFFER_PREPADDING-DataPosInt)*FrameSize; DataSize = (BufferPrePadding-DataPosInt)*FrameSize;
DataSize = min(BufferSize, DataSize); DataSize = min(BufferSize, DataSize);
memset(&SrcData[SrcDataSize], (Bytes==1)?0x80:0, DataSize); memset(&SrcData[SrcDataSize], (Bytes==1)?0x80:0, DataSize);
@ -724,17 +729,17 @@ ALvoid MixSource(ALsource *Source, ALCdevice *Device, ALuint SamplesToDo)
if(DataPosInt >= LoopStart) if(DataPosInt >= LoopStart)
{ {
pos = DataPosInt-LoopStart; pos = DataPosInt-LoopStart;
while(pos < BUFFER_PREPADDING) while(pos < BufferPrePadding)
pos += LoopEnd-LoopStart; pos += LoopEnd-LoopStart;
pos -= BUFFER_PREPADDING; pos -= BufferPrePadding;
pos += LoopStart; pos += LoopStart;
pos *= FrameSize; pos *= FrameSize;
} }
else if(DataPosInt >= BUFFER_PREPADDING) else if(DataPosInt >= BufferPrePadding)
pos = (DataPosInt-BUFFER_PREPADDING)*FrameSize; pos = (DataPosInt-BufferPrePadding)*FrameSize;
else else
{ {
DataSize = (BUFFER_PREPADDING-DataPosInt)*FrameSize; DataSize = (BufferPrePadding-DataPosInt)*FrameSize;
DataSize = min(BufferSize, DataSize); DataSize = min(BufferSize, DataSize);
memset(&SrcData[SrcDataSize], (Bytes==1)?0x80:0, DataSize); memset(&SrcData[SrcDataSize], (Bytes==1)?0x80:0, DataSize);
@ -770,11 +775,11 @@ ALvoid MixSource(ALsource *Source, ALCdevice *Device, ALuint SamplesToDo)
ALbufferlistitem *BufferListIter = BufferListItem; ALbufferlistitem *BufferListIter = BufferListItem;
ALuint pos; ALuint pos;
if(DataPosInt >= BUFFER_PREPADDING) if(DataPosInt >= BufferPrePadding)
pos = (DataPosInt-BUFFER_PREPADDING)*FrameSize; pos = (DataPosInt-BufferPrePadding)*FrameSize;
else else
{ {
pos = (BUFFER_PREPADDING-DataPosInt)*FrameSize; pos = (BufferPrePadding-DataPosInt)*FrameSize;
while(pos > 0) while(pos > 0)
{ {
if(!BufferListIter->prev && !Looping) if(!BufferListIter->prev && !Looping)
@ -846,7 +851,7 @@ ALvoid MixSource(ALsource *Source, ALCdevice *Device, ALuint SamplesToDo)
/* Figure out how many samples we can mix. */ /* Figure out how many samples we can mix. */
DataSize64 = SrcDataSize / FrameSize; DataSize64 = SrcDataSize / FrameSize;
DataSize64 -= BUFFER_PADDING+BUFFER_PREPADDING; DataSize64 -= BufferPadding+BufferPrePadding;
DataSize64 <<= FRACTIONBITS; DataSize64 <<= FRACTIONBITS;
DataSize64 -= increment; DataSize64 -= increment;
@ -864,8 +869,8 @@ ALvoid MixSource(ALsource *Source, ALCdevice *Device, ALuint SamplesToDo)
break; break;
} }
SrcData += BUFFER_PREPADDING*FrameSize; SrcData += BufferPrePadding*FrameSize;
switch((increment != FRACTIONONE) ? Source->Resampler : POINT_RESAMPLER) switch(Resampler)
{ {
case POINT_RESAMPLER: case POINT_RESAMPLER:
if(Bytes == 4) if(Bytes == 4)

View File

@ -7,9 +7,6 @@
extern "C" { extern "C" {
#endif #endif
#define BUFFER_PADDING 2
#define BUFFER_PREPADDING 1
typedef struct ALbuffer typedef struct ALbuffer
{ {
ALvoid *data; ALvoid *data;

View File

@ -22,6 +22,17 @@ typedef enum {
} resampler_t; } resampler_t;
extern resampler_t DefaultResampler; extern resampler_t DefaultResampler;
static const ALsizei ResamplerPadding[RESAMPLER_MAX] = {
0, /* Point */
1, /* Linear */
2, /* Cubic */
};
static const ALsizei ResamplerPrePadding[RESAMPLER_MAX] = {
0, /* Point */
0, /* Linear */
1, /* Cubic */
};
typedef struct ALbufferlistitem typedef struct ALbufferlistitem
{ {
struct ALbuffer *buffer; struct ALbuffer *buffer;