5 #include "mixer_defs.h"
8 #define LIKELY(x) __builtin_expect(!!(x), 1)
9 #define UNLIKELY(x) __builtin_expect(!!(x), 0)
12 #define UNLIKELY(x) (x)
15 #define REAL_MERGE2(a,b) a##b
16 #define MERGE2(a,b) REAL_MERGE2(a,b)
18 #define MixDirect_Hrtf MERGE2(MixDirect_Hrtf_,SUFFIX)
21 static __inline
void ApplyCoeffsStep(ALuint Offset
, ALfloat (*RESTRICT Values
)[2],
23 ALfloat (*RESTRICT Coeffs
)[2],
24 const ALfloat (*RESTRICT CoeffStep
)[2],
25 ALfloat left
, ALfloat right
);
26 static __inline
void ApplyCoeffs(ALuint Offset
, ALfloat (*RESTRICT Values
)[2],
28 ALfloat (*RESTRICT Coeffs
)[2],
29 ALfloat left
, ALfloat right
);
32 void MixDirect_Hrtf(const DirectParams
*params
, const ALfloat
*RESTRICT data
, ALuint srcchan
,
33 ALuint OutPos
, ALuint SamplesToDo
, ALuint BufferSize
)
35 ALfloat (*RESTRICT DryBuffer
)[BUFFERSIZE
] = params
->OutBuffer
;
36 ALfloat
*RESTRICT ClickRemoval
= params
->ClickRemoval
;
37 ALfloat
*RESTRICT PendingClicks
= params
->PendingClicks
;
38 const ALuint IrSize
= params
->Hrtf
.Params
.IrSize
;
39 const ALint
*RESTRICT DelayStep
= params
->Hrtf
.Params
.DelayStep
;
40 const ALfloat (*RESTRICT CoeffStep
)[2] = params
->Hrtf
.Params
.CoeffStep
;
41 const ALfloat (*RESTRICT TargetCoeffs
)[2] = params
->Hrtf
.Params
.Coeffs
[srcchan
];
42 const ALuint
*RESTRICT TargetDelay
= params
->Hrtf
.Params
.Delay
[srcchan
];
43 ALfloat
*RESTRICT History
= params
->Hrtf
.State
->History
[srcchan
];
44 ALfloat (*RESTRICT Values
)[2] = params
->Hrtf
.State
->Values
[srcchan
];
45 ALint Counter
= maxu(params
->Hrtf
.State
->Counter
, OutPos
) - OutPos
;
46 ALuint Offset
= params
->Hrtf
.State
->Offset
+ OutPos
;
47 ALIGN(16) ALfloat Coeffs
[HRIR_LENGTH
][2];
54 for(c
= 0;c
< IrSize
;c
++)
56 Coeffs
[c
][0] = TargetCoeffs
[c
][0] - (CoeffStep
[c
][0]*Counter
);
57 Coeffs
[c
][1] = TargetCoeffs
[c
][1] - (CoeffStep
[c
][1]*Counter
);
60 Delay
[0] = TargetDelay
[0] - (DelayStep
[0]*Counter
);
61 Delay
[1] = TargetDelay
[1] - (DelayStep
[1]*Counter
);
63 if(LIKELY(OutPos
== 0))
65 History
[Offset
&SRC_HISTORY_MASK
] = data
[pos
];
66 left
= lerp(History
[(Offset
-(Delay
[0]>>HRTFDELAY_BITS
))&SRC_HISTORY_MASK
],
67 History
[(Offset
-(Delay
[0]>>HRTFDELAY_BITS
)-1)&SRC_HISTORY_MASK
],
68 (Delay
[0]&HRTFDELAY_MASK
)*(1.0f
/HRTFDELAY_FRACONE
));
69 right
= lerp(History
[(Offset
-(Delay
[1]>>HRTFDELAY_BITS
))&SRC_HISTORY_MASK
],
70 History
[(Offset
-(Delay
[1]>>HRTFDELAY_BITS
)-1)&SRC_HISTORY_MASK
],
71 (Delay
[1]&HRTFDELAY_MASK
)*(1.0f
/HRTFDELAY_FRACONE
));
73 ClickRemoval
[FrontLeft
] -= Values
[(Offset
+1)&HRIR_MASK
][0] +
75 ClickRemoval
[FrontRight
] -= Values
[(Offset
+1)&HRIR_MASK
][1] +
78 for(pos
= 0;pos
< BufferSize
&& Counter
> 0;pos
++)
80 History
[Offset
&SRC_HISTORY_MASK
] = data
[pos
];
81 left
= lerp(History
[(Offset
-(Delay
[0]>>HRTFDELAY_BITS
))&SRC_HISTORY_MASK
],
82 History
[(Offset
-(Delay
[0]>>HRTFDELAY_BITS
)-1)&SRC_HISTORY_MASK
],
83 (Delay
[0]&HRTFDELAY_MASK
)*(1.0f
/HRTFDELAY_FRACONE
));
84 right
= lerp(History
[(Offset
-(Delay
[1]>>HRTFDELAY_BITS
))&SRC_HISTORY_MASK
],
85 History
[(Offset
-(Delay
[1]>>HRTFDELAY_BITS
)-1)&SRC_HISTORY_MASK
],
86 (Delay
[1]&HRTFDELAY_MASK
)*(1.0f
/HRTFDELAY_FRACONE
));
88 Delay
[0] += DelayStep
[0];
89 Delay
[1] += DelayStep
[1];
91 Values
[(Offset
+IrSize
)&HRIR_MASK
][0] = 0.0f
;
92 Values
[(Offset
+IrSize
)&HRIR_MASK
][1] = 0.0f
;
95 ApplyCoeffsStep(Offset
, Values
, IrSize
, Coeffs
, CoeffStep
, left
, right
);
96 DryBuffer
[FrontLeft
][OutPos
] += Values
[Offset
&HRIR_MASK
][0];
97 DryBuffer
[FrontRight
][OutPos
] += Values
[Offset
&HRIR_MASK
][1];
103 Delay
[0] >>= HRTFDELAY_BITS
;
104 Delay
[1] >>= HRTFDELAY_BITS
;
105 for(;pos
< BufferSize
;pos
++)
107 History
[Offset
&SRC_HISTORY_MASK
] = data
[pos
];
108 left
= History
[(Offset
-Delay
[0])&SRC_HISTORY_MASK
];
109 right
= History
[(Offset
-Delay
[1])&SRC_HISTORY_MASK
];
111 Values
[(Offset
+IrSize
)&HRIR_MASK
][0] = 0.0f
;
112 Values
[(Offset
+IrSize
)&HRIR_MASK
][1] = 0.0f
;
115 ApplyCoeffs(Offset
, Values
, IrSize
, Coeffs
, left
, right
);
116 DryBuffer
[FrontLeft
][OutPos
] += Values
[Offset
&HRIR_MASK
][0];
117 DryBuffer
[FrontRight
][OutPos
] += Values
[Offset
&HRIR_MASK
][1];
121 if(LIKELY(OutPos
== SamplesToDo
))
123 History
[Offset
&SRC_HISTORY_MASK
] = data
[pos
];
124 left
= History
[(Offset
-Delay
[0])&SRC_HISTORY_MASK
];
125 right
= History
[(Offset
-Delay
[1])&SRC_HISTORY_MASK
];
127 PendingClicks
[FrontLeft
] += Values
[(Offset
+1)&HRIR_MASK
][0] +
129 PendingClicks
[FrontRight
] += Values
[(Offset
+1)&HRIR_MASK
][1] +
130 Coeffs
[0][1] * right
;
135 #undef MixDirect_Hrtf