diff options
author | Chris Robinson <[email protected]> | 2012-09-14 04:13:18 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2012-09-14 04:13:18 -0700 |
commit | 7635afcb520747b74b7c65bb522016c2c7c2da4d (patch) | |
tree | 85eba69b24c5c089730636c10aa46dda361cc86a | |
parent | 74aee374a646aec1b1ebe40f9efbae692e9720d6 (diff) |
Use a source param for the resampler and move them to the mixer source
-rw-r--r-- | Alc/ALu.c | 23 | ||||
-rw-r--r-- | Alc/mixer.c | 67 | ||||
-rw-r--r-- | Alc/mixer_c.c | 35 | ||||
-rw-r--r-- | Alc/mixer_defs.h | 6 | ||||
-rw-r--r-- | OpenAL32/Include/alSource.h | 1 | ||||
-rw-r--r-- | OpenAL32/Include/alu.h | 4 |
6 files changed, 72 insertions, 64 deletions
@@ -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; } diff --git a/Alc/mixer.c b/Alc/mixer.c index da3dcc20..1ae51b6f 100644 --- a/Alc/mixer.c +++ b/Alc/mixer.c @@ -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); diff --git a/Alc/mixer_c.c b/Alc/mixer_c.c index fab13c0f..f3e416a0 100644 --- a/Alc/mixer_c.c +++ b/Alc/mixer_c.c @@ -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], diff --git a/Alc/mixer_defs.h b/Alc/mixer_defs.h index 7e930a39..38cdb935 100644 --- a/Alc/mixer_defs.h +++ b/Alc/mixer_defs.h @@ -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); diff --git a/OpenAL32/Include/alSource.h b/OpenAL32/Include/alSource.h index c9832e47..005663bd 100644 --- a/OpenAL32/Include/alSource.h +++ b/OpenAL32/Include/alSource.h @@ -149,6 +149,7 @@ typedef struct ALsource /** Current target parameters used for mixing. */ struct { + ResamplerFunc Resample; DryMixerFunc DryMix; WetMixerFunc WetMix; diff --git a/OpenAL32/Include/alu.h b/OpenAL32/Include/alu.h index a4ad48c8..79ba8f7e 100644 --- a/OpenAL32/Include/alu.h +++ b/OpenAL32/Include/alu.h @@ -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, |