diff options
-rw-r--r-- | Alc/ALc.c | 1 | ||||
-rw-r--r-- | Alc/ALu.c | 2 | ||||
-rw-r--r-- | Alc/mixer.c | 17 | ||||
-rw-r--r-- | Alc/mixer_c.c | 2 | ||||
-rw-r--r-- | OpenAL32/Include/alu.h | 18 |
5 files changed, 29 insertions, 11 deletions
@@ -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)) @@ -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<<FRACTIONBITS) #define FRACTIONMASK (FRACTIONONE-1) @@ -164,22 +164,22 @@ inline ALuint64 clampu64(ALuint64 val, ALuint64 min, ALuint64 max) { return minu64(max, maxu64(min, val)); } +extern ALfloat CubicLUT[FRACTIONONE][4]; + + inline ALfloat lerp(ALfloat val1, ALfloat val2, ALfloat mu) { return val1 + (val2-val1)*mu; } -inline ALfloat cubic(ALfloat val0, ALfloat val1, ALfloat val2, ALfloat val3, ALfloat mu) +inline ALfloat cubic(ALfloat val0, ALfloat val1, ALfloat val2, ALfloat val3, ALuint frac) { - ALfloat mu2 = mu*mu, mu3 = mu*mu*mu; - ALfloat a0 = -0.5f*mu3 + mu2 + -0.5f*mu; - ALfloat a1 = 1.5f*mu3 + -2.5f*mu2 + 1.0f; - ALfloat a2 = -1.5f*mu3 + 2.0f*mu2 + 0.5f*mu; - ALfloat a3 = 0.5f*mu3 + -0.5f*mu2; - - return a0*val0 + a1*val1 + a2*val2 + a3*val3; + const ALfloat *k = CubicLUT[frac]; + return k[0]*val0 + k[1]*val1 + k[2]*val2 + k[3]*val3; } +void aluInitResamplers(void); + ALvoid aluInitPanning(ALCdevice *Device); /** |