aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2012-07-20 15:08:11 -0700
committerChris Robinson <[email protected]>2012-07-20 15:08:11 -0700
commit1323e11701984d93c34b7049929b1f1d3bc418bc (patch)
tree3d30d3cc3e38b6c20f96ab76226291cd063ccede
parent7ac9944bb3638845a168a99f4c302822932853b6 (diff)
Interpolate between HRTF delay samples using the delay fraction
-rw-r--r--Alc/hrtf.c8
-rw-r--r--Alc/mixer.c24
-rw-r--r--OpenAL32/Include/alMain.h3
3 files changed, 23 insertions, 12 deletions
diff --git a/Alc/hrtf.c b/Alc/hrtf.c
index 735e53dc..16bc85a9 100644
--- a/Alc/hrtf.c
+++ b/Alc/hrtf.c
@@ -170,10 +170,10 @@ void GetLerpedHrtfCoeffs(const struct Hrtf *Hrtf, ALfloat elevation, ALfloat azi
// Calculate the HRIR delays using linear interpolation.
delays[0] = fastf2u(lerp(lerp(Hrtf->delays[lidx[0]], Hrtf->delays[lidx[1]], mu[0]),
lerp(Hrtf->delays[lidx[2]], Hrtf->delays[lidx[3]], mu[1]),
- mu[2]) * 65536.0f);
+ mu[2]) + 0.5f) << HRTFDELAY_BITS;
delays[1] = fastf2u(lerp(lerp(Hrtf->delays[ridx[0]], Hrtf->delays[ridx[1]], mu[0]),
lerp(Hrtf->delays[ridx[2]], Hrtf->delays[ridx[3]], mu[1]),
- mu[2]) * 65536.0f);
+ mu[2]) + 0.5f) << HRTFDELAY_BITS;
}
// Calculates the moving HRIR target coefficients, target delays, and
@@ -267,10 +267,10 @@ ALuint GetMovingHrtfCoeffs(const struct Hrtf *Hrtf, ALfloat elevation, ALfloat a
delays[0] = fastf2u(lerp(lerp(Hrtf->delays[lidx[0]], Hrtf->delays[lidx[1]], mu[0]),
lerp(Hrtf->delays[lidx[2]], Hrtf->delays[lidx[3]], mu[1]),
- mu[2]) * 65536.0f);
+ mu[2]) + 0.5f) << HRTFDELAY_BITS;
delays[1] = fastf2u(lerp(lerp(Hrtf->delays[ridx[0]], Hrtf->delays[ridx[1]], mu[0]),
lerp(Hrtf->delays[ridx[2]], Hrtf->delays[ridx[3]], mu[1]),
- mu[2]) * 65536.0f);
+ mu[2]) + 0.5f) << HRTFDELAY_BITS;
delayStep[0] = fastf2i(step * (delays[0] - left));
delayStep[1] = fastf2i(step * (delays[1] - right));
diff --git a/Alc/mixer.c b/Alc/mixer.c
index c4120908..79ee31d1 100644
--- a/Alc/mixer.c
+++ b/Alc/mixer.c
@@ -145,8 +145,8 @@ static void MixDirect_Hrtf_##sampler(ALsource *Source, ALCdevice *Device, \
Coeffs[c][1] = TargetCoeffs[c][1] - (CoeffStep[c][1]*Counter); \
} \
\
- Delay[0] = TargetDelay[0] - (DelayStep[0]*Counter) + 32768; \
- Delay[1] = TargetDelay[1] - (DelayStep[1]*Counter) + 32768; \
+ Delay[0] = TargetDelay[0] - (DelayStep[0]*Counter); \
+ Delay[1] = TargetDelay[1] - (DelayStep[1]*Counter); \
\
if(LIKELY(OutPos == 0)) \
{ \
@@ -154,8 +154,12 @@ static void MixDirect_Hrtf_##sampler(ALsource *Source, ALCdevice *Device, \
value = lpFilter2PC(DryFilter, i, value); \
\
History[Offset&SRC_HISTORY_MASK] = value; \
- left = History[(Offset-(Delay[0]>>16))&SRC_HISTORY_MASK]; \
- right = History[(Offset-(Delay[1]>>16))&SRC_HISTORY_MASK]; \
+ left = lerp(History[(Offset-(Delay[0]>>HRTFDELAY_BITS))&SRC_HISTORY_MASK], \
+ History[(Offset-(Delay[0]>>HRTFDELAY_BITS)-1)&SRC_HISTORY_MASK], \
+ (Delay[0]&HRTFDELAY_MASK)/(ALfloat)HRTFDELAY_FRACONE); \
+ right = lerp(History[(Offset-(Delay[1]>>HRTFDELAY_BITS))&SRC_HISTORY_MASK], \
+ History[(Offset-(Delay[1]>>HRTFDELAY_BITS)-1)&SRC_HISTORY_MASK], \
+ (Delay[1]&HRTFDELAY_MASK)/(ALfloat)HRTFDELAY_FRACONE); \
\
ClickRemoval[FrontLeft] -= Values[(Offset+1)&HRIR_MASK][0] + \
Coeffs[0][0] * left; \
@@ -168,8 +172,12 @@ static void MixDirect_Hrtf_##sampler(ALsource *Source, ALCdevice *Device, \
value = lpFilter2P(DryFilter, i, value); \
\
History[Offset&SRC_HISTORY_MASK] = value; \
- left = History[(Offset-(Delay[0]>>16))&SRC_HISTORY_MASK]; \
- right = History[(Offset-(Delay[1]>>16))&SRC_HISTORY_MASK]; \
+ left = lerp(History[(Offset-(Delay[0]>>HRTFDELAY_BITS))&SRC_HISTORY_MASK], \
+ History[(Offset-(Delay[0]>>HRTFDELAY_BITS)-1)&SRC_HISTORY_MASK], \
+ (Delay[0]&HRTFDELAY_MASK)/(ALfloat)HRTFDELAY_FRACONE); \
+ right = lerp(History[(Offset-(Delay[1]>>HRTFDELAY_BITS))&SRC_HISTORY_MASK], \
+ History[(Offset-(Delay[1]>>HRTFDELAY_BITS)-1)&SRC_HISTORY_MASK], \
+ (Delay[1]&HRTFDELAY_MASK)/(ALfloat)HRTFDELAY_FRACONE); \
\
Delay[0] += DelayStep[0]; \
Delay[1] += DelayStep[1]; \
@@ -197,8 +205,8 @@ static void MixDirect_Hrtf_##sampler(ALsource *Source, ALCdevice *Device, \
Counter--; \
} \
\
- Delay[0] >>= 16; \
- Delay[1] >>= 16; \
+ Delay[0] >>= HRTFDELAY_BITS; \
+ Delay[1] >>= HRTFDELAY_BITS; \
for(;BufferIdx < BufferSize;BufferIdx++) \
{ \
value = sampler(data + pos*NumChannels + i, NumChannels, frac); \
diff --git a/OpenAL32/Include/alMain.h b/OpenAL32/Include/alMain.h
index 420c187d..f5d76b10 100644
--- a/OpenAL32/Include/alMain.h
+++ b/OpenAL32/Include/alMain.h
@@ -713,6 +713,9 @@ const ALCchar *DevFmtChannelsString(enum DevFmtChannels chans);
#define HRIR_BITS (5)
#define HRIR_LENGTH (1<<HRIR_BITS)
#define HRIR_MASK (HRIR_LENGTH-1)
+#define HRTFDELAY_BITS (20)
+#define HRTFDELAY_FRACONE (1<<HRTFDELAY_BITS)
+#define HRTFDELAY_MASK (HRTFDELAY_FRACONE-1)
void InitHrtf(void);
void FreeHrtf(void);
const struct Hrtf *GetHrtf(ALCdevice *device);