diff options
author | Chris Robinson <[email protected]> | 2019-01-28 22:07:03 -0800 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2019-01-28 22:22:34 -0800 |
commit | 4c740636c258265162ef6729b5255f67b43205e4 (patch) | |
tree | 1ca636d2362f293ea08bb1c0b8593f02defe2215 /Alc | |
parent | 2d93a9cdb176d0958cd78979794a9acc35de0725 (diff) |
Pass the distance to GetHrtfCoeffs
Diffstat (limited to 'Alc')
-rw-r--r-- | Alc/alu.cpp | 19 | ||||
-rw-r--r-- | Alc/hrtf.cpp | 26 | ||||
-rw-r--r-- | Alc/hrtf.h | 2 |
3 files changed, 25 insertions, 22 deletions
diff --git a/Alc/alu.cpp b/Alc/alu.cpp index 7b2b61ca..5742a925 100644 --- a/Alc/alu.cpp +++ b/Alc/alu.cpp @@ -617,8 +617,7 @@ void CalcPanningAndFilters(ALvoice *voice, const ALfloat Azi, const ALfloat Elev /* Clamp the distance for really close sources, to prevent * excessive bass. */ - const ALfloat mdist{maxf(Distance*Listener.Params.MetersPerUnit, - Device->AvgSpeakerDist/4.0f)}; + const ALfloat mdist{maxf(Distance, Device->AvgSpeakerDist/4.0f)}; const ALfloat w0{SPEEDOFSOUNDMETRESPERSEC / (mdist * static_cast<ALfloat>(Device->Frequency))}; @@ -765,7 +764,7 @@ void CalcPanningAndFilters(ALvoice *voice, const ALfloat Azi, const ALfloat Elev /* Get the HRIR coefficients and delays just once, for the given * source direction. */ - GetHrtfCoeffs(Device->mHrtf, Elev, Azi, Spread, + GetHrtfCoeffs(Device->mHrtf, Elev, Azi, Distance, Spread, voice->Direct.Params[0].Hrtf.Target.Coeffs, voice->Direct.Params[0].Hrtf.Target.Delay); voice->Direct.Params[0].Hrtf.Target.Gain = DryGain * downmix_gain; @@ -812,10 +811,10 @@ void CalcPanningAndFilters(ALvoice *voice, const ALfloat Azi, const ALfloat Elev /* Get the HRIR coefficients and delays for this channel * position. */ - GetHrtfCoeffs(Device->mHrtf, chans[c].elevation, chans[c].angle, Spread, + GetHrtfCoeffs(Device->mHrtf, chans[c].elevation, chans[c].angle, + std::numeric_limits<float>::infinity(), Spread, voice->Direct.Params[c].Hrtf.Target.Coeffs, - voice->Direct.Params[c].Hrtf.Target.Delay - ); + voice->Direct.Params[c].Hrtf.Target.Delay); voice->Direct.Params[c].Hrtf.Target.Gain = DryGain; /* Normal panning for auxiliary sends. */ @@ -846,8 +845,7 @@ void CalcPanningAndFilters(ALvoice *voice, const ALfloat Azi, const ALfloat Elev /* Clamp the distance for really close sources, to prevent * excessive bass. */ - const ALfloat mdist{maxf(Distance*Listener.Params.MetersPerUnit, - Device->AvgSpeakerDist/4.0f)}; + const ALfloat mdist{maxf(Distance, Device->AvgSpeakerDist/4.0f)}; const ALfloat w0{SPEEDOFSOUNDMETRESPERSEC / (mdist * static_cast<ALfloat>(Device->Frequency))}; @@ -1394,8 +1392,9 @@ void CalcAttnSourceParams(ALvoice *voice, const ALvoicePropsBase *props, const A else if(Distance > 0.0f) spread = std::asin(props->Radius/Distance) * 2.0f; - CalcPanningAndFilters(voice, az, ev, Distance, spread, DryGain, DryGainHF, DryGainLF, WetGain, - WetGainLF, WetGainHF, SendSlots, ALBuffer, props, Listener, Device); + CalcPanningAndFilters(voice, az, ev, Distance*Listener.Params.MetersPerUnit, spread, DryGain, + DryGainHF, DryGainLF, WetGain, WetGainLF, WetGainHF, SendSlots, ALBuffer, props, Listener, + Device); } void CalcSourceParams(ALvoice *voice, ALCcontext *context, bool force) diff --git a/Alc/hrtf.cpp b/Alc/hrtf.cpp index 21689706..173b11d8 100644 --- a/Alc/hrtf.cpp +++ b/Alc/hrtf.cpp @@ -202,38 +202,42 @@ IdxBlend CalcAzIndex(ALsizei azcount, ALfloat az) /* Calculates static HRIR coefficients and delays for the given polar elevation * and azimuth in radians. The coefficients are normalized. */ -void GetHrtfCoeffs(const HrtfEntry *Hrtf, ALfloat elevation, ALfloat azimuth, ALfloat spread, - ALfloat (*RESTRICT coeffs)[2], ALsizei *delays) +void GetHrtfCoeffs(const HrtfEntry *Hrtf, ALfloat elevation, ALfloat azimuth, ALfloat distance, + ALfloat spread, ALfloat (*RESTRICT coeffs)[2], ALsizei *delays) { const ALfloat dirfact{1.0f - (spread / al::MathDefs<float>::Tau())}; - const auto &field = Hrtf->field[0]; + const auto *field = Hrtf->field; + const auto *field_end = field + Hrtf->fdCount-1; + ALsizei fdoffset{0}; + for(;field != field_end && (field+1)->distance <= distance;++field) + fdoffset += field->evCount; /* Claculate the lower elevation index. */ - const auto elev = CalcEvIndex(field.evCount, elevation); - ALsizei ev0offset{Hrtf->evOffset[elev.idx]}; + const auto elev = CalcEvIndex(field->evCount, elevation); + ALsizei ev0offset{Hrtf->evOffset[fdoffset + elev.idx]}; ALsizei ev1offset{ev0offset}; /* Calculate lower azimuth index. */ - const auto az0 = CalcAzIndex(Hrtf->azCount[elev.idx], azimuth); + const auto az0 = CalcAzIndex(Hrtf->azCount[fdoffset + elev.idx], azimuth); auto az1 = az0; - if(LIKELY(elev.idx < field.evCount-1)) + if(LIKELY(elev.idx < field->evCount-1)) { /* Increment elevation to the next (upper) index. */ ALsizei evidx{elev.idx+1}; - ev1offset = Hrtf->evOffset[evidx]; + ev1offset = Hrtf->evOffset[fdoffset + evidx]; /* Calculate upper azimuth index. */ - az1 = CalcAzIndex(Hrtf->azCount[evidx], azimuth); + az1 = CalcAzIndex(Hrtf->azCount[fdoffset + evidx], azimuth); } /* Calculate the HRIR indices to blend. */ ALsizei idx[4]{ ev0offset + az0.idx, - ev0offset + ((az0.idx+1) % Hrtf->azCount[elev.idx]), + ev0offset + ((az0.idx+1) % Hrtf->azCount[fdoffset + elev.idx]), ev1offset + az1.idx, - ev1offset + ((az1.idx+1) % Hrtf->azCount[elev.idx]) + ev1offset + ((az1.idx+1) % Hrtf->azCount[fdoffset + elev.idx]) }; /* Calculate bilinear blending weights, attenuated according to the @@ -95,7 +95,7 @@ struct AngularPoint { al::vector<EnumeratedHrtf> EnumerateHrtf(const char *devname); HrtfEntry *GetLoadedHrtf(HrtfHandle *handle); -void GetHrtfCoeffs(const HrtfEntry *Hrtf, ALfloat elevation, ALfloat azimuth, ALfloat spread, ALfloat (*RESTRICT coeffs)[2], ALsizei *delays); +void GetHrtfCoeffs(const HrtfEntry *Hrtf, ALfloat elevation, ALfloat azimuth, ALfloat distance, ALfloat spread, ALfloat (*RESTRICT coeffs)[2], ALsizei *delays); /** * Produces HRTF filter coefficients for decoding B-Format, given a set of |