Interpolate between HRTF delay samples using the delay fraction
This commit is contained in:
parent
7ac9944bb3
commit
1323e11701
@ -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));
|
||||
|
24
Alc/mixer.c
24
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); \
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user