7 #include "mixer_defs.h"
12 static inline void ApplyCoeffsStep(ALuint Offset
, ALfloat (*restrict Values
)[2],
14 ALfloat (*restrict Coeffs
)[2],
15 const ALfloat (*restrict CoeffStep
)[2],
16 ALfloat left
, ALfloat right
);
17 static inline void ApplyCoeffs(ALuint Offset
, ALfloat (*restrict Values
)[2],
19 ALfloat (*restrict Coeffs
)[2],
20 ALfloat left
, ALfloat right
);
23 void MixHrtf(ALfloat (*restrict OutBuffer
)[BUFFERSIZE
], const ALfloat
*data
,
24 ALuint Counter
, ALuint Offset
, ALuint OutPos
, const ALuint IrSize
,
25 const MixHrtfParams
*hrtfparams
, HrtfState
*hrtfstate
, ALuint BufferSize
)
27 ALfloat (*Coeffs
)[2] = hrtfparams
->Current
->Coeffs
;
28 ALuint Delay
[2] = { hrtfparams
->Current
->Delay
[0], hrtfparams
->Current
->Delay
[1] };
35 for(;pos
< BufferSize
&& pos
< Counter
;pos
++)
37 hrtfstate
->History
[Offset
&HRTF_HISTORY_MASK
] = data
[pos
];
38 left
= lerp(hrtfstate
->History
[(Offset
-(Delay
[0]>>HRTFDELAY_BITS
))&HRTF_HISTORY_MASK
],
39 hrtfstate
->History
[(Offset
-(Delay
[0]>>HRTFDELAY_BITS
)-1)&HRTF_HISTORY_MASK
],
40 (Delay
[0]&HRTFDELAY_MASK
)*(1.0f
/HRTFDELAY_FRACONE
));
41 right
= lerp(hrtfstate
->History
[(Offset
-(Delay
[1]>>HRTFDELAY_BITS
))&HRTF_HISTORY_MASK
],
42 hrtfstate
->History
[(Offset
-(Delay
[1]>>HRTFDELAY_BITS
)-1)&HRTF_HISTORY_MASK
],
43 (Delay
[1]&HRTFDELAY_MASK
)*(1.0f
/HRTFDELAY_FRACONE
));
45 Delay
[0] += hrtfparams
->Steps
.Delay
[0];
46 Delay
[1] += hrtfparams
->Steps
.Delay
[1];
48 hrtfstate
->Values
[(Offset
+IrSize
)&HRIR_MASK
][0] = 0.0f
;
49 hrtfstate
->Values
[(Offset
+IrSize
)&HRIR_MASK
][1] = 0.0f
;
52 ApplyCoeffsStep(Offset
, hrtfstate
->Values
, IrSize
, Coeffs
, hrtfparams
->Steps
.Coeffs
, left
, right
);
53 OutBuffer
[0][OutPos
] += hrtfstate
->Values
[Offset
&HRIR_MASK
][0];
54 OutBuffer
[1][OutPos
] += hrtfstate
->Values
[Offset
&HRIR_MASK
][1];
60 *hrtfparams
->Current
= *hrtfparams
->Target
;
61 Delay
[0] = hrtfparams
->Target
->Delay
[0];
62 Delay
[1] = hrtfparams
->Target
->Delay
[1];
66 Delay
[0] >>= HRTFDELAY_BITS
;
67 Delay
[1] >>= HRTFDELAY_BITS
;
68 for(;pos
< BufferSize
;pos
++)
70 hrtfstate
->History
[Offset
&HRTF_HISTORY_MASK
] = data
[pos
];
71 left
= hrtfstate
->History
[(Offset
-Delay
[0])&HRTF_HISTORY_MASK
];
72 right
= hrtfstate
->History
[(Offset
-Delay
[1])&HRTF_HISTORY_MASK
];
74 hrtfstate
->Values
[(Offset
+IrSize
)&HRIR_MASK
][0] = 0.0f
;
75 hrtfstate
->Values
[(Offset
+IrSize
)&HRIR_MASK
][1] = 0.0f
;
78 ApplyCoeffs(Offset
, hrtfstate
->Values
, IrSize
, Coeffs
, left
, right
);
79 OutBuffer
[0][OutPos
] += hrtfstate
->Values
[Offset
&HRIR_MASK
][0];
80 OutBuffer
[1][OutPos
] += hrtfstate
->Values
[Offset
&HRIR_MASK
][1];