From ad782c00007ae7a39352bb649a3cfb957fa2135d Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Tue, 25 Apr 2017 22:10:27 -0700 Subject: Skip mixing the fade out step when starting silent Unfortunately it can't skip mixing the fade in when going to silence because the history needs to be up to date. --- Alc/mixer.c | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) (limited to 'Alc') diff --git a/Alc/mixer.c b/Alc/mixer.c index 2070f859..39def41f 100644 --- a/Alc/mixer.c +++ b/Alc/mixer.c @@ -507,25 +507,32 @@ ALboolean MixSource(ALvoice *voice, ALsource *Source, ALCdevice *Device, ALsizei } else { - HrtfState backupstate = parms->Hrtf.State; ALfloat gain; /* The old coefficients need to fade to silence * completely since they'll be replaced after the mix. * So it needs to fade out over DstBufferSize instead * of Counter. + * + * Don't bother with the fade out when starting from + * silence. */ - hrtfparams.Coeffs = SAFE_CONST(ALfloat2*,parms->Hrtf.Old.Coeffs); - hrtfparams.Delay[0] = parms->Hrtf.Old.Delay[0]; - hrtfparams.Delay[1] = parms->Hrtf.Old.Delay[1]; - hrtfparams.Gain = parms->Hrtf.Old.Gain; - hrtfparams.GainStep = -hrtfparams.Gain / - (ALfloat)DstBufferSize; - MixHrtfSamples( - voice->Direct.Buffer[lidx], voice->Direct.Buffer[ridx], - samples, voice->Offset, OutPos, IrSize, &hrtfparams, - &backupstate, DstBufferSize - ); + if(parms->Hrtf.Old.Gain > GAIN_SILENCE_THRESHOLD) + { + HrtfState backupstate = parms->Hrtf.State; + + hrtfparams.Coeffs = SAFE_CONST(ALfloat2*,parms->Hrtf.Old.Coeffs); + hrtfparams.Delay[0] = parms->Hrtf.Old.Delay[0]; + hrtfparams.Delay[1] = parms->Hrtf.Old.Delay[1]; + hrtfparams.Gain = parms->Hrtf.Old.Gain; + hrtfparams.GainStep = -hrtfparams.Gain / + (ALfloat)DstBufferSize; + MixHrtfSamples( + voice->Direct.Buffer[lidx], voice->Direct.Buffer[ridx], + samples, voice->Offset, OutPos, IrSize, &hrtfparams, + &backupstate, DstBufferSize + ); + } /* The new coefficients need to fade in completely * since they're replacing the old ones. To keep the -- cgit v1.2.3