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
);
46 for(pos
= 0;pos
< BufferSize
&& pos
< Counter
;pos
++)
48 hrtfstate
->History
[Offset
&SRC_HISTORY_MASK
] = data
[pos
];
49 left
= lerp(hrtfstate
->History
[(Offset
-(Delay
[0]>>HRTFDELAY_BITS
))&SRC_HISTORY_MASK
],
50 hrtfstate
->History
[(Offset
-(Delay
[0]>>HRTFDELAY_BITS
)-1)&SRC_HISTORY_MASK
],
51 (Delay
[0]&HRTFDELAY_MASK
)*(1.0f
/HRTFDELAY_FRACONE
));
52 right
= lerp(hrtfstate
->History
[(Offset
-(Delay
[1]>>HRTFDELAY_BITS
))&SRC_HISTORY_MASK
],
53 hrtfstate
->History
[(Offset
-(Delay
[1]>>HRTFDELAY_BITS
)-1)&SRC_HISTORY_MASK
],
54 (Delay
[1]&HRTFDELAY_MASK
)*(1.0f
/HRTFDELAY_FRACONE
));
56 Delay
[0] += hrtfparams
->DelayStep
[0];
57 Delay
[1] += hrtfparams
->DelayStep
[1];
59 hrtfstate
->Values
[(Offset
+IrSize
)&HRIR_MASK
][0] = 0.0f
;
60 hrtfstate
->Values
[(Offset
+IrSize
)&HRIR_MASK
][1] = 0.0f
;
63 ApplyCoeffsStep(Offset
, hrtfstate
->Values
, IrSize
, Coeffs
, hrtfparams
->CoeffStep
, left
, right
);
64 OutBuffer
[FrontLeft
][OutPos
] += hrtfstate
->Values
[Offset
&HRIR_MASK
][0];
65 OutBuffer
[FrontRight
][OutPos
] += hrtfstate
->Values
[Offset
&HRIR_MASK
][1];
69 Delay
[0] >>= HRTFDELAY_BITS
;
70 Delay
[1] >>= HRTFDELAY_BITS
;
71 for(;pos
< BufferSize
;pos
++)
73 hrtfstate
->History
[Offset
&SRC_HISTORY_MASK
] = data
[pos
];
74 left
= hrtfstate
->History
[(Offset
-Delay
[0])&SRC_HISTORY_MASK
];
75 right
= hrtfstate
->History
[(Offset
-Delay
[1])&SRC_HISTORY_MASK
];
77 hrtfstate
->Values
[(Offset
+IrSize
)&HRIR_MASK
][0] = 0.0f
;
78 hrtfstate
->Values
[(Offset
+IrSize
)&HRIR_MASK
][1] = 0.0f
;
81 ApplyCoeffs(Offset
, hrtfstate
->Values
, IrSize
, Coeffs
, left
, right
);
82 OutBuffer
[FrontLeft
][OutPos
] += hrtfstate
->Values
[Offset
&HRIR_MASK
][0];
83 OutBuffer
[FrontRight
][OutPos
] += hrtfstate
->Values
[Offset
&HRIR_MASK
][1];