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 SetupCoeffs(ALfloat (*restrict OutCoeffs
)[2],
18 const HrtfParams
*hrtfparams
,
19 ALuint IrSize
, ALuint Counter
);
20 static inline void ApplyCoeffsStep(ALuint Offset
, ALfloat (*restrict Values
)[2],
22 ALfloat (*restrict Coeffs
)[2],
23 const ALfloat (*restrict CoeffStep
)[2],
24 ALfloat left
, ALfloat right
);
25 static inline void ApplyCoeffs(ALuint Offset
, ALfloat (*restrict Values
)[2],
27 ALfloat (*restrict Coeffs
)[2],
28 ALfloat left
, ALfloat right
);
31 void MixHrtf(ALfloat (*restrict OutBuffer
)[BUFFERSIZE
], const ALfloat
*data
,
32 ALuint Counter
, ALuint Offset
, ALuint OutPos
, const ALuint IrSize
,
33 const HrtfParams
*hrtfparams
, HrtfState
*hrtfstate
, ALuint BufferSize
)
35 alignas(16) ALfloat Coeffs
[HRIR_LENGTH
][2];
40 SetupCoeffs(Coeffs
, hrtfparams
, IrSize
, Counter
);
41 Delay
[0] = hrtfparams
->Delay
[0] - (hrtfparams
->DelayStep
[0]*Counter
);
42 Delay
[1] = hrtfparams
->Delay
[1] - (hrtfparams
->DelayStep
[1]*Counter
);
45 for(;pos
< BufferSize
&& pos
< Counter
;pos
++)
47 hrtfstate
->History
[Offset
&HRTF_HISTORY_MASK
] = data
[pos
];
48 left
= lerp(hrtfstate
->History
[(Offset
-(Delay
[0]>>HRTFDELAY_BITS
))&HRTF_HISTORY_MASK
],
49 hrtfstate
->History
[(Offset
-(Delay
[0]>>HRTFDELAY_BITS
)-1)&HRTF_HISTORY_MASK
],
50 (Delay
[0]&HRTFDELAY_MASK
)*(1.0f
/HRTFDELAY_FRACONE
));
51 right
= lerp(hrtfstate
->History
[(Offset
-(Delay
[1]>>HRTFDELAY_BITS
))&HRTF_HISTORY_MASK
],
52 hrtfstate
->History
[(Offset
-(Delay
[1]>>HRTFDELAY_BITS
)-1)&HRTF_HISTORY_MASK
],
53 (Delay
[1]&HRTFDELAY_MASK
)*(1.0f
/HRTFDELAY_FRACONE
));
55 Delay
[0] += hrtfparams
->DelayStep
[0];
56 Delay
[1] += hrtfparams
->DelayStep
[1];
58 hrtfstate
->Values
[(Offset
+IrSize
)&HRIR_MASK
][0] = 0.0f
;
59 hrtfstate
->Values
[(Offset
+IrSize
)&HRIR_MASK
][1] = 0.0f
;
62 ApplyCoeffsStep(Offset
, hrtfstate
->Values
, IrSize
, Coeffs
, hrtfparams
->CoeffStep
, left
, right
);
63 OutBuffer
[0][OutPos
] += hrtfstate
->Values
[Offset
&HRIR_MASK
][0];
64 OutBuffer
[1][OutPos
] += hrtfstate
->Values
[Offset
&HRIR_MASK
][1];
68 Delay
[0] >>= HRTFDELAY_BITS
;
69 Delay
[1] >>= HRTFDELAY_BITS
;
70 for(;pos
< BufferSize
;pos
++)
72 hrtfstate
->History
[Offset
&HRTF_HISTORY_MASK
] = data
[pos
];
73 left
= hrtfstate
->History
[(Offset
-Delay
[0])&HRTF_HISTORY_MASK
];
74 right
= hrtfstate
->History
[(Offset
-Delay
[1])&HRTF_HISTORY_MASK
];
76 hrtfstate
->Values
[(Offset
+IrSize
)&HRIR_MASK
][0] = 0.0f
;
77 hrtfstate
->Values
[(Offset
+IrSize
)&HRIR_MASK
][1] = 0.0f
;
80 ApplyCoeffs(Offset
, hrtfstate
->Values
, IrSize
, Coeffs
, left
, right
);
81 OutBuffer
[0][OutPos
] += hrtfstate
->Values
[Offset
&HRIR_MASK
][0];
82 OutBuffer
[1][OutPos
] += hrtfstate
->Values
[Offset
&HRIR_MASK
][1];