7 #include "mixer_defs.h"
11 #define REAL_MERGE(a,b) a##b
12 #define MERGE(a,b) REAL_MERGE(a,b)
14 #define MixHrtf MERGE(MixHrtf_,SUFFIX)
17 static inline void ApplyCoeffsStep(ALuint Offset
, ALfloat (*restrict Values
)[2],
19 ALfloat (*restrict Coeffs
)[2],
20 const ALfloat (*restrict CoeffStep
)[2],
21 ALfloat left
, ALfloat right
);
22 static inline void ApplyCoeffs(ALuint Offset
, ALfloat (*restrict Values
)[2],
24 ALfloat (*restrict Coeffs
)[2],
25 ALfloat left
, ALfloat right
);
28 void MixHrtf(ALfloat (*restrict OutBuffer
)[BUFFERSIZE
], const ALfloat
*data
,
29 ALuint Counter
, ALuint Offset
, ALuint OutPos
, const ALuint IrSize
,
30 const HrtfParams
*hrtfparams
, HrtfState
*hrtfstate
, ALuint BufferSize
)
32 alignas(16) ALfloat Coeffs
[HRIR_LENGTH
][2];
38 for(c
= 0;c
< IrSize
;c
++)
40 Coeffs
[c
][0] = hrtfparams
->Coeffs
[c
][0] - (hrtfparams
->CoeffStep
[c
][0]*Counter
);
41 Coeffs
[c
][1] = hrtfparams
->Coeffs
[c
][1] - (hrtfparams
->CoeffStep
[c
][1]*Counter
);
43 Delay
[0] = hrtfparams
->Delay
[0] - (hrtfparams
->DelayStep
[0]*Counter
);
44 Delay
[1] = hrtfparams
->Delay
[1] - (hrtfparams
->DelayStep
[1]*Counter
);
47 for(;pos
< BufferSize
&& pos
< Counter
;pos
++)
49 hrtfstate
->History
[Offset
&HRTF_HISTORY_MASK
] = data
[pos
];
50 left
= lerp(hrtfstate
->History
[(Offset
-(Delay
[0]>>HRTFDELAY_BITS
))&HRTF_HISTORY_MASK
],
51 hrtfstate
->History
[(Offset
-(Delay
[0]>>HRTFDELAY_BITS
)-1)&HRTF_HISTORY_MASK
],
52 (Delay
[0]&HRTFDELAY_MASK
)*(1.0f
/HRTFDELAY_FRACONE
));
53 right
= lerp(hrtfstate
->History
[(Offset
-(Delay
[1]>>HRTFDELAY_BITS
))&HRTF_HISTORY_MASK
],
54 hrtfstate
->History
[(Offset
-(Delay
[1]>>HRTFDELAY_BITS
)-1)&HRTF_HISTORY_MASK
],
55 (Delay
[1]&HRTFDELAY_MASK
)*(1.0f
/HRTFDELAY_FRACONE
));
57 Delay
[0] += hrtfparams
->DelayStep
[0];
58 Delay
[1] += hrtfparams
->DelayStep
[1];
60 hrtfstate
->Values
[(Offset
+IrSize
)&HRIR_MASK
][0] = 0.0f
;
61 hrtfstate
->Values
[(Offset
+IrSize
)&HRIR_MASK
][1] = 0.0f
;
64 ApplyCoeffsStep(Offset
, hrtfstate
->Values
, IrSize
, Coeffs
, hrtfparams
->CoeffStep
, left
, right
);
65 OutBuffer
[0][OutPos
] += hrtfstate
->Values
[Offset
&HRIR_MASK
][0];
66 OutBuffer
[1][OutPos
] += hrtfstate
->Values
[Offset
&HRIR_MASK
][1];
70 Delay
[0] >>= HRTFDELAY_BITS
;
71 Delay
[1] >>= HRTFDELAY_BITS
;
72 for(;pos
< BufferSize
;pos
++)
74 hrtfstate
->History
[Offset
&HRTF_HISTORY_MASK
] = data
[pos
];
75 left
= hrtfstate
->History
[(Offset
-Delay
[0])&HRTF_HISTORY_MASK
];
76 right
= hrtfstate
->History
[(Offset
-Delay
[1])&HRTF_HISTORY_MASK
];
78 hrtfstate
->Values
[(Offset
+IrSize
)&HRIR_MASK
][0] = 0.0f
;
79 hrtfstate
->Values
[(Offset
+IrSize
)&HRIR_MASK
][1] = 0.0f
;
82 ApplyCoeffs(Offset
, hrtfstate
->Values
, IrSize
, Coeffs
, left
, right
);
83 OutBuffer
[0][OutPos
] += hrtfstate
->Values
[Offset
&HRIR_MASK
][0];
84 OutBuffer
[1][OutPos
] += hrtfstate
->Values
[Offset
&HRIR_MASK
][1];