Use 2-channel UHJ for stereo output
[openal-soft.git] / Alc / mixer_inc.c
blobd69becc9c71c64564f7021743e71cbeb8ecc0683
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"
9 #include "alu.h"
12 static inline void ApplyCoeffsStep(ALuint Offset, ALfloat (*restrict Values)[2],
13 const ALuint irSize,
14 ALfloat (*restrict Coeffs)[2],
15 const ALfloat (*restrict CoeffStep)[2],
16 ALfloat left, ALfloat right);
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 Counter, ALuint Offset, ALuint OutPos, const ALuint IrSize,
25 const MixHrtfParams *hrtfparams, HrtfState *hrtfstate, ALuint BufferSize)
27 ALfloat (*Coeffs)[2] = hrtfparams->Current->Coeffs;
28 ALuint Delay[2] = { hrtfparams->Current->Delay[0], hrtfparams->Current->Delay[1] };
29 ALfloat left, right;
30 ALuint pos;
32 pos = 0;
33 if(pos < Counter)
35 for(;pos < BufferSize && pos < Counter;pos++)
37 hrtfstate->History[Offset&HRTF_HISTORY_MASK] = data[pos];
38 left = lerp(hrtfstate->History[(Offset-(Delay[0]>>HRTFDELAY_BITS))&HRTF_HISTORY_MASK],
39 hrtfstate->History[(Offset-(Delay[0]>>HRTFDELAY_BITS)-1)&HRTF_HISTORY_MASK],
40 (Delay[0]&HRTFDELAY_MASK)*(1.0f/HRTFDELAY_FRACONE));
41 right = lerp(hrtfstate->History[(Offset-(Delay[1]>>HRTFDELAY_BITS))&HRTF_HISTORY_MASK],
42 hrtfstate->History[(Offset-(Delay[1]>>HRTFDELAY_BITS)-1)&HRTF_HISTORY_MASK],
43 (Delay[1]&HRTFDELAY_MASK)*(1.0f/HRTFDELAY_FRACONE));
45 Delay[0] += hrtfparams->Steps.Delay[0];
46 Delay[1] += hrtfparams->Steps.Delay[1];
48 hrtfstate->Values[(Offset+IrSize)&HRIR_MASK][0] = 0.0f;
49 hrtfstate->Values[(Offset+IrSize)&HRIR_MASK][1] = 0.0f;
50 Offset++;
52 ApplyCoeffsStep(Offset, hrtfstate->Values, IrSize, Coeffs, hrtfparams->Steps.Coeffs, left, right);
53 OutBuffer[0][OutPos] += hrtfstate->Values[Offset&HRIR_MASK][0];
54 OutBuffer[1][OutPos] += hrtfstate->Values[Offset&HRIR_MASK][1];
55 OutPos++;
58 if(pos == Counter)
60 *hrtfparams->Current = *hrtfparams->Target;
61 Delay[0] = hrtfparams->Target->Delay[0];
62 Delay[1] = hrtfparams->Target->Delay[1];
66 Delay[0] >>= HRTFDELAY_BITS;
67 Delay[1] >>= HRTFDELAY_BITS;
68 for(;pos < BufferSize;pos++)
70 hrtfstate->History[Offset&HRTF_HISTORY_MASK] = data[pos];
71 left = hrtfstate->History[(Offset-Delay[0])&HRTF_HISTORY_MASK];
72 right = hrtfstate->History[(Offset-Delay[1])&HRTF_HISTORY_MASK];
74 hrtfstate->Values[(Offset+IrSize)&HRIR_MASK][0] = 0.0f;
75 hrtfstate->Values[(Offset+IrSize)&HRIR_MASK][1] = 0.0f;
76 Offset++;
78 ApplyCoeffs(Offset, hrtfstate->Values, IrSize, Coeffs, left, right);
79 OutBuffer[0][OutPos] += hrtfstate->Values[Offset&HRIR_MASK][0];
80 OutBuffer[1][OutPos] += hrtfstate->Values[Offset&HRIR_MASK][1];
81 OutPos++;