Use a source param for the resampler and move them to the mixer source

This commit is contained in:
Chris Robinson
2012-09-14 04:13:18 -07:00
parent 74aee374a6
commit 7635afcb52
6 changed files with 72 additions and 64 deletions
+23
View File
@@ -51,6 +51,27 @@ ALfloat ConeScale = 1.0f;
ALfloat ZScale = 1.0f;
static ResamplerFunc SelectResampler(enum Resampler Resampler, ALuint increment)
{
if(increment == FRACTIONONE)
return Resample_point32_C;
switch(Resampler)
{
case PointResampler:
return Resample_point32_C;
case LinearResampler:
return Resample_lerp32_C;
case CubicResampler:
return Resample_cubic32_C;
case ResamplerMax:
/* Shouldn't happen */
break;
}
return NULL;
}
static DryMixerFunc SelectDirectMixer(void)
{
#ifdef HAVE_SSE
@@ -210,6 +231,7 @@ ALvoid CalcNonAttnSourceParams(ALsource *ALSource, const ALCcontext *ALContext)
if(ALSource->Params.Step == 0)
ALSource->Params.Step = 1;
}
ALSource->Params.Resample = SelectResampler(Resampler, ALSource->Params.Step);
Channels = ALBuffer->FmtChannels;
break;
@@ -703,6 +725,7 @@ ALvoid CalcSourceParams(ALsource *ALSource, const ALCcontext *ALContext)
if(ALSource->Params.Step == 0)
ALSource->Params.Step = 1;
}
ALSource->Params.Resample = SelectResampler(Resampler, ALSource->Params.Step);
break;
}
+3 -64
View File
@@ -84,68 +84,6 @@ static void SilenceStack(ALfloat *dst, ALuint samples)
}
static __inline ALfloat point32(const ALfloat *vals, ALint step, ALint frac)
{ return vals[0]; (void)step; (void)frac; }
static __inline ALfloat lerp32(const ALfloat *vals, ALint step, ALint frac)
{ return lerp(vals[0], vals[step], frac * (1.0f/FRACTIONONE)); }
static __inline ALfloat cubic32(const ALfloat *vals, ALint step, ALint frac)
{ return cubic(vals[-step], vals[0], vals[step], vals[step+step],
frac * (1.0f/FRACTIONONE)); }
#define DECL_TEMPLATE(Sampler) \
static void Resample_##Sampler(const ALfloat *data, ALuint frac, \
ALuint increment, ALuint NumChannels, ALfloat *RESTRICT OutBuffer, \
ALuint BufferSize) \
{ \
ALuint pos = 0; \
ALfloat value; \
ALuint i; \
\
for(i = 0;i < BufferSize+1;i++) \
{ \
value = Sampler(data + pos*NumChannels, NumChannels, frac); \
OutBuffer[i] = value; \
\
frac += increment; \
pos += frac>>FRACTIONBITS; \
frac &= FRACTIONMASK; \
} \
}
DECL_TEMPLATE(point32)
DECL_TEMPLATE(lerp32)
DECL_TEMPLATE(cubic32)
#undef DECL_TEMPLATE
static void Resample(enum Resampler Resampler, const ALfloat *data, ALuint frac,
ALuint increment, ALuint NumChannels,
ALfloat *RESTRICT OutBuffer, ALuint BufferSize)
{
if(increment == FRACTIONONE)
goto do_point;
switch(Resampler)
{
case PointResampler:
do_point:
Resample_point32(data, frac, increment, NumChannels,
OutBuffer, BufferSize);
break;
case LinearResampler:
Resample_lerp32(data, frac, increment, NumChannels,
OutBuffer, BufferSize);
break;
case CubicResampler:
Resample_cubic32(data, frac, increment, NumChannels,
OutBuffer, BufferSize);
break;
case ResamplerMax:
/* Shouldn't happen */
break;
}
}
static void Filter2P(FILTER *filter, ALuint chan, ALfloat *RESTRICT dst,
const ALfloat *RESTRICT src, ALuint numsamples)
{
@@ -401,11 +339,12 @@ ALvoid MixSource(ALsource *Source, ALCdevice *Device, ALuint SamplesToDo)
ALIGN(16) ALfloat FilteredData[BUFFERSIZE];
ALfloat ResampledData[BUFFERSIZE];
Resample(Resampler, SrcData+i, DataPosFrac, increment,
NumChannels, ResampledData, BufferSize);
Source->Params.Resample(SrcData+i, DataPosFrac, increment,
NumChannels, ResampledData, BufferSize);
Filter2P(&directparms->iirFilter, i, FilteredData, ResampledData,
BufferSize);
Source->Params.DryMix(Source, Device, directparms,
FilteredData, i, OutPos, SamplesToDo,
BufferSize);
+35
View File
@@ -6,6 +6,41 @@
#include "alu.h"
static __inline ALfloat point32(const ALfloat *vals, ALint step, ALint frac)
{ return vals[0]; (void)step; (void)frac; }
static __inline ALfloat lerp32(const ALfloat *vals, ALint step, ALint frac)
{ return lerp(vals[0], vals[step], frac * (1.0f/FRACTIONONE)); }
static __inline ALfloat cubic32(const ALfloat *vals, ALint step, ALint frac)
{ return cubic(vals[-step], vals[0], vals[step], vals[step+step],
frac * (1.0f/FRACTIONONE)); }
#define DECL_TEMPLATE(Sampler) \
void Resample_##Sampler##_C(const ALfloat *data, ALuint frac, \
ALuint increment, ALuint NumChannels, ALfloat *RESTRICT OutBuffer, \
ALuint BufferSize) \
{ \
ALuint pos = 0; \
ALfloat value; \
ALuint i; \
\
for(i = 0;i < BufferSize+1;i++) \
{ \
value = Sampler(data + pos*NumChannels, NumChannels, frac); \
OutBuffer[i] = value; \
\
frac += increment; \
pos += frac>>FRACTIONBITS; \
frac &= FRACTIONMASK; \
} \
}
DECL_TEMPLATE(point32)
DECL_TEMPLATE(lerp32)
DECL_TEMPLATE(cubic32)
#undef DECL_TEMPLATE
static __inline void ApplyCoeffsStep(ALuint Offset, ALfloat (*RESTRICT Values)[2],
const ALuint IrSize,
ALfloat (*RESTRICT Coeffs)[2],
+6
View File
@@ -10,6 +10,12 @@ struct ALsource;
struct DirectParams;
struct SendParams;
/* C resamplers */
void Resample_point32_C(const ALfloat *src, ALuint frac, ALuint increment, ALuint NumChannels, ALfloat *RESTRICT dst, ALuint dstlen);
void Resample_lerp32_C(const ALfloat *src, ALuint frac, ALuint increment, ALuint NumChannels, ALfloat *RESTRICT dst, ALuint dstlen);
void Resample_cubic32_C(const ALfloat *src, ALuint frac, ALuint increment, ALuint NumChannels, ALfloat *RESTRICT dst, ALuint dstlen);
/* C mixers */
void MixDirect_Hrtf_C(struct ALsource*,ALCdevice*,struct DirectParams*,const ALfloat*RESTRICT,ALuint,ALuint,ALuint,ALuint);
void MixDirect_C(struct ALsource*,ALCdevice*,struct DirectParams*,const ALfloat*RESTRICT,ALuint,ALuint,ALuint,ALuint);
+1
View File
@@ -149,6 +149,7 @@ typedef struct ALsource
/** Current target parameters used for mixing. */
struct {
ResamplerFunc Resample;
DryMixerFunc DryMix;
WetMixerFunc WetMix;
+4
View File
@@ -80,6 +80,10 @@ struct ALbuffer;
struct DirectParams;
struct SendParams;
typedef void (*ResamplerFunc)(const ALfloat *src, ALuint frac,
ALuint increment, ALuint NumChannels,
ALfloat *RESTRICT dst, ALuint dstlen);
typedef ALvoid (*DryMixerFunc)(struct ALsource *self, ALCdevice *Device,
struct DirectParams *params,
const ALfloat *RESTRICT data, ALuint srcchan,