diff options
author | Chris Robinson <[email protected]> | 2016-08-18 23:33:08 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2016-08-18 23:33:08 -0700 |
commit | d16954c34ebb4bfbd4e7ef27090b01d6f4ff9261 (patch) | |
tree | 75222d2dc3b8b7d2ee1ca29f23a4a6e6d14d4ce8 | |
parent | e13c6bca207d5a7659fca03a9576bcab6ea7728e (diff) |
Fix HRTF index calculations for B-Format coefficients
The CalcEvIndices and CalcAzIndices methods were dependent on the FPU being in
round-to-zero mode, which is not the case for panning initialization. And since
we just need the closest index and don't need to lerp between them, it's better
to just directly calculate the index with rounding.
-rw-r--r-- | Alc/hrtf.c | 21 |
1 files changed, 10 insertions, 11 deletions
@@ -206,26 +206,25 @@ ALuint BuildBFormatHrtf(const struct Hrtf *Hrtf, ALfloat (*coeffs)[HRIR_LENGTH][ for(c = 0;c < 8;c++) { - ALuint evidx[2]; + ALuint evidx, azidx; ALuint evoffset; - ALuint azidx[2]; ALuint azcount; - ALfloat mu; /* Calculate elevation index. */ - CalcEvIndices(Hrtf->evCount, CubePoints[c].elevation, evidx, &mu); - if(mu >= 0.5f) evidx[0] = evidx[1]; + evidx = (ALuint)floorf((F_PI_2 + CubePoints[c].elevation) * + (Hrtf->evCount-1)/F_PI + 0.5f); + evidx = minu(evidx, Hrtf->evCount-1); - azcount = Hrtf->azCount[evidx[0]]; - evoffset = Hrtf->evOffset[evidx[0]]; + azcount = Hrtf->azCount[evidx]; + evoffset = Hrtf->evOffset[evidx]; /* Calculate azimuth index for this elevation. */ - CalcAzIndices(azcount, CubePoints[c].azimuth, azidx, &mu); - if(mu >= 0.5f) azidx[0] = azidx[1]; + azidx = (ALuint)floorf((F_TAU+CubePoints[c].azimuth) * + azcount/F_TAU + 0.5f) % azcount; /* Calculate indices for left and right channels. */ - lidx[c] = evoffset + azidx[0]; - ridx[c] = evoffset + ((azcount-azidx[0]) % azcount); + lidx[c] = evoffset + azidx; + ridx[c] = evoffset + ((azcount-azidx) % azcount); min_delay = minu(min_delay, minu(Hrtf->delays[lidx[c]], Hrtf->delays[ridx[c]])); } |