7 #include "mixer_defs.h"
11 static inline void SetupCoeffs(ALfloat (*restrict OutCoeffs
)[2],
12 const HrtfParams
*hrtfparams
,
13 ALuint IrSize
, ALuint Counter
);
14 static inline void ApplyCoeffsStep(ALuint Offset
, ALfloat (*restrict Values
)[2],
16 ALfloat (*restrict Coeffs
)[2],
17 const ALfloat (*restrict CoeffStep
)[2],
18 ALfloat left
, ALfloat right
);
19 static inline void ApplyCoeffs(ALuint Offset
, ALfloat (*restrict Values
)[2],
21 ALfloat (*restrict Coeffs
)[2],
22 ALfloat left
, ALfloat right
);
25 void MixHrtf(ALfloat (*restrict OutBuffer
)[BUFFERSIZE
], const ALfloat
*data
,
26 ALuint Counter
, ALuint Offset
, ALuint OutPos
, const ALuint IrSize
,
27 const HrtfParams
*hrtfparams
, HrtfState
*hrtfstate
, ALuint BufferSize
)
29 alignas(16) ALfloat Coeffs
[HRIR_LENGTH
][2];
34 SetupCoeffs(Coeffs
, hrtfparams
, IrSize
, Counter
);
35 Delay
[0] = hrtfparams
->Delay
[0] - (hrtfparams
->DelayStep
[0]*Counter
);
36 Delay
[1] = hrtfparams
->Delay
[1] - (hrtfparams
->DelayStep
[1]*Counter
);
39 for(;pos
< BufferSize
&& pos
< Counter
;pos
++)
41 hrtfstate
->History
[Offset
&HRTF_HISTORY_MASK
] = data
[pos
];
42 left
= lerp(hrtfstate
->History
[(Offset
-(Delay
[0]>>HRTFDELAY_BITS
))&HRTF_HISTORY_MASK
],
43 hrtfstate
->History
[(Offset
-(Delay
[0]>>HRTFDELAY_BITS
)-1)&HRTF_HISTORY_MASK
],
44 (Delay
[0]&HRTFDELAY_MASK
)*(1.0f
/HRTFDELAY_FRACONE
));
45 right
= lerp(hrtfstate
->History
[(Offset
-(Delay
[1]>>HRTFDELAY_BITS
))&HRTF_HISTORY_MASK
],
46 hrtfstate
->History
[(Offset
-(Delay
[1]>>HRTFDELAY_BITS
)-1)&HRTF_HISTORY_MASK
],
47 (Delay
[1]&HRTFDELAY_MASK
)*(1.0f
/HRTFDELAY_FRACONE
));
49 Delay
[0] += hrtfparams
->DelayStep
[0];
50 Delay
[1] += hrtfparams
->DelayStep
[1];
52 hrtfstate
->Values
[(Offset
+IrSize
)&HRIR_MASK
][0] = 0.0f
;
53 hrtfstate
->Values
[(Offset
+IrSize
)&HRIR_MASK
][1] = 0.0f
;
56 ApplyCoeffsStep(Offset
, hrtfstate
->Values
, IrSize
, Coeffs
, hrtfparams
->CoeffStep
, left
, right
);
57 OutBuffer
[0][OutPos
] += hrtfstate
->Values
[Offset
&HRIR_MASK
][0];
58 OutBuffer
[1][OutPos
] += hrtfstate
->Values
[Offset
&HRIR_MASK
][1];
62 Delay
[0] >>= HRTFDELAY_BITS
;
63 Delay
[1] >>= HRTFDELAY_BITS
;
64 for(;pos
< BufferSize
;pos
++)
66 hrtfstate
->History
[Offset
&HRTF_HISTORY_MASK
] = data
[pos
];
67 left
= hrtfstate
->History
[(Offset
-Delay
[0])&HRTF_HISTORY_MASK
];
68 right
= hrtfstate
->History
[(Offset
-Delay
[1])&HRTF_HISTORY_MASK
];
70 hrtfstate
->Values
[(Offset
+IrSize
)&HRIR_MASK
][0] = 0.0f
;
71 hrtfstate
->Values
[(Offset
+IrSize
)&HRIR_MASK
][1] = 0.0f
;
74 ApplyCoeffs(Offset
, hrtfstate
->Values
, IrSize
, Coeffs
, left
, right
);
75 OutBuffer
[0][OutPos
] += hrtfstate
->Values
[Offset
&HRIR_MASK
][0];
76 OutBuffer
[1][OutPos
] += hrtfstate
->Values
[Offset
&HRIR_MASK
][1];