Move atomic method definitions to a separate common source
[openal-soft.git] / Alc / mixer_inc.c
blobe9288b295b896b312bf9c43197cf10264e718ecf
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_MERGE2(a,b) a##b
12 #define MERGE2(a,b) REAL_MERGE2(a,b)
14 #define MixDirect_Hrtf MERGE2(MixDirect_Hrtf_,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 MixDirect_Hrtf(DirectParams *params, const ALfloat *restrict data, ALuint srcchan,
29 ALuint OutPos, ALuint BufferSize)
31 ALfloat (*restrict DryBuffer)[BUFFERSIZE] = params->OutBuffer;
32 const ALuint IrSize = params->Mix.Hrtf.IrSize;
33 const HrtfParams *hrtfparams = &params->Mix.Hrtf.Params[srcchan];
34 HrtfState *hrtfstate = &params->Mix.Hrtf.State[srcchan];
35 ALuint Counter = maxu(params->Counter, OutPos) - OutPos;
36 ALuint Offset = params->Offset + OutPos;
37 alignas(16) ALfloat Coeffs[HRIR_LENGTH][2];
38 ALuint Delay[2];
39 ALfloat left, right;
40 ALuint pos;
41 ALuint c;
43 pos = 0;
44 for(c = 0;c < IrSize;c++)
46 Coeffs[c][0] = hrtfparams->Coeffs[c][0] - (hrtfparams->CoeffStep[c][0]*Counter);
47 Coeffs[c][1] = hrtfparams->Coeffs[c][1] - (hrtfparams->CoeffStep[c][1]*Counter);
49 Delay[0] = hrtfparams->Delay[0] - (hrtfparams->DelayStep[0]*Counter);
50 Delay[1] = hrtfparams->Delay[1] - (hrtfparams->DelayStep[1]*Counter);
52 for(pos = 0;pos < BufferSize && pos < Counter;pos++)
54 hrtfstate->History[Offset&SRC_HISTORY_MASK] = data[pos];
55 left = lerp(hrtfstate->History[(Offset-(Delay[0]>>HRTFDELAY_BITS))&SRC_HISTORY_MASK],
56 hrtfstate->History[(Offset-(Delay[0]>>HRTFDELAY_BITS)-1)&SRC_HISTORY_MASK],
57 (Delay[0]&HRTFDELAY_MASK)*(1.0f/HRTFDELAY_FRACONE));
58 right = lerp(hrtfstate->History[(Offset-(Delay[1]>>HRTFDELAY_BITS))&SRC_HISTORY_MASK],
59 hrtfstate->History[(Offset-(Delay[1]>>HRTFDELAY_BITS)-1)&SRC_HISTORY_MASK],
60 (Delay[1]&HRTFDELAY_MASK)*(1.0f/HRTFDELAY_FRACONE));
62 Delay[0] += hrtfparams->DelayStep[0];
63 Delay[1] += hrtfparams->DelayStep[1];
65 hrtfstate->Values[(Offset+IrSize)&HRIR_MASK][0] = 0.0f;
66 hrtfstate->Values[(Offset+IrSize)&HRIR_MASK][1] = 0.0f;
67 Offset++;
69 ApplyCoeffsStep(Offset, hrtfstate->Values, IrSize, Coeffs, hrtfparams->CoeffStep, left, right);
70 DryBuffer[FrontLeft][OutPos] += hrtfstate->Values[Offset&HRIR_MASK][0];
71 DryBuffer[FrontRight][OutPos] += hrtfstate->Values[Offset&HRIR_MASK][1];
72 OutPos++;
75 Delay[0] >>= HRTFDELAY_BITS;
76 Delay[1] >>= HRTFDELAY_BITS;
77 for(;pos < BufferSize;pos++)
79 hrtfstate->History[Offset&SRC_HISTORY_MASK] = data[pos];
80 left = hrtfstate->History[(Offset-Delay[0])&SRC_HISTORY_MASK];
81 right = hrtfstate->History[(Offset-Delay[1])&SRC_HISTORY_MASK];
83 hrtfstate->Values[(Offset+IrSize)&HRIR_MASK][0] = 0.0f;
84 hrtfstate->Values[(Offset+IrSize)&HRIR_MASK][1] = 0.0f;
85 Offset++;
87 ApplyCoeffs(Offset, hrtfstate->Values, IrSize, Coeffs, left, right);
88 DryBuffer[FrontLeft][OutPos] += hrtfstate->Values[Offset&HRIR_MASK][0];
89 DryBuffer[FrontRight][OutPos] += hrtfstate->Values[Offset&HRIR_MASK][1];
91 OutPos++;
96 #undef MixDirect_Hrtf
98 #undef MERGE2
99 #undef REAL_MERGE2
101 #undef UNLIKELY
102 #undef LIKELY