Don't feed the HRTF mix to the click removal and pending click buffers
[openal-soft.git] / Alc / mixer_inc.c
blobc28c2e97bd7bfdaa9b16122bb0abc9ab8259dd7d
1 #include "config.h"
3 #include "alMain.h"
4 #include "alSource.h"
5 #include "hrtf.h"
6 #include "mixer_defs.h"
9 #define REAL_MERGE2(a,b) a##b
10 #define MERGE2(a,b) REAL_MERGE2(a,b)
12 #define MixDirect_Hrtf MERGE2(MixDirect_Hrtf_,SUFFIX)
15 static inline void ApplyCoeffsStep(ALuint Offset, ALfloat (*restrict Values)[2],
16 const ALuint irSize,
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],
21 const ALuint irSize,
22 ALfloat (*restrict Coeffs)[2],
23 ALfloat left, ALfloat right);
26 void MixDirect_Hrtf(DirectParams *params, const ALfloat *restrict data, ALuint srcchan,
27 ALuint OutPos, ALuint UNUSED(SamplesToDo), ALuint BufferSize)
29 ALfloat (*restrict DryBuffer)[BUFFERSIZE] = params->OutBuffer;
30 const ALuint IrSize = params->Mix.Hrtf.Params.IrSize;
31 const ALint *restrict DelayStep = params->Mix.Hrtf.Params.DelayStep;
32 const ALfloat (*restrict CoeffStep)[2] = params->Mix.Hrtf.Params.CoeffStep;
33 const ALfloat (*restrict TargetCoeffs)[2] = params->Mix.Hrtf.Params.Coeffs[srcchan];
34 const ALuint *restrict TargetDelay = params->Mix.Hrtf.Params.Delay[srcchan];
35 ALfloat *restrict History = params->Mix.Hrtf.State.History[srcchan];
36 ALfloat (*restrict Values)[2] = params->Mix.Hrtf.State.Values[srcchan];
37 ALuint Counter = maxu(params->Counter, OutPos) - OutPos;
38 ALuint Offset = params->Offset + OutPos;
39 ALIGN(16) ALfloat Coeffs[HRIR_LENGTH][2];
40 ALuint Delay[2];
41 ALfloat left, right;
42 ALuint pos;
43 ALuint c;
45 pos = 0;
46 for(c = 0;c < IrSize;c++)
48 Coeffs[c][0] = TargetCoeffs[c][0] - (CoeffStep[c][0]*Counter);
49 Coeffs[c][1] = TargetCoeffs[c][1] - (CoeffStep[c][1]*Counter);
52 Delay[0] = TargetDelay[0] - (DelayStep[0]*Counter);
53 Delay[1] = TargetDelay[1] - (DelayStep[1]*Counter);
55 for(pos = 0;pos < BufferSize && pos < Counter;pos++)
57 History[Offset&SRC_HISTORY_MASK] = data[pos];
58 left = lerp(History[(Offset-(Delay[0]>>HRTFDELAY_BITS))&SRC_HISTORY_MASK],
59 History[(Offset-(Delay[0]>>HRTFDELAY_BITS)-1)&SRC_HISTORY_MASK],
60 (Delay[0]&HRTFDELAY_MASK)*(1.0f/HRTFDELAY_FRACONE));
61 right = lerp(History[(Offset-(Delay[1]>>HRTFDELAY_BITS))&SRC_HISTORY_MASK],
62 History[(Offset-(Delay[1]>>HRTFDELAY_BITS)-1)&SRC_HISTORY_MASK],
63 (Delay[1]&HRTFDELAY_MASK)*(1.0f/HRTFDELAY_FRACONE));
65 Delay[0] += DelayStep[0];
66 Delay[1] += DelayStep[1];
68 Values[(Offset+IrSize)&HRIR_MASK][0] = 0.0f;
69 Values[(Offset+IrSize)&HRIR_MASK][1] = 0.0f;
70 Offset++;
72 ApplyCoeffsStep(Offset, Values, IrSize, Coeffs, CoeffStep, left, right);
73 DryBuffer[FrontLeft][OutPos] += Values[Offset&HRIR_MASK][0];
74 DryBuffer[FrontRight][OutPos] += Values[Offset&HRIR_MASK][1];
75 OutPos++;
78 Delay[0] >>= HRTFDELAY_BITS;
79 Delay[1] >>= HRTFDELAY_BITS;
80 for(;pos < BufferSize;pos++)
82 History[Offset&SRC_HISTORY_MASK] = data[pos];
83 left = History[(Offset-Delay[0])&SRC_HISTORY_MASK];
84 right = History[(Offset-Delay[1])&SRC_HISTORY_MASK];
86 Values[(Offset+IrSize)&HRIR_MASK][0] = 0.0f;
87 Values[(Offset+IrSize)&HRIR_MASK][1] = 0.0f;
88 Offset++;
90 ApplyCoeffs(Offset, Values, IrSize, Coeffs, left, right);
91 DryBuffer[FrontLeft][OutPos] += Values[Offset&HRIR_MASK][0];
92 DryBuffer[FrontRight][OutPos] += Values[Offset&HRIR_MASK][1];
94 OutPos++;
99 #undef MixDirect_Hrtf
101 #undef MERGE2
102 #undef REAL_MERGE2
104 #undef UNLIKELY
105 #undef LIKELY