Select the mixer during a source update

This commit is contained in:
Chris Robinson 2011-06-25 00:08:05 -07:00
parent 913c70557d
commit 1fc44d5788
5 changed files with 83 additions and 50 deletions

View File

@ -147,6 +147,10 @@ ALvoid CalcNonAttnSourceParams(ALsource *ALSource, const ALCcontext *ALContext)
}
Channels = ALBuffer->FmtChannels;
ALSource->Params.DoMix = ((Device->Flags&DEVICE_USE_HRTF) ?
SelectHrtfMixer(ALBuffer, (ALSource->Params.Step==FRACTIONONE)) :
SelectMixer(ALBuffer, (ALSource->Params.Step==FRACTIONONE)));
break;
}
BufferListItem = BufferListItem->next;
@ -654,6 +658,10 @@ ALvoid CalcSourceParams(ALsource *ALSource, const ALCcontext *ALContext)
if(ALSource->Params.Step == 0)
ALSource->Params.Step = 1;
}
ALSource->Params.DoMix = ((Device->Flags&DEVICE_USE_HRTF) ?
SelectHrtfMixer(ALBuffer, (ALSource->Params.Step==FRACTIONONE)) :
SelectMixer(ALBuffer, (ALSource->Params.Step==FRACTIONONE)));
break;
}
BufferListItem = BufferListItem->next;

View File

@ -383,23 +383,18 @@ DECL_TEMPLATE(ALbyte, cubic8)
#define DECL_TEMPLATE(sampler) \
static void Select_##sampler(ALsource *Source, enum FmtType FmtType) \
static MixerFunc Select_##sampler(enum FmtType FmtType) \
{ \
switch(FmtType) \
{ \
case FmtByte: \
Source->DoMix = Mix_ALbyte_##sampler##8; \
Source->DoHrtfMix = Mix_Hrtf_ALbyte_##sampler##8; \
break; \
return Mix_ALbyte_##sampler##8; \
case FmtShort: \
Source->DoMix = Mix_ALshort_##sampler##16; \
Source->DoHrtfMix = Mix_Hrtf_ALshort_##sampler##16; \
break; \
return Mix_ALshort_##sampler##16; \
case FmtFloat: \
Source->DoMix = Mix_ALfloat_##sampler##32; \
Source->DoHrtfMix = Mix_Hrtf_ALfloat_##sampler##32; \
break; \
return Mix_ALfloat_##sampler##32; \
} \
return NULL; \
}
DECL_TEMPLATE(point)
@ -408,24 +403,59 @@ DECL_TEMPLATE(cubic)
#undef DECL_TEMPLATE
ALvoid SelectMixer(ALsource *Source, ALbuffer *Buffer)
MixerFunc SelectMixer(ALbuffer *Buffer, resampler_t Resampler)
{
switch(Source->Resampler)
switch(Resampler)
{
case POINT_RESAMPLER:
Select_point(Source, Buffer->FmtType);
break;
return Select_point(Buffer->FmtType);
case LINEAR_RESAMPLER:
Select_lerp(Source, Buffer->FmtType);
break;
return Select_lerp(Buffer->FmtType);
case CUBIC_RESAMPLER:
Select_cubic(Source, Buffer->FmtType);
break;
return Select_cubic(Buffer->FmtType);
case RESAMPLER_MIN:
case RESAMPLER_MAX:
break;
}
return NULL;
}
#define DECL_TEMPLATE(sampler) \
static MixerFunc Select_Hrtf_##sampler(enum FmtType FmtType) \
{ \
switch(FmtType) \
{ \
case FmtByte: \
return Mix_Hrtf_ALbyte_##sampler##8; \
case FmtShort: \
return Mix_Hrtf_ALshort_##sampler##16; \
case FmtFloat: \
return Mix_Hrtf_ALfloat_##sampler##32; \
} \
return NULL; \
}
DECL_TEMPLATE(point)
DECL_TEMPLATE(lerp)
DECL_TEMPLATE(cubic)
#undef DECL_TEMPLATE
MixerFunc SelectHrtfMixer(ALbuffer *Buffer, resampler_t Resampler)
{
switch(Resampler)
{
case POINT_RESAMPLER:
return Select_Hrtf_point(Buffer->FmtType);
case LINEAR_RESAMPLER:
return Select_Hrtf_lerp(Buffer->FmtType);
case CUBIC_RESAMPLER:
return Select_Hrtf_cubic(Buffer->FmtType);
case RESAMPLER_MIN:
case RESAMPLER_MAX:
break;
}
return NULL;
}
@ -656,11 +686,7 @@ ALvoid MixSource(ALsource *Source, ALCdevice *Device, ALuint SamplesToDo)
BufferSize = min(BufferSize, (SamplesToDo-OutPos));
SrcData += BufferPrePadding*FrameSize;
if((Device->Flags&DEVICE_USE_HRTF))
ALsource_DoHrtfMix(Source, Device, SrcData, &DataPosInt, &DataPosFrac,
OutPos, SamplesToDo, BufferSize);
else
ALsource_DoMix(Source, Device, SrcData, &DataPosInt, &DataPosFrac,
Source->Params.DoMix(Source, Device, SrcData, &DataPosInt, &DataPosFrac,
OutPos, SamplesToDo, BufferSize);
OutPos += BufferSize;

View File

@ -15,15 +15,6 @@ extern "C" {
#define SRC_HISTORY_LENGTH (1<<SRC_HISTORY_BITS)
#define SRC_HISTORY_MASK (SRC_HISTORY_LENGTH-1)
typedef enum {
POINT_RESAMPLER = 0,
LINEAR_RESAMPLER,
CUBIC_RESAMPLER,
RESAMPLER_MAX,
RESAMPLER_MIN = -1,
RESAMPLER_DEFAULT = LINEAR_RESAMPLER
} resampler_t;
extern resampler_t DefaultResampler;
extern const ALsizei ResamplerPadding[RESAMPLER_MAX];
@ -100,6 +91,8 @@ typedef struct ALsource
/* Current target parameters used for mixing */
struct {
MixerFunc DoMix;
ALint Step;
ALfloat HrtfCoeffs[MAXCHANNELS][HRIR_LENGTH][2];
@ -122,21 +115,11 @@ typedef struct ALsource
ALboolean NeedsUpdate;
ALvoid (*Update)(struct ALsource *self, const ALCcontext *context);
ALvoid (*DoMix)(struct ALsource *self, ALCdevice *Device,
const ALvoid *RESTRICT data,
ALuint *DataPosInt, ALuint *DataPosFrac,
ALuint OutPos, ALuint SamplesToDo, ALuint BufferSize);
ALvoid (*DoHrtfMix)(struct ALsource *self, ALCdevice *Device,
const ALvoid *RESTRICT data,
ALuint *DataPosInt, ALuint *DataPosFrac,
ALuint OutPos, ALuint SamplesToDo, ALuint BufferSize);
// Index to itself
ALuint source;
} ALsource;
#define ALsource_Update(s,a) ((s)->Update(s,a))
#define ALsource_DoMix(s,a,b,c,d,e,f,g) ((s)->DoMix(s,a,b,c,d,e,f,g))
#define ALsource_DoHrtfMix(s,a,b,c,d,e,f,g) ((s)->DoHrtfMix(s,a,b,c,d,e,f,g))
ALvoid ReleaseALSources(ALCcontext *Context);

View File

@ -61,6 +61,25 @@
extern "C" {
#endif
struct ALsource;
struct ALbuffer;
typedef ALvoid (*MixerFunc)(struct ALsource *self, ALCdevice *Device,
const ALvoid *RESTRICT data,
ALuint *DataPosInt, ALuint *DataPosFrac,
ALuint OutPos, ALuint SamplesToDo,
ALuint BufferSize);
typedef enum {
POINT_RESAMPLER = 0,
LINEAR_RESAMPLER,
CUBIC_RESAMPLER,
RESAMPLER_MAX,
RESAMPLER_MIN = -1,
RESAMPLER_DEFAULT = LINEAR_RESAMPLER
} resampler_t;
typedef enum {
FRONT_LEFT = 0,
FRONT_RIGHT,
@ -110,16 +129,15 @@ static __inline ALdouble cubic(ALdouble val0, ALdouble val1, ALdouble val2, ALdo
return a0*mu*mu2 + a1*mu2 + a2*mu + a3;
}
struct ALsource;
struct ALbuffer;
ALvoid aluInitPanning(ALCdevice *Device);
ALint aluCart2LUTpos(ALfloat re, ALfloat im);
ALvoid CalcSourceParams(struct ALsource *ALSource, const ALCcontext *ALContext);
ALvoid CalcNonAttnSourceParams(struct ALsource *ALSource, const ALCcontext *ALContext);
ALvoid SelectMixer(struct ALsource *Source, struct ALbuffer *Buffer);
MixerFunc SelectMixer(struct ALbuffer *Buffer, resampler_t Resampler);
MixerFunc SelectHrtfMixer(struct ALbuffer *Buffer, resampler_t Resampler);
ALvoid MixSource(struct ALsource *Source, ALCdevice *Device, ALuint SamplesToDo);
ALvoid aluMixData(ALCdevice *device, ALvoid *buffer, ALsizei size);

View File

@ -581,7 +581,6 @@ AL_API ALvoid AL_APIENTRY alSourcei(ALuint source,ALenum eParam,ALint lValue)
Source->Update = CalcSourceParams;
else
Source->Update = CalcNonAttnSourceParams;
SelectMixer(Source, buffer);
// Increment reference counter for buffer
buffer->refcount++;
@ -1639,7 +1638,6 @@ AL_API ALvoid AL_APIENTRY alSourceQueueBuffers(ALuint source, ALsizei n, const A
Source->Update = CalcSourceParams;
else
Source->Update = CalcNonAttnSourceParams;
SelectMixer(Source, buffer);
Source->NeedsUpdate = AL_TRUE;
}