From 12999f9efe756874bb35b67085ca6cbbcb7c6105 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Thu, 14 Mar 2019 22:26:19 -0700 Subject: Simplify calculating azimuth and elevation indices for HRTF --- Alc/hrtf.cpp | 24 +++++++----------------- Alc/hrtf.h | 2 +- 2 files changed, 8 insertions(+), 18 deletions(-) (limited to 'Alc') diff --git a/Alc/hrtf.cpp b/Alc/hrtf.cpp index 94307f04..f71f6fc5 100644 --- a/Alc/hrtf.cpp +++ b/Alc/hrtf.cpp @@ -208,7 +208,7 @@ IdxBlend CalcAzIndex(ALsizei azcount, ALfloat az) * and azimuth in radians. The coefficients are normalized. */ void GetHrtfCoeffs(const HrtfEntry *Hrtf, ALfloat elevation, ALfloat azimuth, ALfloat distance, - ALfloat spread, HrirArray &coeffs, ALsizei *delays) + ALfloat spread, HrirArray &coeffs, ALsizei (&delays)[2]) { const ALfloat dirfact{1.0f - (spread / al::MathDefs::Tau())}; @@ -222,25 +222,15 @@ void GetHrtfCoeffs(const HrtfEntry *Hrtf, ALfloat elevation, ALfloat azimuth, AL } assert(fdoffset >= 0); - /* Claculate the lower elevation index. */ + /* Claculate the elevation indinces. */ const auto elev0 = CalcEvIndex(field->evCount, elevation); - ALsizei elev1_idx{elev0.idx}; - ALsizei ev0offset{Hrtf->evOffset[fdoffset + elev0.idx]}; - ALsizei ev1offset{ev0offset}; + const ALsizei elev1_idx{mini(elev0.idx+1, field->evCount-1)}; + const ALsizei ev0offset{Hrtf->evOffset[fdoffset + elev0.idx]}; + const ALsizei ev1offset{Hrtf->evOffset[fdoffset + elev1_idx]}; - /* Calculate lower azimuth index. */ + /* Calculate azimuth indices. */ const auto az0 = CalcAzIndex(Hrtf->azCount[fdoffset + elev0.idx], azimuth); - auto az1 = az0; - - if(LIKELY(elev0.idx+1 < field->evCount)) - { - /* Increment elevation to the next (upper) index. */ - elev1_idx = elev0.idx+1; - ev1offset = Hrtf->evOffset[fdoffset + elev1_idx]; - - /* Calculate upper azimuth index. */ - az1 = CalcAzIndex(Hrtf->azCount[fdoffset + elev1_idx], azimuth); - } + const auto az1 = CalcAzIndex(Hrtf->azCount[fdoffset + elev1_idx], azimuth); /* Calculate the HRIR indices to blend. */ ALsizei idx[4]{ diff --git a/Alc/hrtf.h b/Alc/hrtf.h index 9a6dc61e..b3063dd9 100644 --- a/Alc/hrtf.h +++ b/Alc/hrtf.h @@ -105,7 +105,7 @@ al::vector EnumerateHrtf(const char *devname); HrtfEntry *GetLoadedHrtf(HrtfHandle *handle); void GetHrtfCoeffs(const HrtfEntry *Hrtf, ALfloat elevation, ALfloat azimuth, ALfloat distance, - ALfloat spread, HrirArray &coeffs, ALsizei *delays); + ALfloat spread, HrirArray &coeffs, ALsizei (&delays)[2]); /** * Produces HRTF filter coefficients for decoding B-Format, given a set of -- cgit v1.2.3