2012-08-15 01:01:55 -07:00
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include "alMain.h"
|
|
|
|
#include "alSource.h"
|
2014-04-19 02:11:04 -07:00
|
|
|
|
2014-02-23 21:11:01 -08:00
|
|
|
#include "hrtf.h"
|
2012-08-15 01:01:55 -07:00
|
|
|
#include "mixer_defs.h"
|
2014-04-19 02:11:04 -07:00
|
|
|
#include "align.h"
|
2016-02-14 03:23:06 -08:00
|
|
|
#include "alu.h"
|
2012-08-15 01:01:55 -07:00
|
|
|
|
|
|
|
|
2017-01-16 07:45:07 -08:00
|
|
|
static inline void ApplyCoeffs(ALsizei Offset, ALfloat (*restrict Values)[2],
|
|
|
|
const ALsizei irSize,
|
2017-03-11 18:04:06 -08:00
|
|
|
const ALfloat (*restrict Coeffs)[2],
|
2013-05-28 22:27:07 -07:00
|
|
|
ALfloat left, ALfloat right);
|
2012-09-08 21:34:36 -07:00
|
|
|
|
2012-08-29 01:56:04 -07:00
|
|
|
|
2017-01-17 16:49:26 -08:00
|
|
|
void MixHrtf(ALfloat *restrict LeftOut, ALfloat *restrict RightOut,
|
2017-03-11 18:04:06 -08:00
|
|
|
const ALfloat *data, ALsizei Offset, ALsizei OutPos,
|
|
|
|
const ALsizei IrSize, MixHrtfParams *hrtfparams, HrtfState *hrtfstate,
|
2017-01-16 07:45:07 -08:00
|
|
|
ALsizei BufferSize)
|
2012-08-15 01:01:55 -07:00
|
|
|
{
|
2017-03-12 06:58:27 -07:00
|
|
|
const ALfloat (*Coeffs)[2] = ASSUME_ALIGNED(hrtfparams->Coeffs, 16);
|
|
|
|
const ALsizei Delay[2] = { hrtfparams->Delay[0], hrtfparams->Delay[1] };
|
2017-03-11 18:04:06 -08:00
|
|
|
ALfloat gainstep = hrtfparams->GainStep;
|
|
|
|
ALfloat gain = hrtfparams->Gain;
|
2012-09-08 21:34:36 -07:00
|
|
|
ALfloat left, right;
|
2017-04-27 06:35:53 -07:00
|
|
|
ALsizei i;
|
2012-08-15 01:01:55 -07:00
|
|
|
|
2017-04-27 06:35:53 -07:00
|
|
|
LeftOut += OutPos;
|
|
|
|
RightOut += OutPos;
|
|
|
|
for(i = 0;i < BufferSize;i++)
|
2012-09-08 21:34:36 -07:00
|
|
|
{
|
2017-04-27 06:35:53 -07:00
|
|
|
hrtfstate->History[Offset&HRTF_HISTORY_MASK] = *(data++);
|
2017-05-03 03:29:21 -07:00
|
|
|
left = hrtfstate->History[(Offset-Delay[0])&HRTF_HISTORY_MASK]*gain;
|
|
|
|
right = hrtfstate->History[(Offset-Delay[1])&HRTF_HISTORY_MASK]*gain;
|
2017-04-27 06:35:53 -07:00
|
|
|
|
2017-05-03 03:29:21 -07:00
|
|
|
hrtfstate->Values[(Offset+IrSize-1)&HRIR_MASK][0] = 0.0f;
|
|
|
|
hrtfstate->Values[(Offset+IrSize-1)&HRIR_MASK][1] = 0.0f;
|
2017-04-27 06:35:53 -07:00
|
|
|
|
|
|
|
ApplyCoeffs(Offset, hrtfstate->Values, IrSize, Coeffs, left, right);
|
2017-05-03 03:29:21 -07:00
|
|
|
*(LeftOut++) += hrtfstate->Values[Offset&HRIR_MASK][0];
|
|
|
|
*(RightOut++) += hrtfstate->Values[Offset&HRIR_MASK][1];
|
|
|
|
|
2017-04-27 06:35:53 -07:00
|
|
|
gain += gainstep;
|
2017-05-03 03:29:21 -07:00
|
|
|
Offset++;
|
2012-09-08 21:34:36 -07:00
|
|
|
}
|
2017-03-11 18:04:06 -08:00
|
|
|
hrtfparams->Gain = gain;
|
2012-08-15 01:01:55 -07:00
|
|
|
}
|
2016-08-12 05:26:36 -07:00
|
|
|
|
2017-05-03 03:29:21 -07: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] };
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2017-01-17 16:49:26 -08:00
|
|
|
void MixDirectHrtf(ALfloat *restrict LeftOut, ALfloat *restrict RightOut,
|
2017-01-16 07:45:07 -08:00
|
|
|
const ALfloat *data, ALsizei Offset, const ALsizei IrSize,
|
2017-03-11 18:04:06 -08:00
|
|
|
const ALfloat (*restrict Coeffs)[2], ALfloat (*restrict Values)[2],
|
2017-01-16 07:45:07 -08:00
|
|
|
ALsizei BufferSize)
|
2016-08-12 05:26:36 -07:00
|
|
|
{
|
|
|
|
ALfloat insample;
|
2017-04-27 06:35:53 -07:00
|
|
|
ALsizei i;
|
2016-08-12 05:26:36 -07:00
|
|
|
|
2017-04-27 06:35:53 -07:00
|
|
|
for(i = 0;i < BufferSize;i++)
|
2016-08-12 05:26:36 -07:00
|
|
|
{
|
2017-04-27 06:35:53 -07:00
|
|
|
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];
|
2016-08-12 05:26:36 -07:00
|
|
|
}
|
|
|
|
}
|