etlegacy-libs/openal/Alc/mixer/hrtf_inc.c

129 lines
4.5 KiB
C
Raw Normal View History

2015-12-12 21:07:33 +00:00
#include "config.h"
#include "alMain.h"
#include "alSource.h"
#include "hrtf.h"
#include "align.h"
2017-07-01 14:18:03 +00:00
#include "alu.h"
2019-01-03 15:00:15 +00:00
#include "defs.h"
2015-12-12 21:07:33 +00:00
2017-07-01 14:18:03 +00:00
static inline void ApplyCoeffs(ALsizei Offset, ALfloat (*restrict Values)[2],
const ALsizei irSize,
const ALfloat (*restrict Coeffs)[2],
2015-12-12 21:07:33 +00:00
ALfloat left, ALfloat right);
2017-07-01 14:18:03 +00:00
void MixHrtf(ALfloat *restrict LeftOut, ALfloat *restrict RightOut,
const ALfloat *data, ALsizei Offset, ALsizei OutPos,
const ALsizei IrSize, MixHrtfParams *hrtfparams, HrtfState *hrtfstate,
ALsizei BufferSize)
2015-12-12 21:07:33 +00:00
{
2017-07-01 14:18:03 +00:00
const ALfloat (*Coeffs)[2] = ASSUME_ALIGNED(hrtfparams->Coeffs, 16);
const ALsizei Delay[2] = { hrtfparams->Delay[0], hrtfparams->Delay[1] };
2019-01-03 15:00:15 +00:00
const ALfloat gainstep = hrtfparams->GainStep;
const ALfloat gain = hrtfparams->Gain;
ALfloat g, stepcount = 0.0f;
2015-12-12 21:07:33 +00:00
ALfloat left, right;
2017-07-01 14:18:03 +00:00
ALsizei i;
2015-12-12 21:07:33 +00:00
2019-01-03 15:00:15 +00:00
ASSUME(IrSize >= 4);
ASSUME(BufferSize > 0);
2017-07-01 14:18:03 +00:00
LeftOut += OutPos;
RightOut += OutPos;
for(i = 0;i < BufferSize;i++)
2015-12-12 21:07:33 +00:00
{
2017-07-01 14:18:03 +00:00
hrtfstate->History[Offset&HRTF_HISTORY_MASK] = *(data++);
2019-01-03 15:00:15 +00:00
g = gain + gainstep*stepcount;
left = hrtfstate->History[(Offset-Delay[0])&HRTF_HISTORY_MASK]*g;
right = hrtfstate->History[(Offset-Delay[1])&HRTF_HISTORY_MASK]*g;
2017-07-01 14:18:03 +00:00
hrtfstate->Values[(Offset+IrSize-1)&HRIR_MASK][0] = 0.0f;
hrtfstate->Values[(Offset+IrSize-1)&HRIR_MASK][1] = 0.0f;
2015-12-12 21:07:33 +00:00
2017-07-01 14:18:03 +00:00
ApplyCoeffs(Offset, hrtfstate->Values, IrSize, Coeffs, left, right);
*(LeftOut++) += hrtfstate->Values[Offset&HRIR_MASK][0];
*(RightOut++) += hrtfstate->Values[Offset&HRIR_MASK][1];
2019-01-03 15:00:15 +00:00
stepcount += 1.0f;
2017-07-01 14:18:03 +00:00
Offset++;
2015-12-12 21:07:33 +00:00
}
2019-01-03 15:00:15 +00:00
hrtfparams->Gain = gain + gainstep*stepcount;
2017-07-01 14:18:03 +00:00
}
2015-12-12 21:07:33 +00:00
2017-07-01 14:18:03 +00:00
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] };
2019-01-03 15:00:15 +00:00
const ALfloat oldGain = oldparams->Gain;
const ALfloat oldGainStep = -oldGain / (ALfloat)BufferSize;
2017-07-01 14:18:03 +00:00
const ALfloat (*NewCoeffs)[2] = ASSUME_ALIGNED(newparams->Coeffs, 16);
const ALsizei NewDelay[2] = { newparams->Delay[0], newparams->Delay[1] };
2019-01-03 15:00:15 +00:00
const ALfloat newGain = newparams->Gain;
const ALfloat newGainStep = newparams->GainStep;
ALfloat g, stepcount = 0.0f;
2017-07-01 14:18:03 +00:00
ALfloat left, right;
ALsizei i;
2019-01-03 15:00:15 +00:00
ASSUME(IrSize >= 4);
ASSUME(BufferSize > 0);
2017-07-01 14:18:03 +00:00
LeftOut += OutPos;
RightOut += OutPos;
for(i = 0;i < BufferSize;i++)
2015-12-12 21:07:33 +00:00
{
2017-07-01 14:18:03 +00:00
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++);
2015-12-12 21:07:33 +00:00
2019-01-03 15:00:15 +00:00
g = oldGain + oldGainStep*stepcount;
left = hrtfstate->History[(Offset-OldDelay[0])&HRTF_HISTORY_MASK]*g;
right = hrtfstate->History[(Offset-OldDelay[1])&HRTF_HISTORY_MASK]*g;
2017-07-01 14:18:03 +00:00
ApplyCoeffs(Offset, hrtfstate->Values, IrSize, OldCoeffs, left, right);
2019-01-03 15:00:15 +00:00
g = newGain + newGainStep*stepcount;
left = hrtfstate->History[(Offset-NewDelay[0])&HRTF_HISTORY_MASK]*g;
right = hrtfstate->History[(Offset-NewDelay[1])&HRTF_HISTORY_MASK]*g;
2017-07-01 14:18:03 +00:00
ApplyCoeffs(Offset, hrtfstate->Values, IrSize, NewCoeffs, left, right);
*(LeftOut++) += hrtfstate->Values[Offset&HRIR_MASK][0];
*(RightOut++) += hrtfstate->Values[Offset&HRIR_MASK][1];
2019-01-03 15:00:15 +00:00
stepcount += 1.0f;
2015-12-12 21:07:33 +00:00
Offset++;
2017-07-01 14:18:03 +00:00
}
2019-01-03 15:00:15 +00:00
newparams->Gain = newGain + newGainStep*stepcount;
2017-07-01 14:18:03 +00:00
}
2015-12-12 21:07:33 +00:00
2017-07-01 14:18:03 +00:00
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],
ALsizei BufferSize)
{
ALfloat insample;
ALsizei i;
2019-01-03 15:00:15 +00:00
ASSUME(IrSize >= 4);
ASSUME(BufferSize > 0);
2017-07-01 14:18:03 +00:00
for(i = 0;i < BufferSize;i++)
{
Values[(Offset+IrSize)&HRIR_MASK][0] = 0.0f;
Values[(Offset+IrSize)&HRIR_MASK][1] = 0.0f;
Offset++;
insample = *(data++);
ApplyCoeffs(Offset, Values, IrSize, Coeffs, insample, insample);
*(LeftOut++) += Values[Offset&HRIR_MASK][0];
*(RightOut++) += Values[Offset&HRIR_MASK][1];
2015-12-12 21:07:33 +00:00
}
}