7 #include "mixer_defs.h"
12 #define MAX_UPDATE_SAMPLES 128
15 static inline void ApplyCoeffsStep(ALuint Offset
, ALfloat (*restrict Values
)[2],
17 ALfloat (*restrict Coeffs
)[2],
18 const ALfloat (*restrict CoeffStep
)[2],
19 ALfloat left
, ALfloat right
);
20 static inline void ApplyCoeffs(ALuint Offset
, ALfloat (*restrict Values
)[2],
22 ALfloat (*restrict Coeffs
)[2],
23 ALfloat left
, ALfloat right
);
26 void MixHrtf(ALfloat (*restrict OutBuffer
)[BUFFERSIZE
], ALuint lidx
, ALuint ridx
,
27 const ALfloat
*data
, ALuint Counter
, ALuint Offset
, ALuint OutPos
,
28 const ALuint IrSize
, const MixHrtfParams
*hrtfparams
, HrtfState
*hrtfstate
,
31 ALfloat (*Coeffs
)[2] = hrtfparams
->Current
->Coeffs
;
32 ALuint Delay
[2] = { hrtfparams
->Current
->Delay
[0], hrtfparams
->Current
->Delay
[1] };
33 ALfloat out
[MAX_UPDATE_SAMPLES
][2];
42 minsize
= minu(BufferSize
, Counter
);
45 ALuint todo
= minu(minsize
-pos
, MAX_UPDATE_SAMPLES
);
47 for(i
= 0;i
< todo
;i
++)
49 hrtfstate
->History
[Offset
&HRTF_HISTORY_MASK
] = data
[pos
++];
50 left
= lerp(hrtfstate
->History
[(Offset
-(Delay
[0]>>HRTFDELAY_BITS
))&HRTF_HISTORY_MASK
],
51 hrtfstate
->History
[(Offset
-(Delay
[0]>>HRTFDELAY_BITS
)-1)&HRTF_HISTORY_MASK
],
52 (Delay
[0]&HRTFDELAY_MASK
)*(1.0f
/HRTFDELAY_FRACONE
));
53 right
= lerp(hrtfstate
->History
[(Offset
-(Delay
[1]>>HRTFDELAY_BITS
))&HRTF_HISTORY_MASK
],
54 hrtfstate
->History
[(Offset
-(Delay
[1]>>HRTFDELAY_BITS
)-1)&HRTF_HISTORY_MASK
],
55 (Delay
[1]&HRTFDELAY_MASK
)*(1.0f
/HRTFDELAY_FRACONE
));
57 Delay
[0] += hrtfparams
->Steps
.Delay
[0];
58 Delay
[1] += hrtfparams
->Steps
.Delay
[1];
60 hrtfstate
->Values
[(Offset
+IrSize
)&HRIR_MASK
][0] = 0.0f
;
61 hrtfstate
->Values
[(Offset
+IrSize
)&HRIR_MASK
][1] = 0.0f
;
64 ApplyCoeffsStep(Offset
, hrtfstate
->Values
, IrSize
, Coeffs
, hrtfparams
->Steps
.Coeffs
, left
, right
);
65 out
[i
][0] = hrtfstate
->Values
[Offset
&HRIR_MASK
][0];
66 out
[i
][1] = hrtfstate
->Values
[Offset
&HRIR_MASK
][1];
69 for(i
= 0;i
< todo
;i
++)
70 OutBuffer
[lidx
][OutPos
+i
] += out
[i
][0];
71 for(i
= 0;i
< todo
;i
++)
72 OutBuffer
[ridx
][OutPos
+i
] += out
[i
][1];
78 *hrtfparams
->Current
= *hrtfparams
->Target
;
79 Delay
[0] = hrtfparams
->Target
->Delay
[0];
80 Delay
[1] = hrtfparams
->Target
->Delay
[1];
84 hrtfparams
->Current
->Delay
[0] = Delay
[0];
85 hrtfparams
->Current
->Delay
[1] = Delay
[1];
89 Delay
[0] >>= HRTFDELAY_BITS
;
90 Delay
[1] >>= HRTFDELAY_BITS
;
91 while(pos
< BufferSize
)
93 ALuint todo
= minu(BufferSize
-pos
, MAX_UPDATE_SAMPLES
);
95 for(i
= 0;i
< todo
;i
++)
97 hrtfstate
->History
[Offset
&HRTF_HISTORY_MASK
] = data
[pos
++];
98 left
= hrtfstate
->History
[(Offset
-Delay
[0])&HRTF_HISTORY_MASK
];
99 right
= hrtfstate
->History
[(Offset
-Delay
[1])&HRTF_HISTORY_MASK
];
101 hrtfstate
->Values
[(Offset
+IrSize
)&HRIR_MASK
][0] = 0.0f
;
102 hrtfstate
->Values
[(Offset
+IrSize
)&HRIR_MASK
][1] = 0.0f
;
105 ApplyCoeffs(Offset
, hrtfstate
->Values
, IrSize
, Coeffs
, left
, right
);
106 out
[i
][0] = hrtfstate
->Values
[Offset
&HRIR_MASK
][0];
107 out
[i
][1] = hrtfstate
->Values
[Offset
&HRIR_MASK
][1];
110 for(i
= 0;i
< todo
;i
++)
111 OutBuffer
[lidx
][OutPos
+i
] += out
[i
][0];
112 for(i
= 0;i
< todo
;i
++)
113 OutBuffer
[ridx
][OutPos
+i
] += out
[i
][1];