7 #include "mixer_defs.h"
12 static inline void ApplyCoeffs(ALsizei Offset
, ALfloat (*restrict Values
)[2],
14 const ALfloat (*restrict Coeffs
)[2],
15 ALfloat left
, ALfloat right
);
18 void MixHrtf(ALfloat
*restrict LeftOut
, ALfloat
*restrict RightOut
,
19 const ALfloat
*data
, ALsizei Offset
, ALsizei OutPos
,
20 const ALsizei IrSize
, MixHrtfParams
*hrtfparams
, HrtfState
*hrtfstate
,
23 const ALfloat (*Coeffs
)[2] = ASSUME_ALIGNED(hrtfparams
->Coeffs
, 16);
24 const ALsizei Delay
[2] = { hrtfparams
->Delay
[0], hrtfparams
->Delay
[1] };
25 ALfloat gainstep
= hrtfparams
->GainStep
;
26 ALfloat gain
= hrtfparams
->Gain
;
32 for(i
= 0;i
< BufferSize
;i
++)
34 hrtfstate
->History
[Offset
&HRTF_HISTORY_MASK
] = *(data
++);
35 left
= hrtfstate
->History
[(Offset
-Delay
[0])&HRTF_HISTORY_MASK
]*gain
;
36 right
= hrtfstate
->History
[(Offset
-Delay
[1])&HRTF_HISTORY_MASK
]*gain
;
38 hrtfstate
->Values
[(Offset
+IrSize
-1)&HRIR_MASK
][0] = 0.0f
;
39 hrtfstate
->Values
[(Offset
+IrSize
-1)&HRIR_MASK
][1] = 0.0f
;
41 ApplyCoeffs(Offset
, hrtfstate
->Values
, IrSize
, Coeffs
, left
, right
);
42 *(LeftOut
++) += hrtfstate
->Values
[Offset
&HRIR_MASK
][0];
43 *(RightOut
++) += hrtfstate
->Values
[Offset
&HRIR_MASK
][1];
48 hrtfparams
->Gain
= gain
;
51 void MixHrtfBlend(ALfloat
*restrict LeftOut
, ALfloat
*restrict RightOut
,
52 const ALfloat
*data
, ALsizei Offset
, ALsizei OutPos
,
53 const ALsizei IrSize
, const HrtfParams
*oldparams
,
54 MixHrtfParams
*newparams
, HrtfState
*hrtfstate
,
57 const ALfloat (*OldCoeffs
)[2] = ASSUME_ALIGNED(oldparams
->Coeffs
, 16);
58 const ALsizei OldDelay
[2] = { oldparams
->Delay
[0], oldparams
->Delay
[1] };
59 ALfloat oldGain
= oldparams
->Gain
;
60 ALfloat oldGainStep
= -oldGain
/ (ALfloat
)BufferSize
;
61 const ALfloat (*NewCoeffs
)[2] = ASSUME_ALIGNED(newparams
->Coeffs
, 16);
62 const ALsizei NewDelay
[2] = { newparams
->Delay
[0], newparams
->Delay
[1] };
63 ALfloat newGain
= newparams
->Gain
;
64 ALfloat newGainStep
= newparams
->GainStep
;
70 for(i
= 0;i
< BufferSize
;i
++)
72 hrtfstate
->Values
[(Offset
+IrSize
-1)&HRIR_MASK
][0] = 0.0f
;
73 hrtfstate
->Values
[(Offset
+IrSize
-1)&HRIR_MASK
][1] = 0.0f
;
75 hrtfstate
->History
[Offset
&HRTF_HISTORY_MASK
] = *(data
++);
77 left
= hrtfstate
->History
[(Offset
-OldDelay
[0])&HRTF_HISTORY_MASK
]*oldGain
;
78 right
= hrtfstate
->History
[(Offset
-OldDelay
[1])&HRTF_HISTORY_MASK
]*oldGain
;
79 ApplyCoeffs(Offset
, hrtfstate
->Values
, IrSize
, OldCoeffs
, left
, right
);
81 left
= hrtfstate
->History
[(Offset
-NewDelay
[0])&HRTF_HISTORY_MASK
]*newGain
;
82 right
= hrtfstate
->History
[(Offset
-NewDelay
[1])&HRTF_HISTORY_MASK
]*newGain
;
83 ApplyCoeffs(Offset
, hrtfstate
->Values
, IrSize
, NewCoeffs
, left
, right
);
85 *(LeftOut
++) += hrtfstate
->Values
[Offset
&HRIR_MASK
][0];
86 *(RightOut
++) += hrtfstate
->Values
[Offset
&HRIR_MASK
][1];
88 oldGain
+= oldGainStep
;
89 newGain
+= newGainStep
;
92 newparams
->Gain
= newGain
;
95 void MixDirectHrtf(ALfloat
*restrict LeftOut
, ALfloat
*restrict RightOut
,
96 const ALfloat
*data
, ALsizei Offset
, const ALsizei IrSize
,
97 const ALfloat (*restrict Coeffs
)[2], ALfloat (*restrict Values
)[2],
103 for(i
= 0;i
< BufferSize
;i
++)
105 Values
[(Offset
+IrSize
)&HRIR_MASK
][0] = 0.0f
;
106 Values
[(Offset
+IrSize
)&HRIR_MASK
][1] = 0.0f
;
109 insample
= *(data
++);
110 ApplyCoeffs(Offset
, Values
, IrSize
, Coeffs
, insample
, insample
);
111 *(LeftOut
++) += Values
[Offset
&HRIR_MASK
][0];
112 *(RightOut
++) += Values
[Offset
&HRIR_MASK
][1];