aboutsummaryrefslogtreecommitdiffstats
path: root/Alc/mixer_inc.c
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2016-02-14 03:23:06 -0800
committerChris Robinson <[email protected]>2016-02-14 03:23:06 -0800
commitecdc93f3ca3b12ab0b226864cf8cd579140f1484 (patch)
tree9c5d34a6f9caaf163512908af0eb5da11dd90c60 /Alc/mixer_inc.c
parent25732d0895cc4d320472fc50cd74302d91b24a0c (diff)
Calculate HRTF stepping params right before mixing
This means we track the current params and the target params, rather than the target params and the stepping. This closer matches the non-HRTF mixers.
Diffstat (limited to 'Alc/mixer_inc.c')
-rw-r--r--Alc/mixer_inc.c58
1 files changed, 31 insertions, 27 deletions
diff --git a/Alc/mixer_inc.c b/Alc/mixer_inc.c
index a82930cc..d69becc9 100644
--- a/Alc/mixer_inc.c
+++ b/Alc/mixer_inc.c
@@ -6,11 +6,9 @@
#include "hrtf.h"
#include "mixer_defs.h"
#include "align.h"
+#include "alu.h"
-static inline void SetupCoeffs(ALfloat (*restrict OutCoeffs)[2],
- const HrtfParams *hrtfparams,
- ALuint IrSize, ALuint Counter);
static inline void ApplyCoeffsStep(ALuint Offset, ALfloat (*restrict Values)[2],
const ALuint irSize,
ALfloat (*restrict Coeffs)[2],
@@ -24,39 +22,45 @@ static inline void ApplyCoeffs(ALuint Offset, ALfloat (*restrict Values)[2],
void MixHrtf(ALfloat (*restrict OutBuffer)[BUFFERSIZE], const ALfloat *data,
ALuint Counter, ALuint Offset, ALuint OutPos, const ALuint IrSize,
- const HrtfParams *hrtfparams, HrtfState *hrtfstate, ALuint BufferSize)
+ const MixHrtfParams *hrtfparams, HrtfState *hrtfstate, ALuint BufferSize)
{
- alignas(16) ALfloat Coeffs[HRIR_LENGTH][2];
- ALuint Delay[2];
+ ALfloat (*Coeffs)[2] = hrtfparams->Current->Coeffs;
+ ALuint Delay[2] = { hrtfparams->Current->Delay[0], hrtfparams->Current->Delay[1] };
ALfloat left, right;
ALuint pos;
- SetupCoeffs(Coeffs, hrtfparams, IrSize, Counter);
- Delay[0] = hrtfparams->Delay[0] - (hrtfparams->DelayStep[0]*Counter);
- Delay[1] = hrtfparams->Delay[1] - (hrtfparams->DelayStep[1]*Counter);
-
pos = 0;
- for(;pos < BufferSize && pos < Counter;pos++)
+ if(pos < Counter)
{
- hrtfstate->History[Offset&HRTF_HISTORY_MASK] = data[pos];
- left = lerp(hrtfstate->History[(Offset-(Delay[0]>>HRTFDELAY_BITS))&HRTF_HISTORY_MASK],
- hrtfstate->History[(Offset-(Delay[0]>>HRTFDELAY_BITS)-1)&HRTF_HISTORY_MASK],
- (Delay[0]&HRTFDELAY_MASK)*(1.0f/HRTFDELAY_FRACONE));
- right = lerp(hrtfstate->History[(Offset-(Delay[1]>>HRTFDELAY_BITS))&HRTF_HISTORY_MASK],
- hrtfstate->History[(Offset-(Delay[1]>>HRTFDELAY_BITS)-1)&HRTF_HISTORY_MASK],
- (Delay[1]&HRTFDELAY_MASK)*(1.0f/HRTFDELAY_FRACONE));
+ for(;pos < BufferSize && pos < Counter;pos++)
+ {
+ hrtfstate->History[Offset&HRTF_HISTORY_MASK] = data[pos];
+ left = lerp(hrtfstate->History[(Offset-(Delay[0]>>HRTFDELAY_BITS))&HRTF_HISTORY_MASK],
+ hrtfstate->History[(Offset-(Delay[0]>>HRTFDELAY_BITS)-1)&HRTF_HISTORY_MASK],
+ (Delay[0]&HRTFDELAY_MASK)*(1.0f/HRTFDELAY_FRACONE));
+ right = lerp(hrtfstate->History[(Offset-(Delay[1]>>HRTFDELAY_BITS))&HRTF_HISTORY_MASK],
+ hrtfstate->History[(Offset-(Delay[1]>>HRTFDELAY_BITS)-1)&HRTF_HISTORY_MASK],
+ (Delay[1]&HRTFDELAY_MASK)*(1.0f/HRTFDELAY_FRACONE));
- Delay[0] += hrtfparams->DelayStep[0];
- Delay[1] += hrtfparams->DelayStep[1];
+ Delay[0] += hrtfparams->Steps.Delay[0];
+ Delay[1] += hrtfparams->Steps.Delay[1];
- hrtfstate->Values[(Offset+IrSize)&HRIR_MASK][0] = 0.0f;
- hrtfstate->Values[(Offset+IrSize)&HRIR_MASK][1] = 0.0f;
- Offset++;
+ hrtfstate->Values[(Offset+IrSize)&HRIR_MASK][0] = 0.0f;
+ hrtfstate->Values[(Offset+IrSize)&HRIR_MASK][1] = 0.0f;
+ Offset++;
- ApplyCoeffsStep(Offset, hrtfstate->Values, IrSize, Coeffs, hrtfparams->CoeffStep, left, right);
- OutBuffer[0][OutPos] += hrtfstate->Values[Offset&HRIR_MASK][0];
- OutBuffer[1][OutPos] += hrtfstate->Values[Offset&HRIR_MASK][1];
- OutPos++;
+ ApplyCoeffsStep(Offset, hrtfstate->Values, IrSize, Coeffs, hrtfparams->Steps.Coeffs, left, right);
+ OutBuffer[0][OutPos] += hrtfstate->Values[Offset&HRIR_MASK][0];
+ OutBuffer[1][OutPos] += hrtfstate->Values[Offset&HRIR_MASK][1];
+ OutPos++;
+ }
+
+ if(pos == Counter)
+ {
+ *hrtfparams->Current = *hrtfparams->Target;
+ Delay[0] = hrtfparams->Target->Delay[0];
+ Delay[1] = hrtfparams->Target->Delay[1];
+ }
}
Delay[0] >>= HRTFDELAY_BITS;