Handle HRTF coefficients and values by reference where possible

This commit is contained in:
Chris Robinson
2018-12-26 15:35:05 -08:00
parent c5be03b51e
commit 4f253a935a
8 changed files with 42 additions and 44 deletions
+1 -4
View File
@@ -139,10 +139,7 @@ void ProcessHrtf(ALCdevice *device, ALsizei SamplesToDo)
const ALfloat (*Input)[BUFFERSIZE]{device->Dry.Buffer};
DirectHrtfState *state{device->mHrtfState.get()};
for(ALsizei c{0};c < num_chans;c++)
{
MixDirectHrtf(LeftOut, RightOut, Input[c], state->Offset, state->IrSize,
state->Chan[c].Coeffs, state->Chan[c].Values, SamplesToDo);
}
MixDirectHrtf(LeftOut, RightOut, Input[c], state, c, SamplesToDo);
state->Offset += SamplesToDo;
}
+7 -9
View File
@@ -10,6 +10,7 @@
struct MixGains;
struct MixHrtfParams;
struct HrtfState;
struct DirectHrtfState;
/* C resamplers */
const ALfloat *Resample_copy_C(const InterpState *state, const ALfloat *RESTRICT src, ALsizei frac, ALint increment, ALfloat *RESTRICT dst, ALsizei dstlen);
@@ -30,9 +31,8 @@ void MixHrtfBlend_C(ALfloat *RESTRICT LeftOut, ALfloat *RESTRICT RightOut,
MixHrtfParams *newparams, HrtfState *hrtfstate,
ALsizei BufferSize);
void MixDirectHrtf_C(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);
const ALfloat *data, DirectHrtfState *State, const ALsizei Chan,
const ALsizei BufferSize);
void Mix_C(const ALfloat *data, ALsizei OutChans, ALfloat (*RESTRICT OutBuffer)[BUFFERSIZE],
ALfloat *CurrentGains, const ALfloat *TargetGains, ALsizei Counter, ALsizei OutPos,
ALsizei BufferSize);
@@ -51,9 +51,8 @@ void MixHrtfBlend_SSE(ALfloat *RESTRICT LeftOut, ALfloat *RESTRICT RightOut,
MixHrtfParams *newparams, HrtfState *hrtfstate,
ALsizei BufferSize);
void MixDirectHrtf_SSE(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);
const ALfloat *data, DirectHrtfState *State, const ALsizei Chan,
const ALsizei BufferSize);
void Mix_SSE(const ALfloat *data, ALsizei OutChans, ALfloat (*RESTRICT OutBuffer)[BUFFERSIZE],
ALfloat *CurrentGains, const ALfloat *TargetGains, ALsizei Counter, ALsizei OutPos,
ALsizei BufferSize);
@@ -98,9 +97,8 @@ void MixHrtfBlend_Neon(ALfloat *RESTRICT LeftOut, ALfloat *RESTRICT RightOut,
MixHrtfParams *newparams, HrtfState *hrtfstate,
ALsizei BufferSize);
void MixDirectHrtf_Neon(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);
const ALfloat *data, DirectHrtfState *State, const ALsizei Chan,
const ALsizei BufferSize);
void Mix_Neon(const ALfloat *data, ALsizei OutChans, ALfloat (*RESTRICT OutBuffer)[BUFFERSIZE],
ALfloat *CurrentGains, const ALfloat *TargetGains, ALsizei Counter, ALsizei OutPos,
ALsizei BufferSize);
+13 -10
View File
@@ -8,10 +8,9 @@
#include "defs.h"
static inline void ApplyCoeffs(ALsizei Offset, ALfloat (*RESTRICT Values)[2],
const ALsizei irSize,
const ALfloat (*RESTRICT Coeffs)[2],
ALfloat left, ALfloat right);
static inline void ApplyCoeffs(ALsizei Offset, ALfloat (&Values)[HRIR_LENGTH][2],
const ALsizei irSize, const ALfloat (&Coeffs)[HRIR_LENGTH][2],
const ALfloat left, const ALfloat right);
void MixHrtf(ALfloat *RESTRICT LeftOut, ALfloat *RESTRICT RightOut,
@@ -19,7 +18,7 @@ void MixHrtf(ALfloat *RESTRICT LeftOut, ALfloat *RESTRICT RightOut,
const ALsizei IrSize, MixHrtfParams *hrtfparams, HrtfState *hrtfstate,
ALsizei BufferSize)
{
const ALfloat (*Coeffs)[2] = hrtfparams->Coeffs;
const ALfloat (&Coeffs)[HRIR_LENGTH][2] = *hrtfparams->Coeffs;
const ALsizei Delay[2] = { hrtfparams->Delay[0], hrtfparams->Delay[1] };
const ALfloat gainstep = hrtfparams->GainStep;
const ALfloat gain = hrtfparams->Gain;
@@ -59,11 +58,11 @@ void MixHrtfBlend(ALfloat *RESTRICT LeftOut, ALfloat *RESTRICT RightOut,
MixHrtfParams *newparams, HrtfState *hrtfstate,
ALsizei BufferSize)
{
const ALfloat (*OldCoeffs)[2] = oldparams->Coeffs;
const ALfloat (&OldCoeffs)[HRIR_LENGTH][2] = oldparams->Coeffs;
const ALsizei OldDelay[2] = { oldparams->Delay[0], oldparams->Delay[1] };
const ALfloat oldGain = oldparams->Gain;
const ALfloat oldGainStep = -oldGain / (ALfloat)BufferSize;
const ALfloat (*NewCoeffs)[2] = newparams->Coeffs;
const ALfloat (&NewCoeffs)[HRIR_LENGTH][2] = *newparams->Coeffs;
const ALsizei NewDelay[2] = { newparams->Delay[0], newparams->Delay[1] };
const ALfloat newGain = newparams->Gain;
const ALfloat newGainStep = newparams->GainStep;
@@ -103,10 +102,14 @@ void MixHrtfBlend(ALfloat *RESTRICT LeftOut, ALfloat *RESTRICT RightOut,
}
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)
const ALfloat *data, DirectHrtfState *State, const ALsizei Chan,
const ALsizei BufferSize)
{
const ALsizei IrSize{State->IrSize};
ALsizei Offset{State->Offset};
ALfloat (&Values)[HRIR_LENGTH][2] = State->Chan[Chan].Values;
const ALfloat (&Coeffs)[HRIR_LENGTH][2] = State->Chan[Chan].Coeffs;
ASSUME(IrSize >= 4);
ASSUME(BufferSize > 0);
+5 -5
View File
@@ -103,15 +103,15 @@ const ALfloat *Resample_bsinc_C(const InterpState *state, const ALfloat *RESTRIC
{ return DoResample<do_bsinc>(state, src-state->bsinc.l, frac, increment, dst, numsamples); }
static inline void ApplyCoeffs(ALsizei Offset, ALfloat (*RESTRICT Values)[2],
const ALsizei IrSize,
const ALfloat (*RESTRICT Coeffs)[2],
ALfloat left, ALfloat right)
static inline void ApplyCoeffs(ALsizei Offset, ALfloat (&Values)[HRIR_LENGTH][2],
const ALsizei IrSize, const ALfloat (&Coeffs)[HRIR_LENGTH][2],
const ALfloat left, const ALfloat right)
{
ALsizei off{Offset&HRIR_MASK};
ALsizei count{mini(IrSize, HRIR_LENGTH - off)};
ASSUME(IrSize > 0);
ASSUME(IrSize >= 2);
ASSUME(&Values != &Coeffs);
ASSUME(count > 0);
for(ALsizei c{0};;)
+7 -6
View File
@@ -133,12 +133,13 @@ const ALfloat *Resample_bsinc_Neon(const InterpState *state,
}
static inline void ApplyCoeffs(ALsizei Offset, ALfloat (*RESTRICT Values)[2],
const ALsizei IrSize,
const ALfloat (*RESTRICT Coeffs)[2],
ALfloat left, ALfloat right)
static inline void ApplyCoeffs(ALsizei Offset, ALfloat (&Values)[HRIR_LENGTH][2],
const ALsizei IrSize, const ALfloat (&Coeffs)[HRIR_LENGTH][2],
const ALfloat left, const ALfloat right)
{
ALsizei c;
ASSUME(IrSize >= 2);
ASSUME(&Values != &Coeffs);
float32x4_t leftright4;
{
float32x2_t leftright2 = vdup_n_f32(0.0);
@@ -147,7 +148,7 @@ static inline void ApplyCoeffs(ALsizei Offset, ALfloat (*RESTRICT Values)[2],
leftright4 = vcombine_f32(leftright2, leftright2);
}
for(c = 0;c < IrSize;c += 2)
for(ALsizei c{0};c < IrSize;c += 2)
{
const ALsizei o0 = (Offset+c)&HRIR_MASK;
const ALsizei o1 = (o0+1)&HRIR_MASK;
+5 -5
View File
@@ -79,16 +79,16 @@ const ALfloat *Resample_bsinc_SSE(const InterpState *state, const ALfloat *RESTR
}
static inline void ApplyCoeffs(ALsizei Offset, ALfloat (*RESTRICT Values)[2],
const ALsizei IrSize,
const ALfloat (*RESTRICT Coeffs)[2],
ALfloat left, ALfloat right)
static inline void ApplyCoeffs(ALsizei Offset, ALfloat (&Values)[HRIR_LENGTH][2],
const ALsizei IrSize, const ALfloat (&Coeffs)[HRIR_LENGTH][2],
const ALfloat left, const ALfloat right)
{
const __m128 lrlr = _mm_setr_ps(left, right, left, right);
__m128 vals = _mm_setzero_ps();
__m128 coeffs;
ASSUME(IrSize > 1);
ASSUME(IrSize >= 2);
ASSUME(&Values != &Coeffs);
ALsizei off{Offset&HRIR_MASK};
if((Offset&1))
+2 -2
View File
@@ -605,7 +605,7 @@ ALboolean MixSource(ALvoice *voice, const ALuint SourceID, ALCcontext *Context,
ALfloat gain{lerp(parms.Hrtf.Old.Gain, parms.Hrtf.Target.Gain,
minf(1.0f, (ALfloat)fademix/Counter))};
MixHrtfParams hrtfparams;
hrtfparams.Coeffs = parms.Hrtf.Target.Coeffs;
hrtfparams.Coeffs = &parms.Hrtf.Target.Coeffs;
hrtfparams.Delay[0] = parms.Hrtf.Target.Delay[0];
hrtfparams.Delay[1] = parms.Hrtf.Target.Delay[1];
hrtfparams.Gain = 0.0f;
@@ -634,7 +634,7 @@ ALboolean MixSource(ALvoice *voice, const ALuint SourceID, ALCcontext *Context,
(ALfloat)todo/(Counter-fademix));
MixHrtfParams hrtfparams;
hrtfparams.Coeffs = parms.Hrtf.Target.Coeffs;
hrtfparams.Coeffs = &parms.Hrtf.Target.Coeffs;
hrtfparams.Delay[0] = parms.Hrtf.Target.Delay[0];
hrtfparams.Delay[1] = parms.Hrtf.Target.Delay[1];
hrtfparams.Gain = parms.Hrtf.Old.Gain;
+2 -3
View File
@@ -108,7 +108,7 @@ enum {
struct MixHrtfParams {
const ALfloat (*Coeffs)[2];
const ALfloat (*Coeffs)[HRIR_LENGTH][2];
ALsizei Delay[2];
ALfloat Gain;
ALfloat GainStep;
@@ -286,8 +286,7 @@ using HrtfMixerBlendFunc = void(*)(ALfloat *RESTRICT LeftOut, ALfloat *RESTRICT
const HrtfParams *oldparams, MixHrtfParams *newparams, HrtfState *hrtfstate,
ALsizei BufferSize);
using HrtfDirectMixerFunc = void(*)(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);
const ALfloat *data, DirectHrtfState *State, const ALsizei Chan, const ALsizei BufferSize);
#define GAIN_MIX_MAX (1000.0f) /* +60dB */