diff --git a/Alc/ALu.c b/Alc/ALu.c index ae09cca..602bd48 100644 --- a/Alc/ALu.c +++ b/Alc/ALu.c @@ -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; diff --git a/Alc/mixer.c b/Alc/mixer.c index 86337a2..77c0d73 100644 --- a/Alc/mixer.c +++ b/Alc/mixer.c @@ -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,12 +686,8 @@ 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, - OutPos, SamplesToDo, BufferSize); + Source->Params.DoMix(Source, Device, SrcData, &DataPosInt, &DataPosFrac, + OutPos, SamplesToDo, BufferSize); OutPos += BufferSize; /* Handle looping sources */ diff --git a/OpenAL32/Include/alSource.h b/OpenAL32/Include/alSource.h index e9c50f1..9cbd7f5 100644 --- a/OpenAL32/Include/alSource.h +++ b/OpenAL32/Include/alSource.h @@ -15,15 +15,6 @@ extern "C" { #define SRC_HISTORY_LENGTH (1<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); diff --git a/OpenAL32/Include/alu.h b/OpenAL32/Include/alu.h index 41ad5f6..4e794f2 100644 --- a/OpenAL32/Include/alu.h +++ b/OpenAL32/Include/alu.h @@ -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); diff --git a/OpenAL32/alSource.c b/OpenAL32/alSource.c index ec73004..e91206e 100644 --- a/OpenAL32/alSource.c +++ b/OpenAL32/alSource.c @@ -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; }