From a606bbc7f106b9e741a2e9c2a4726431699cb4ff Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Mon, 15 Dec 2014 12:23:28 -0800 Subject: Use a lookup table to do cubic resampling --- Alc/ALc.c | 1 + Alc/ALu.c | 2 +- Alc/mixer.c | 17 +++++++++++++++++ Alc/mixer_c.c | 2 +- OpenAL32/Include/alu.h | 18 +++++++++--------- 5 files changed, 29 insertions(+), 11 deletions(-) diff --git a/Alc/ALc.c b/Alc/ALc.c index d2b98edf..4bdf4fb0 100644 --- a/Alc/ALc.c +++ b/Alc/ALc.c @@ -1006,6 +1006,7 @@ static void alc_initconfig(void) WARN("Invalid resampler: %s\n", str); } } + aluInitResamplers(); str = getenv("ALSOFT_TRAP_ERROR"); if(str && (strcasecmp(str, "true") == 0 || strtol(str, NULL, 0) == 1)) diff --git a/Alc/ALu.c b/Alc/ALu.c index d7830ae7..57a68c24 100644 --- a/Alc/ALu.c +++ b/Alc/ALu.c @@ -82,7 +82,7 @@ extern inline ALuint64 maxu64(ALuint64 a, ALuint64 b); extern inline ALuint64 clampu64(ALuint64 val, ALuint64 min, ALuint64 max); extern inline ALfloat lerp(ALfloat val1, ALfloat val2, ALfloat mu); -extern inline ALfloat cubic(ALfloat val0, ALfloat val1, ALfloat val2, ALfloat val3, ALfloat mu); +extern inline ALfloat cubic(ALfloat val0, ALfloat val1, ALfloat val2, ALfloat val3, ALuint frac); static inline HrtfMixerFunc SelectHrtfMixer(void) diff --git a/Alc/mixer.c b/Alc/mixer.c index ae049ac8..a11b44dd 100644 --- a/Alc/mixer.c +++ b/Alc/mixer.c @@ -40,6 +40,23 @@ extern inline void InitiatePositionArrays(ALuint frac, ALuint increment, ALuint *frac_arr, ALuint *pos_arr, ALuint size); +alignas(16) ALfloat CubicLUT[FRACTIONONE][4]; + + +void aluInitResamplers(void) +{ + ALuint i; + for(i = 0;i < FRACTIONONE;i++) + { + ALfloat mu = (ALfloat)i / FRACTIONONE; + ALfloat mu2 = mu*mu, mu3 = mu*mu*mu; + CubicLUT[i][0] = -0.5f*mu3 + mu2 + -0.5f*mu; + CubicLUT[i][1] = 1.5f*mu3 + -2.5f*mu2 + 1.0f; + CubicLUT[i][2] = -1.5f*mu3 + 2.0f*mu2 + 0.5f*mu; + CubicLUT[i][3] = 0.5f*mu3 + -0.5f*mu2; + } +} + static inline HrtfMixerFunc SelectHrtfMixer(void) { diff --git a/Alc/mixer_c.c b/Alc/mixer_c.c index f5898024..cd7499f0 100644 --- a/Alc/mixer_c.c +++ b/Alc/mixer_c.c @@ -13,7 +13,7 @@ static inline ALfloat point32(const ALfloat *vals, ALuint UNUSED(frac)) static inline ALfloat lerp32(const ALfloat *vals, ALuint frac) { return lerp(vals[0], vals[1], frac * (1.0f/FRACTIONONE)); } static inline ALfloat cubic32(const ALfloat *vals, ALuint frac) -{ return cubic(vals[-1], vals[0], vals[1], vals[2], frac * (1.0f/FRACTIONONE)); } +{ return cubic(vals[-1], vals[0], vals[1], vals[2], frac); } const ALfloat *Resample_copy32_C(const ALfloat *src, ALuint UNUSED(frac), ALuint increment, ALfloat *restrict dst, ALuint numsamples) diff --git a/OpenAL32/Include/alu.h b/OpenAL32/Include/alu.h index 70beebce..41182749 100644 --- a/OpenAL32/Include/alu.h +++ b/OpenAL32/Include/alu.h @@ -116,7 +116,7 @@ typedef void (*HrtfMixerFunc)(ALfloat (*restrict OutBuffer)[BUFFERSIZE], const A #define SPEEDOFSOUNDMETRESPERSEC (343.3f) #define AIRABSORBGAINHF (0.99426f) /* -0.05dB */ -#define FRACTIONBITS (14) +#define FRACTIONBITS (12) #define FRACTIONONE (1<