Combine the direct and send mixers
[openal-soft.git] / Alc / mixer_inc.c
blobab6f32c51642632d4dc3aee2d3e8ea1936065a1b
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 ApplyCoeffsStep(ALuint Offset, ALfloat (*restrict Values)[2],
18 const ALuint irSize,
19 ALfloat (*restrict Coeffs)[2],
20 const ALfloat (*restrict CoeffStep)[2],
21 ALfloat left, ALfloat right);
22 static inline void ApplyCoeffs(ALuint Offset, ALfloat (*restrict Values)[2],
23 const ALuint irSize,
24 ALfloat (*restrict Coeffs)[2],
25 ALfloat left, ALfloat right);
28 void MixHrtf(ALfloat (*restrict OutBuffer)[BUFFERSIZE], const ALfloat *data,
29 ALuint Counter, ALuint Offset, ALuint OutPos, const ALuint IrSize,
30 const HrtfParams *hrtfparams, HrtfState *hrtfstate, ALuint BufferSize)
32 alignas(16) ALfloat Coeffs[HRIR_LENGTH][2];
33 ALuint Delay[2];
34 ALfloat left, right;
35 ALuint pos;
36 ALuint c;
38 for(c = 0;c < IrSize;c++)
40 Coeffs[c][0] = hrtfparams->Coeffs[c][0] - (hrtfparams->CoeffStep[c][0]*Counter);
41 Coeffs[c][1] = hrtfparams->Coeffs[c][1] - (hrtfparams->CoeffStep[c][1]*Counter);
43 Delay[0] = hrtfparams->Delay[0] - (hrtfparams->DelayStep[0]*Counter);
44 Delay[1] = hrtfparams->Delay[1] - (hrtfparams->DelayStep[1]*Counter);
46 for(pos = 0;pos < BufferSize && pos < Counter;pos++)
48 hrtfstate->History[Offset&SRC_HISTORY_MASK] = data[pos];
49 left = lerp(hrtfstate->History[(Offset-(Delay[0]>>HRTFDELAY_BITS))&SRC_HISTORY_MASK],
50 hrtfstate->History[(Offset-(Delay[0]>>HRTFDELAY_BITS)-1)&SRC_HISTORY_MASK],
51 (Delay[0]&HRTFDELAY_MASK)*(1.0f/HRTFDELAY_FRACONE));
52 right = lerp(hrtfstate->History[(Offset-(Delay[1]>>HRTFDELAY_BITS))&SRC_HISTORY_MASK],
53 hrtfstate->History[(Offset-(Delay[1]>>HRTFDELAY_BITS)-1)&SRC_HISTORY_MASK],
54 (Delay[1]&HRTFDELAY_MASK)*(1.0f/HRTFDELAY_FRACONE));
56 Delay[0] += hrtfparams->DelayStep[0];
57 Delay[1] += hrtfparams->DelayStep[1];
59 hrtfstate->Values[(Offset+IrSize)&HRIR_MASK][0] = 0.0f;
60 hrtfstate->Values[(Offset+IrSize)&HRIR_MASK][1] = 0.0f;
61 Offset++;
63 ApplyCoeffsStep(Offset, hrtfstate->Values, IrSize, Coeffs, hrtfparams->CoeffStep, left, right);
64 OutBuffer[FrontLeft][OutPos] += hrtfstate->Values[Offset&HRIR_MASK][0];
65 OutBuffer[FrontRight][OutPos] += hrtfstate->Values[Offset&HRIR_MASK][1];
66 OutPos++;
69 Delay[0] >>= HRTFDELAY_BITS;
70 Delay[1] >>= HRTFDELAY_BITS;
71 for(;pos < BufferSize;pos++)
73 hrtfstate->History[Offset&SRC_HISTORY_MASK] = data[pos];
74 left = hrtfstate->History[(Offset-Delay[0])&SRC_HISTORY_MASK];
75 right = hrtfstate->History[(Offset-Delay[1])&SRC_HISTORY_MASK];
77 hrtfstate->Values[(Offset+IrSize)&HRIR_MASK][0] = 0.0f;
78 hrtfstate->Values[(Offset+IrSize)&HRIR_MASK][1] = 0.0f;
79 Offset++;
81 ApplyCoeffs(Offset, hrtfstate->Values, IrSize, Coeffs, left, right);
82 OutBuffer[FrontLeft][OutPos] += hrtfstate->Values[Offset&HRIR_MASK][0];
83 OutBuffer[FrontRight][OutPos] += hrtfstate->Values[Offset&HRIR_MASK][1];
85 OutPos++;
90 #undef MixHrtf
92 #undef MERGE
93 #undef REAL_MERGE