Better pack HRTF mixing properties
This commit is contained in:
parent
b2e533fbfc
commit
d066c7b124
48
Alc/ALu.c
48
Alc/ALu.c
@ -473,12 +473,12 @@ ALvoid CalcNonAttnSourceParams(ALactivesource *src, const ALCcontext *ALContext)
|
||||
if(chans[c].channel == LFE)
|
||||
{
|
||||
/* Skip LFE */
|
||||
src->Direct.Mix.Hrtf.Params.Delay[c][0] = 0;
|
||||
src->Direct.Mix.Hrtf.Params.Delay[c][1] = 0;
|
||||
src->Direct.Mix.Hrtf.Params[c].Delay[0] = 0;
|
||||
src->Direct.Mix.Hrtf.Params[c].Delay[1] = 0;
|
||||
for(i = 0;i < HRIR_LENGTH;i++)
|
||||
{
|
||||
src->Direct.Mix.Hrtf.Params.Coeffs[c][i][0] = 0.0f;
|
||||
src->Direct.Mix.Hrtf.Params.Coeffs[c][i][1] = 0.0f;
|
||||
src->Direct.Mix.Hrtf.Params[c].Coeffs[i][0] = 0.0f;
|
||||
src->Direct.Mix.Hrtf.Params[c].Coeffs[i][1] = 0.0f;
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -487,13 +487,13 @@ ALvoid CalcNonAttnSourceParams(ALactivesource *src, const ALCcontext *ALContext)
|
||||
* channel. */
|
||||
GetLerpedHrtfCoeffs(Device->Hrtf,
|
||||
0.0f, chans[c].angle, DryGain,
|
||||
src->Direct.Mix.Hrtf.Params.Coeffs[c],
|
||||
src->Direct.Mix.Hrtf.Params.Delay[c]);
|
||||
src->Direct.Mix.Hrtf.Params[c].Coeffs,
|
||||
src->Direct.Mix.Hrtf.Params[c].Delay);
|
||||
}
|
||||
}
|
||||
src->Direct.Counter = 0;
|
||||
src->Direct.Moving = AL_TRUE;
|
||||
src->Direct.Mix.Hrtf.Params.IrSize = GetHrtfIrSize(Device->Hrtf);
|
||||
src->Direct.Mix.Hrtf.IrSize = GetHrtfIrSize(Device->Hrtf);
|
||||
|
||||
src->DryMix = SelectHrtfMixer();
|
||||
}
|
||||
@ -948,8 +948,8 @@ ALvoid CalcSourceParams(ALactivesource *src, const ALCcontext *ALContext)
|
||||
if(src->Direct.Moving)
|
||||
{
|
||||
/* Calculate the normalized HRTF transition factor (delta). */
|
||||
delta = CalcHrtfDelta(src->Direct.Mix.Hrtf.Params.Gain, DryGain,
|
||||
src->Direct.Mix.Hrtf.Params.Dir, Position);
|
||||
delta = CalcHrtfDelta(src->Direct.Mix.Hrtf.Gain, DryGain,
|
||||
src->Direct.Mix.Hrtf.Dir, Position);
|
||||
/* If the delta is large enough, get the moving HRIR target
|
||||
* coefficients, target delays, steppping values, and counter. */
|
||||
if(delta > 0.001f)
|
||||
@ -957,31 +957,31 @@ ALvoid CalcSourceParams(ALactivesource *src, const ALCcontext *ALContext)
|
||||
ALuint counter = GetMovingHrtfCoeffs(Device->Hrtf,
|
||||
ev, az, DryGain, delta,
|
||||
src->Direct.Counter,
|
||||
src->Direct.Mix.Hrtf.Params.Coeffs[0],
|
||||
src->Direct.Mix.Hrtf.Params.Delay[0],
|
||||
src->Direct.Mix.Hrtf.Params.CoeffStep[0],
|
||||
src->Direct.Mix.Hrtf.Params.DelayStep[0]);
|
||||
src->Direct.Mix.Hrtf.Params[0].Coeffs,
|
||||
src->Direct.Mix.Hrtf.Params[0].Delay,
|
||||
src->Direct.Mix.Hrtf.Params[0].CoeffStep,
|
||||
src->Direct.Mix.Hrtf.Params[0].DelayStep);
|
||||
src->Direct.Counter = counter;
|
||||
src->Direct.Mix.Hrtf.Params.Gain = DryGain;
|
||||
src->Direct.Mix.Hrtf.Params.Dir[0] = Position[0];
|
||||
src->Direct.Mix.Hrtf.Params.Dir[1] = Position[1];
|
||||
src->Direct.Mix.Hrtf.Params.Dir[2] = Position[2];
|
||||
src->Direct.Mix.Hrtf.Gain = DryGain;
|
||||
src->Direct.Mix.Hrtf.Dir[0] = Position[0];
|
||||
src->Direct.Mix.Hrtf.Dir[1] = Position[1];
|
||||
src->Direct.Mix.Hrtf.Dir[2] = Position[2];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Get the initial (static) HRIR coefficients and delays. */
|
||||
GetLerpedHrtfCoeffs(Device->Hrtf, ev, az, DryGain,
|
||||
src->Direct.Mix.Hrtf.Params.Coeffs[0],
|
||||
src->Direct.Mix.Hrtf.Params.Delay[0]);
|
||||
src->Direct.Mix.Hrtf.Params[0].Coeffs,
|
||||
src->Direct.Mix.Hrtf.Params[0].Delay);
|
||||
src->Direct.Counter = 0;
|
||||
src->Direct.Moving = AL_TRUE;
|
||||
src->Direct.Mix.Hrtf.Params.Gain = DryGain;
|
||||
src->Direct.Mix.Hrtf.Params.Dir[0] = Position[0];
|
||||
src->Direct.Mix.Hrtf.Params.Dir[1] = Position[1];
|
||||
src->Direct.Mix.Hrtf.Params.Dir[2] = Position[2];
|
||||
src->Direct.Mix.Hrtf.Gain = DryGain;
|
||||
src->Direct.Mix.Hrtf.Dir[0] = Position[0];
|
||||
src->Direct.Mix.Hrtf.Dir[1] = Position[1];
|
||||
src->Direct.Mix.Hrtf.Dir[2] = Position[2];
|
||||
}
|
||||
src->Direct.Mix.Hrtf.Params.IrSize = GetHrtfIrSize(Device->Hrtf);
|
||||
src->Direct.Mix.Hrtf.IrSize = GetHrtfIrSize(Device->Hrtf);
|
||||
|
||||
src->DryMix = SelectHrtfMixer();
|
||||
}
|
||||
|
@ -29,13 +29,9 @@ void MixDirect_Hrtf(DirectParams *params, const ALfloat *restrict data, ALuint s
|
||||
ALuint OutPos, ALuint BufferSize)
|
||||
{
|
||||
ALfloat (*restrict DryBuffer)[BUFFERSIZE] = params->OutBuffer;
|
||||
const ALuint IrSize = params->Mix.Hrtf.Params.IrSize;
|
||||
const ALint *restrict DelayStep = params->Mix.Hrtf.Params.DelayStep[srcchan];
|
||||
const ALfloat (*restrict CoeffStep)[2] = params->Mix.Hrtf.Params.CoeffStep[srcchan];
|
||||
const ALfloat (*restrict TargetCoeffs)[2] = params->Mix.Hrtf.Params.Coeffs[srcchan];
|
||||
const ALuint *restrict TargetDelay = params->Mix.Hrtf.Params.Delay[srcchan];
|
||||
ALfloat *restrict History = params->Mix.Hrtf.State.History[srcchan];
|
||||
ALfloat (*restrict Values)[2] = params->Mix.Hrtf.State.Values[srcchan];
|
||||
const ALuint IrSize = params->Mix.Hrtf.IrSize;
|
||||
const HrtfParams *hrtfparams = ¶ms->Mix.Hrtf.Params[srcchan];
|
||||
HrtfState *hrtfstate = ¶ms->Mix.Hrtf.State[srcchan];
|
||||
ALuint Counter = maxu(params->Counter, OutPos) - OutPos;
|
||||
ALuint Offset = params->Offset + OutPos;
|
||||
alignas(16) ALfloat Coeffs[HRIR_LENGTH][2];
|
||||
@ -47,33 +43,32 @@ void MixDirect_Hrtf(DirectParams *params, const ALfloat *restrict data, ALuint s
|
||||
pos = 0;
|
||||
for(c = 0;c < IrSize;c++)
|
||||
{
|
||||
Coeffs[c][0] = TargetCoeffs[c][0] - (CoeffStep[c][0]*Counter);
|
||||
Coeffs[c][1] = TargetCoeffs[c][1] - (CoeffStep[c][1]*Counter);
|
||||
Coeffs[c][0] = hrtfparams->Coeffs[c][0] - (hrtfparams->CoeffStep[c][0]*Counter);
|
||||
Coeffs[c][1] = hrtfparams->Coeffs[c][1] - (hrtfparams->CoeffStep[c][1]*Counter);
|
||||
}
|
||||
|
||||
Delay[0] = TargetDelay[0] - (DelayStep[0]*Counter);
|
||||
Delay[1] = TargetDelay[1] - (DelayStep[1]*Counter);
|
||||
Delay[0] = hrtfparams->Delay[0] - (hrtfparams->DelayStep[0]*Counter);
|
||||
Delay[1] = hrtfparams->Delay[1] - (hrtfparams->DelayStep[1]*Counter);
|
||||
|
||||
for(pos = 0;pos < BufferSize && pos < Counter;pos++)
|
||||
{
|
||||
History[Offset&SRC_HISTORY_MASK] = data[pos];
|
||||
left = lerp(History[(Offset-(Delay[0]>>HRTFDELAY_BITS))&SRC_HISTORY_MASK],
|
||||
History[(Offset-(Delay[0]>>HRTFDELAY_BITS)-1)&SRC_HISTORY_MASK],
|
||||
hrtfstate->History[Offset&SRC_HISTORY_MASK] = data[pos];
|
||||
left = lerp(hrtfstate->History[(Offset-(Delay[0]>>HRTFDELAY_BITS))&SRC_HISTORY_MASK],
|
||||
hrtfstate->History[(Offset-(Delay[0]>>HRTFDELAY_BITS)-1)&SRC_HISTORY_MASK],
|
||||
(Delay[0]&HRTFDELAY_MASK)*(1.0f/HRTFDELAY_FRACONE));
|
||||
right = lerp(History[(Offset-(Delay[1]>>HRTFDELAY_BITS))&SRC_HISTORY_MASK],
|
||||
History[(Offset-(Delay[1]>>HRTFDELAY_BITS)-1)&SRC_HISTORY_MASK],
|
||||
right = lerp(hrtfstate->History[(Offset-(Delay[1]>>HRTFDELAY_BITS))&SRC_HISTORY_MASK],
|
||||
hrtfstate->History[(Offset-(Delay[1]>>HRTFDELAY_BITS)-1)&SRC_HISTORY_MASK],
|
||||
(Delay[1]&HRTFDELAY_MASK)*(1.0f/HRTFDELAY_FRACONE));
|
||||
|
||||
Delay[0] += DelayStep[0];
|
||||
Delay[1] += DelayStep[1];
|
||||
Delay[0] += hrtfparams->DelayStep[0];
|
||||
Delay[1] += hrtfparams->DelayStep[1];
|
||||
|
||||
Values[(Offset+IrSize)&HRIR_MASK][0] = 0.0f;
|
||||
Values[(Offset+IrSize)&HRIR_MASK][1] = 0.0f;
|
||||
hrtfstate->Values[(Offset+IrSize)&HRIR_MASK][0] = 0.0f;
|
||||
hrtfstate->Values[(Offset+IrSize)&HRIR_MASK][1] = 0.0f;
|
||||
Offset++;
|
||||
|
||||
ApplyCoeffsStep(Offset, Values, IrSize, Coeffs, CoeffStep, left, right);
|
||||
DryBuffer[FrontLeft][OutPos] += Values[Offset&HRIR_MASK][0];
|
||||
DryBuffer[FrontRight][OutPos] += Values[Offset&HRIR_MASK][1];
|
||||
ApplyCoeffsStep(Offset, hrtfstate->Values, IrSize, Coeffs, hrtfparams->CoeffStep, left, right);
|
||||
DryBuffer[FrontLeft][OutPos] += hrtfstate->Values[Offset&HRIR_MASK][0];
|
||||
DryBuffer[FrontRight][OutPos] += hrtfstate->Values[Offset&HRIR_MASK][1];
|
||||
OutPos++;
|
||||
}
|
||||
|
||||
@ -81,17 +76,17 @@ void MixDirect_Hrtf(DirectParams *params, const ALfloat *restrict data, ALuint s
|
||||
Delay[1] >>= HRTFDELAY_BITS;
|
||||
for(;pos < BufferSize;pos++)
|
||||
{
|
||||
History[Offset&SRC_HISTORY_MASK] = data[pos];
|
||||
left = History[(Offset-Delay[0])&SRC_HISTORY_MASK];
|
||||
right = History[(Offset-Delay[1])&SRC_HISTORY_MASK];
|
||||
hrtfstate->History[Offset&SRC_HISTORY_MASK] = data[pos];
|
||||
left = hrtfstate->History[(Offset-Delay[0])&SRC_HISTORY_MASK];
|
||||
right = hrtfstate->History[(Offset-Delay[1])&SRC_HISTORY_MASK];
|
||||
|
||||
Values[(Offset+IrSize)&HRIR_MASK][0] = 0.0f;
|
||||
Values[(Offset+IrSize)&HRIR_MASK][1] = 0.0f;
|
||||
hrtfstate->Values[(Offset+IrSize)&HRIR_MASK][0] = 0.0f;
|
||||
hrtfstate->Values[(Offset+IrSize)&HRIR_MASK][1] = 0.0f;
|
||||
Offset++;
|
||||
|
||||
ApplyCoeffs(Offset, Values, IrSize, Coeffs, left, right);
|
||||
DryBuffer[FrontLeft][OutPos] += Values[Offset&HRIR_MASK][0];
|
||||
DryBuffer[FrontRight][OutPos] += Values[Offset&HRIR_MASK][1];
|
||||
ApplyCoeffs(Offset, hrtfstate->Values, IrSize, Coeffs, left, right);
|
||||
DryBuffer[FrontLeft][OutPos] += hrtfstate->Values[Offset&HRIR_MASK][0];
|
||||
DryBuffer[FrontRight][OutPos] += hrtfstate->Values[Offset&HRIR_MASK][1];
|
||||
|
||||
OutPos++;
|
||||
}
|
||||
|
@ -40,18 +40,15 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct HrtfState {
|
||||
alignas(16) ALfloat History[MAX_INPUT_CHANNELS][SRC_HISTORY_LENGTH];
|
||||
alignas(16) ALfloat Values[MAX_INPUT_CHANNELS][HRIR_LENGTH][2];
|
||||
alignas(16) ALfloat History[SRC_HISTORY_LENGTH];
|
||||
alignas(16) ALfloat Values[HRIR_LENGTH][2];
|
||||
} HrtfState;
|
||||
|
||||
typedef struct HrtfParams {
|
||||
ALfloat Gain;
|
||||
ALfloat Dir[3];
|
||||
alignas(16) ALfloat Coeffs[MAX_INPUT_CHANNELS][HRIR_LENGTH][2];
|
||||
alignas(16) ALfloat CoeffStep[MAX_INPUT_CHANNELS][HRIR_LENGTH][2];
|
||||
ALuint Delay[MAX_INPUT_CHANNELS][2];
|
||||
ALint DelayStep[MAX_INPUT_CHANNELS][2];
|
||||
ALuint IrSize;
|
||||
alignas(16) ALfloat Coeffs[HRIR_LENGTH][2];
|
||||
alignas(16) ALfloat CoeffStep[HRIR_LENGTH][2];
|
||||
ALuint Delay[2];
|
||||
ALint DelayStep[2];
|
||||
} HrtfParams;
|
||||
|
||||
typedef struct DirectParams {
|
||||
@ -59,8 +56,11 @@ typedef struct DirectParams {
|
||||
|
||||
union {
|
||||
struct {
|
||||
HrtfParams Params;
|
||||
HrtfState State;
|
||||
HrtfParams Params[MAX_INPUT_CHANNELS];
|
||||
HrtfState State[MAX_INPUT_CHANNELS];
|
||||
ALuint IrSize;
|
||||
ALfloat Gain;
|
||||
ALfloat Dir[3];
|
||||
} Hrtf;
|
||||
|
||||
/* A mixing matrix. First subscript is the channel number of the input
|
||||
|
@ -2347,11 +2347,11 @@ ALvoid SetSourceState(ALsource *Source, ALCcontext *Context, ALenum state)
|
||||
for(j = 0;j < MAX_INPUT_CHANNELS;j++)
|
||||
{
|
||||
for(k = 0;k < SRC_HISTORY_LENGTH;k++)
|
||||
src->Direct.Mix.Hrtf.State.History[j][k] = 0.0f;
|
||||
src->Direct.Mix.Hrtf.State[j].History[k] = 0.0f;
|
||||
for(k = 0;k < HRIR_LENGTH;k++)
|
||||
{
|
||||
src->Direct.Mix.Hrtf.State.Values[j][k][0] = 0.0f;
|
||||
src->Direct.Mix.Hrtf.State.Values[j][k][1] = 0.0f;
|
||||
src->Direct.Mix.Hrtf.State[j].Values[k][0] = 0.0f;
|
||||
src->Direct.Mix.Hrtf.State[j].Values[k][1] = 0.0f;
|
||||
}
|
||||
}
|
||||
for(i = 0;i < device->NumAuxSends;i++)
|
||||
|
Loading…
x
Reference in New Issue
Block a user