aboutsummaryrefslogtreecommitdiffstats
path: root/Alc/mixer_inc.c
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2017-05-03 03:29:21 -0700
committerChris Robinson <[email protected]>2017-05-03 03:29:21 -0700
commit444e9563b357b4e2af0d428afac9f87596aba9a6 (patch)
tree1fc1f56f2a748332ad21b482895ea1fff3f7f9f7 /Alc/mixer_inc.c
parent4e5c4b8e01060bb34c58480895e70a0529d8a55e (diff)
Add a mixing function to blend HRIRs
This is a bit more efficient than calling the normal HRTF mixing function twice, and helps solve the problem of the values generated from convolution not being consistent with the new HRIR.
Diffstat (limited to 'Alc/mixer_inc.c')
-rw-r--r--Alc/mixer_inc.c59
1 files changed, 52 insertions, 7 deletions
diff --git a/Alc/mixer_inc.c b/Alc/mixer_inc.c
index 16c3a61e..3c9d4dc5 100644
--- a/Alc/mixer_inc.c
+++ b/Alc/mixer_inc.c
@@ -32,21 +32,66 @@ void MixHrtf(ALfloat *restrict LeftOut, ALfloat *restrict RightOut,
for(i = 0;i < BufferSize;i++)
{
hrtfstate->History[Offset&HRTF_HISTORY_MASK] = *(data++);
- left = hrtfstate->History[(Offset-Delay[0])&HRTF_HISTORY_MASK];
- right = hrtfstate->History[(Offset-Delay[1])&HRTF_HISTORY_MASK];
+ left = hrtfstate->History[(Offset-Delay[0])&HRTF_HISTORY_MASK]*gain;
+ right = hrtfstate->History[(Offset-Delay[1])&HRTF_HISTORY_MASK]*gain;
- hrtfstate->Values[(Offset+IrSize)&HRIR_MASK][0] = 0.0f;
- hrtfstate->Values[(Offset+IrSize)&HRIR_MASK][1] = 0.0f;
- Offset++;
+ hrtfstate->Values[(Offset+IrSize-1)&HRIR_MASK][0] = 0.0f;
+ hrtfstate->Values[(Offset+IrSize-1)&HRIR_MASK][1] = 0.0f;
ApplyCoeffs(Offset, hrtfstate->Values, IrSize, Coeffs, left, right);
- *(LeftOut++) += hrtfstate->Values[Offset&HRIR_MASK][0]*gain;
- *(RightOut++) += hrtfstate->Values[Offset&HRIR_MASK][1]*gain;
+ *(LeftOut++) += hrtfstate->Values[Offset&HRIR_MASK][0];
+ *(RightOut++) += hrtfstate->Values[Offset&HRIR_MASK][1];
+
gain += gainstep;
+ Offset++;
}
hrtfparams->Gain = gain;
}
+void MixHrtfBlend(ALfloat *restrict LeftOut, ALfloat *restrict RightOut,
+ const ALfloat *data, ALsizei Offset, ALsizei OutPos,
+ const ALsizei IrSize, const HrtfParams *oldparams,
+ MixHrtfParams *newparams, HrtfState *hrtfstate,
+ ALsizei BufferSize)
+{
+ const ALfloat (*OldCoeffs)[2] = ASSUME_ALIGNED(oldparams->Coeffs, 16);
+ const ALsizei OldDelay[2] = { oldparams->Delay[0], oldparams->Delay[1] };
+ ALfloat oldGain = oldparams->Gain;
+ ALfloat oldGainStep = -oldGain / (ALfloat)BufferSize;
+ const ALfloat (*NewCoeffs)[2] = ASSUME_ALIGNED(newparams->Coeffs, 16);
+ const ALsizei NewDelay[2] = { newparams->Delay[0], newparams->Delay[1] };
+ ALfloat newGain = newparams->Gain;
+ ALfloat newGainStep = newparams->GainStep;
+ ALfloat left, right;
+ ALsizei i;
+
+ LeftOut += OutPos;
+ RightOut += OutPos;
+ for(i = 0;i < BufferSize;i++)
+ {
+ hrtfstate->Values[(Offset+IrSize-1)&HRIR_MASK][0] = 0.0f;
+ hrtfstate->Values[(Offset+IrSize-1)&HRIR_MASK][1] = 0.0f;
+
+ hrtfstate->History[Offset&HRTF_HISTORY_MASK] = *(data++);
+
+ left = hrtfstate->History[(Offset-OldDelay[0])&HRTF_HISTORY_MASK]*oldGain;
+ right = hrtfstate->History[(Offset-OldDelay[1])&HRTF_HISTORY_MASK]*oldGain;
+ ApplyCoeffs(Offset, hrtfstate->Values, IrSize, OldCoeffs, left, right);
+
+ left = hrtfstate->History[(Offset-NewDelay[0])&HRTF_HISTORY_MASK]*newGain;
+ right = hrtfstate->History[(Offset-NewDelay[1])&HRTF_HISTORY_MASK]*newGain;
+ ApplyCoeffs(Offset, hrtfstate->Values, IrSize, NewCoeffs, left, right);
+
+ *(LeftOut++) += hrtfstate->Values[Offset&HRIR_MASK][0];
+ *(RightOut++) += hrtfstate->Values[Offset&HRIR_MASK][1];
+
+ oldGain += oldGainStep;
+ newGain += newGainStep;
+ Offset++;
+ }
+ newparams->Gain = newGain;
+}
+
void MixDirectHrtf(ALfloat *restrict LeftOut, ALfloat *restrict RightOut,
const ALfloat *data, ALsizei Offset, const ALsizei IrSize,
const ALfloat (*restrict Coeffs)[2], ALfloat (*restrict Values)[2],