Better organize the reverb code into separate labeled sections
[openal-soft.git] / Alc / mixer_inc.c
bloba82930cc822bf6af6af80681dd75e1e6afd8b8d5
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 static inline void SetupCoeffs(ALfloat (*restrict OutCoeffs)[2],
12 const HrtfParams *hrtfparams,
13 ALuint IrSize, ALuint Counter);
14 static inline void ApplyCoeffsStep(ALuint Offset, ALfloat (*restrict Values)[2],
15 const ALuint irSize,
16 ALfloat (*restrict Coeffs)[2],
17 const ALfloat (*restrict CoeffStep)[2],
18 ALfloat left, ALfloat right);
19 static inline void ApplyCoeffs(ALuint Offset, ALfloat (*restrict Values)[2],
20 const ALuint irSize,
21 ALfloat (*restrict Coeffs)[2],
22 ALfloat left, ALfloat right);
25 void MixHrtf(ALfloat (*restrict OutBuffer)[BUFFERSIZE], const ALfloat *data,
26 ALuint Counter, ALuint Offset, ALuint OutPos, const ALuint IrSize,
27 const HrtfParams *hrtfparams, HrtfState *hrtfstate, ALuint BufferSize)
29 alignas(16) ALfloat Coeffs[HRIR_LENGTH][2];
30 ALuint Delay[2];
31 ALfloat left, right;
32 ALuint pos;
34 SetupCoeffs(Coeffs, hrtfparams, IrSize, Counter);
35 Delay[0] = hrtfparams->Delay[0] - (hrtfparams->DelayStep[0]*Counter);
36 Delay[1] = hrtfparams->Delay[1] - (hrtfparams->DelayStep[1]*Counter);
38 pos = 0;
39 for(;pos < BufferSize && pos < Counter;pos++)
41 hrtfstate->History[Offset&HRTF_HISTORY_MASK] = data[pos];
42 left = lerp(hrtfstate->History[(Offset-(Delay[0]>>HRTFDELAY_BITS))&HRTF_HISTORY_MASK],
43 hrtfstate->History[(Offset-(Delay[0]>>HRTFDELAY_BITS)-1)&HRTF_HISTORY_MASK],
44 (Delay[0]&HRTFDELAY_MASK)*(1.0f/HRTFDELAY_FRACONE));
45 right = lerp(hrtfstate->History[(Offset-(Delay[1]>>HRTFDELAY_BITS))&HRTF_HISTORY_MASK],
46 hrtfstate->History[(Offset-(Delay[1]>>HRTFDELAY_BITS)-1)&HRTF_HISTORY_MASK],
47 (Delay[1]&HRTFDELAY_MASK)*(1.0f/HRTFDELAY_FRACONE));
49 Delay[0] += hrtfparams->DelayStep[0];
50 Delay[1] += hrtfparams->DelayStep[1];
52 hrtfstate->Values[(Offset+IrSize)&HRIR_MASK][0] = 0.0f;
53 hrtfstate->Values[(Offset+IrSize)&HRIR_MASK][1] = 0.0f;
54 Offset++;
56 ApplyCoeffsStep(Offset, hrtfstate->Values, IrSize, Coeffs, hrtfparams->CoeffStep, left, right);
57 OutBuffer[0][OutPos] += hrtfstate->Values[Offset&HRIR_MASK][0];
58 OutBuffer[1][OutPos] += hrtfstate->Values[Offset&HRIR_MASK][1];
59 OutPos++;
62 Delay[0] >>= HRTFDELAY_BITS;
63 Delay[1] >>= HRTFDELAY_BITS;
64 for(;pos < BufferSize;pos++)
66 hrtfstate->History[Offset&HRTF_HISTORY_MASK] = data[pos];
67 left = hrtfstate->History[(Offset-Delay[0])&HRTF_HISTORY_MASK];
68 right = hrtfstate->History[(Offset-Delay[1])&HRTF_HISTORY_MASK];
70 hrtfstate->Values[(Offset+IrSize)&HRIR_MASK][0] = 0.0f;
71 hrtfstate->Values[(Offset+IrSize)&HRIR_MASK][1] = 0.0f;
72 Offset++;
74 ApplyCoeffs(Offset, hrtfstate->Values, IrSize, Coeffs, left, right);
75 OutBuffer[0][OutPos] += hrtfstate->Values[Offset&HRIR_MASK][0];
76 OutBuffer[1][OutPos] += hrtfstate->Values[Offset&HRIR_MASK][1];
77 OutPos++;