aboutsummaryrefslogtreecommitdiffstats
path: root/Alc/ALu.c
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2017-03-11 18:04:06 -0800
committerChris Robinson <[email protected]>2017-03-11 18:04:06 -0800
commit96aaab93662be289d3b2c5312ae50502afa8d221 (patch)
treec270633e689c7a64edaea8a6c15305197b435ced /Alc/ALu.c
parentfeffe1e81a155ded0bcdb519a1a126fd8e908baa (diff)
Rework HRTF coefficient fading
This improves fading between HRIRs as sources pan around. In particular, it improves the issue with individual coefficients having various rounding errors in the stepping values, as well as issues with interpolating delay values. It does this by doing two mixing passes for each source. First using the last coefficients that fade to silence, and then again using the new coefficients that fade from silence. When added together, it creates a linear fade from one to the other. Additionally, the gain is applied separately so the individual coefficients don't step with rounding errors. Although this does increase CPU cost since it's doing two mixes per source, each mix is a bit cheaper now since the stepping is simplified to a single gain value, and the overall quality is improved.
Diffstat (limited to 'Alc/ALu.c')
-rw-r--r--Alc/ALu.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/Alc/ALu.c b/Alc/ALu.c
index aff87895..55f0c09a 100644
--- a/Alc/ALu.c
+++ b/Alc/ALu.c
@@ -634,10 +634,11 @@ static void CalcNonAttnSourceParams(ALvoice *voice, const struct ALsourceProps *
/* Get the static HRIR coefficients and delays for this channel. */
GetHrtfCoeffs(Device->HrtfHandle,
- chans[c].elevation, chans[c].angle, 0.0f, DryGain,
+ chans[c].elevation, chans[c].angle, 0.0f,
voice->Direct.Params[c].Hrtf.Target.Coeffs,
voice->Direct.Params[c].Hrtf.Target.Delay
);
+ voice->Direct.Params[c].Hrtf.Target.Gain = DryGain;
/* Normal panning for auxiliary sends. */
CalcAngleCoeffs(chans[c].angle, chans[c].elevation, 0.0f, coeffs);
@@ -1104,9 +1105,10 @@ static void CalcAttnSourceParams(ALvoice *voice, const struct ALsourceProps *pro
spread = asinf(radius / Distance) * 2.0f;
/* Get the HRIR coefficients and delays. */
- GetHrtfCoeffs(Device->HrtfHandle, ev, az, spread, DryGain,
+ GetHrtfCoeffs(Device->HrtfHandle, ev, az, spread,
voice->Direct.Params[0].Hrtf.Target.Coeffs,
voice->Direct.Params[0].Hrtf.Target.Delay);
+ voice->Direct.Params[0].Hrtf.Target.Gain = DryGain;
CalcDirectionCoeffs(dir, spread, coeffs);
@@ -1502,9 +1504,11 @@ void aluMixData(ALCdevice *device, ALvoid *buffer, ALsizei size)
state = device->Hrtf;
for(c = 0;c < device->Dry.NumChannels;c++)
{
+ typedef ALfloat ALfloat2[2];
HrtfMix(device->RealOut.Buffer[lidx], device->RealOut.Buffer[ridx],
device->Dry.Buffer[c], state->Offset, state->IrSize,
- state->Chan[c].Coeffs, state->Chan[c].Values, SamplesToDo
+ SAFE_CONST(ALfloat2*,state->Chan[c].Coeffs),
+ state->Chan[c].Values, SamplesToDo
);
}
state->Offset += SamplesToDo;