From 444e9563b357b4e2af0d428afac9f87596aba9a6 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Wed, 3 May 2017 03:29:21 -0700 Subject: Add a mixing function to blend HRIRs This is a bit more efficient than calling the normal HRTF mixing function twice, and helps solve the problem of the values generated from convolution not being consistent with the new HRIR. --- Alc/mixer.c | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) (limited to 'Alc/mixer.c') diff --git a/Alc/mixer.c b/Alc/mixer.c index a7adf9b6..6eaf4caf 100644 --- a/Alc/mixer.c +++ b/Alc/mixer.c @@ -53,6 +53,7 @@ enum Resampler ResamplerDefault = LinearResampler; static MixerFunc MixSamples = Mix_C; static HrtfMixerFunc MixHrtfSamples = MixHrtf_C; +HrtfMixerBlendFunc MixHrtfBlendSamples = MixHrtfBlend_C; MixerFunc SelectMixer(void) { @@ -90,10 +91,22 @@ static inline HrtfMixerFunc SelectHrtfMixer(void) if((CPUCapFlags&CPU_CAP_SSE)) return MixHrtf_SSE; #endif - return MixHrtf_C; } +static inline HrtfMixerBlendFunc SelectHrtfBlendMixer(void) +{ +#ifdef HAVE_NEON + if((CPUCapFlags&CPU_CAP_NEON)) + return MixHrtfBlend_Neon; +#endif +#ifdef HAVE_SSE + if((CPUCapFlags&CPU_CAP_SSE)) + return MixHrtfBlend_SSE; +#endif + return MixHrtfBlend_C; +} + ResamplerFunc SelectResampler(enum Resampler resampler) { switch(resampler) @@ -174,6 +187,7 @@ void aluInitMixer(void) } } + MixHrtfBlendSamples = SelectHrtfBlendMixer(); MixHrtfSamples = SelectHrtfMixer(); MixSamples = SelectMixer(); } @@ -511,25 +525,10 @@ ALboolean MixSource(ALvoice *voice, ALsource *Source, ALCdevice *Device, ALsizei } else if(firstpass) { - HrtfState backupstate = parms->Hrtf.State; ALfloat gain; /* Fade between the coefficients over 64 samples. */ - fademix = mini(DstBufferSize, 64); - - /* The old coefficients need to fade to silence - * completely since they'll be replaced after this mix. - */ - 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)fademix; - MixHrtfSamples( - voice->Direct.Buffer[lidx], voice->Direct.Buffer[ridx], - samples, voice->Offset, OutPos, IrSize, &hrtfparams, - &backupstate, fademix - ); + fademix = mini(DstBufferSize, 64); /* The new coefficients need to fade in completely * since they're replacing the old ones. To keep the @@ -544,10 +543,11 @@ ALboolean MixSource(ALvoice *voice, ALsource *Source, ALCdevice *Device, ALsizei hrtfparams.Delay[1] = parms->Hrtf.Target.Delay[1]; hrtfparams.Gain = 0.0f; hrtfparams.GainStep = gain / (ALfloat)fademix; - MixHrtfSamples( + + MixHrtfBlendSamples( voice->Direct.Buffer[lidx], voice->Direct.Buffer[ridx], - samples, voice->Offset, OutPos, IrSize, &hrtfparams, - &parms->Hrtf.State, fademix + samples, voice->Offset, OutPos, IrSize, &parms->Hrtf.Old, + &hrtfparams, &parms->Hrtf.State, fademix ); /* Update the old parameters with the result. */ parms->Hrtf.Old = parms->Hrtf.Target; -- cgit v1.2.3