Rework HRTF decision logic
[openal-soft.git] / Alc / mixer_inc.c
blob46ccec7d586e07cb07afeb95bea003f5a587eb5c
1 #include "config.h"
3 #include "alMain.h"
4 #include "alSource.h"
6 #include "hrtf.h"
7 #include "mixer_defs.h"
8 #include "align.h"
11 #define REAL_MERGE(a,b) a##b
12 #define MERGE(a,b) REAL_MERGE(a,b)
14 #define MixHrtf MERGE(MixHrtf_,SUFFIX)
17 static inline void ApplyCoeffs(ALuint Offset, ALfloat (*restrict Values)[2],
18 const ALuint irSize,
19 ALfloat (*restrict Coeffs)[2],
20 ALfloat left, ALfloat right);
23 void MixHrtf(ALfloat (*restrict OutBuffer)[BUFFERSIZE], const ALfloat *data,
24 ALuint Offset, const ALuint IrSize,
25 const HrtfParams *hrtfparams, HrtfState *hrtfstate, ALuint BufferSize)
27 alignas(16) ALfloat Coeffs[HRIR_LENGTH][2];
28 ALuint Delay[2];
29 ALfloat left, right;
30 ALuint pos;
31 ALuint c;
33 for(c = 0;c < IrSize;c++)
35 Coeffs[c][0] = hrtfparams->Coeffs[c][0];
36 Coeffs[c][1] = hrtfparams->Coeffs[c][1];
38 Delay[0] = hrtfparams->Delay[0];
39 Delay[1] = hrtfparams->Delay[1];
41 for(pos = 0;pos < BufferSize;pos++)
43 hrtfstate->History[Offset&HRTF_HISTORY_MASK] = data[pos];
44 left = hrtfstate->History[(Offset-Delay[0])&HRTF_HISTORY_MASK];
45 right = hrtfstate->History[(Offset-Delay[1])&HRTF_HISTORY_MASK];
47 hrtfstate->Values[(Offset+IrSize)&HRIR_MASK][0] = 0.0f;
48 hrtfstate->Values[(Offset+IrSize)&HRIR_MASK][1] = 0.0f;
49 Offset++;
51 ApplyCoeffs(Offset, hrtfstate->Values, IrSize, Coeffs, left, right);
52 OutBuffer[0][pos] += hrtfstate->Values[Offset&HRIR_MASK][0];
53 OutBuffer[1][pos] += hrtfstate->Values[Offset&HRIR_MASK][1];
58 #undef MixHrtf
60 #undef MERGE
61 #undef REAL_MERGE