aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2018-12-21 08:55:22 -0800
committerChris Robinson <[email protected]>2018-12-21 08:55:22 -0800
commit3553ce1f67d46573e338ff6e53a31d60a722d5c6 (patch)
treeb574ab621a47ee6163ef73e6c93af8f9a2e760dc
parentb785d805263c9517c1523785b2da39f9a47b6002 (diff)
Don't convert the HRTF decoder virtual speaker positions to radians
-rw-r--r--Alc/hrtf.cpp18
-rw-r--r--Alc/hrtf.h5
-rw-r--r--Alc/panning.cpp42
3 files changed, 32 insertions, 33 deletions
diff --git a/Alc/hrtf.cpp b/Alc/hrtf.cpp
index 5cc1e8b4..ab202e53 100644
--- a/Alc/hrtf.cpp
+++ b/Alc/hrtf.cpp
@@ -275,7 +275,7 @@ void GetHrtfCoeffs(const struct Hrtf *Hrtf, ALfloat elevation, ALfloat azimuth,
}
-void BuildBFormatHrtf(const struct Hrtf *Hrtf, DirectHrtfState *state, ALsizei NumChannels, const struct AngularPoint *AmbiPoints, const ALfloat (*RESTRICT AmbiMatrix)[MAX_AMBI_COEFFS], ALsizei AmbiCount, const ALfloat *RESTRICT AmbiOrderHFGain)
+void BuildBFormatHrtf(const struct Hrtf *Hrtf, DirectHrtfState *state, const ALsizei NumChannels, const AngularPoint *AmbiPoints, const ALfloat (*RESTRICT AmbiMatrix)[MAX_AMBI_COEFFS], const ALsizei AmbiCount, const ALfloat *RESTRICT AmbiOrderHFGain)
{
/* Set this to 2 for dual-band HRTF processing. May require a higher quality
* band-splitter, or better calculation of the new IR length to deal with the
@@ -287,19 +287,17 @@ void BuildBFormatHrtf(const struct Hrtf *Hrtf, DirectHrtfState *state, ALsizei N
al::vector<ALsizei> idx(AmbiCount);
for(ALsizei c{0};c < AmbiCount;c++)
{
- ALuint evidx, azidx;
- ALuint evoffset;
- ALuint azcount;
-
/* Calculate elevation index. */
- evidx = (ALsizei)((F_PI_2+AmbiPoints[c].Elev) * (Hrtf->evCount-1) / F_PI + 0.5f);
- evidx = clampi(evidx, 0, Hrtf->evCount-1);
+ const auto evidx = clampi(
+ static_cast<ALsizei>((90.0f+AmbiPoints[c].Elev)*(Hrtf->evCount-1)/180.0f + 0.5f),
+ 0, Hrtf->evCount-1);
- azcount = Hrtf->azCount[evidx];
- evoffset = Hrtf->evOffset[evidx];
+ const ALsizei azcount{Hrtf->azCount[evidx]};
+ const ALsizei evoffset{Hrtf->evOffset[evidx]};
/* Calculate azimuth index for this elevation. */
- azidx = (ALsizei)((F_TAU+AmbiPoints[c].Azim) * azcount / F_TAU + 0.5f) % azcount;
+ const auto azidx = static_cast<ALsizei>(
+ (360.0f+AmbiPoints[c].Azim)*azcount/360.0f + 0.5f) % azcount;
/* Calculate indices for left and right channels. */
idx[c] = evoffset + azidx;
diff --git a/Alc/hrtf.h b/Alc/hrtf.h
index b814c282..756795c9 100644
--- a/Alc/hrtf.h
+++ b/Alc/hrtf.h
@@ -79,8 +79,9 @@ void GetHrtfCoeffs(const struct Hrtf *Hrtf, ALfloat elevation, ALfloat azimuth,
* Produces HRTF filter coefficients for decoding B-Format, given a set of
* virtual speaker positions, a matching decoding matrix, and per-order high-
* frequency gains for the decoder. The calculated impulse responses are
- * ordered and scaled according to the matrix input.
+ * ordered and scaled according to the matrix input. Note the specified virtual
+ * positions should be in degrees, not radians!
*/
-void BuildBFormatHrtf(const struct Hrtf *Hrtf, DirectHrtfState *state, ALsizei NumChannels, const struct AngularPoint *AmbiPoints, const ALfloat (*RESTRICT AmbiMatrix)[MAX_AMBI_COEFFS], ALsizei AmbiCount, const ALfloat *RESTRICT AmbiOrderHFGain);
+void BuildBFormatHrtf(const struct Hrtf *Hrtf, DirectHrtfState *state, const ALsizei NumChannels, const AngularPoint *AmbiPoints, const ALfloat (*RESTRICT AmbiMatrix)[MAX_AMBI_COEFFS], const ALsizei AmbiCount, const ALfloat *RESTRICT AmbiOrderHFGain);
#endif /* ALC_HRTF_H */
diff --git a/Alc/panning.cpp b/Alc/panning.cpp
index 9c3be106..e4a9d787 100644
--- a/Alc/panning.cpp
+++ b/Alc/panning.cpp
@@ -617,28 +617,28 @@ void InitHQPanning(ALCdevice *device, const AmbDecConf *conf, const ALsizei (&sp
void InitHrtfPanning(ALCdevice *device)
{
- /* NOTE: azimuth goes clockwise. */
+ /* NOTE: In degrees, and azimuth goes clockwise. */
static constexpr AngularPoint AmbiPoints[]{
- { DEG2RAD( 35.264390f), DEG2RAD( -45.000000f) },
- { DEG2RAD( 35.264390f), DEG2RAD( 45.000000f) },
- { DEG2RAD( 35.264390f), DEG2RAD( 135.000000f) },
- { DEG2RAD( 35.264390f), DEG2RAD(-135.000000f) },
- { DEG2RAD(-35.264390f), DEG2RAD( -45.000000f) },
- { DEG2RAD(-35.264390f), DEG2RAD( 45.000000f) },
- { DEG2RAD(-35.264390f), DEG2RAD( 135.000000f) },
- { DEG2RAD(-35.264390f), DEG2RAD(-135.000000f) },
- { DEG2RAD( 0.000000f), DEG2RAD( -20.905157f) },
- { DEG2RAD( 0.000000f), DEG2RAD( 20.905157f) },
- { DEG2RAD( 0.000000f), DEG2RAD( 159.094843f) },
- { DEG2RAD( 0.000000f), DEG2RAD(-159.094843f) },
- { DEG2RAD( 20.905157f), DEG2RAD( -90.000000f) },
- { DEG2RAD(-20.905157f), DEG2RAD( -90.000000f) },
- { DEG2RAD(-20.905157f), DEG2RAD( 90.000000f) },
- { DEG2RAD( 20.905157f), DEG2RAD( 90.000000f) },
- { DEG2RAD( 69.094843f), DEG2RAD( 0.000000f) },
- { DEG2RAD(-69.094843f), DEG2RAD( 0.000000f) },
- { DEG2RAD(-69.094843f), DEG2RAD( 180.000000f) },
- { DEG2RAD( 69.094843f), DEG2RAD( 180.000000f) },
+ { 35.264390f, -45.000000f },
+ { 35.264390f, 45.000000f },
+ { 35.264390f, 135.000000f },
+ { 35.264390f, -135.000000f },
+ { -35.264390f, -45.000000f },
+ { -35.264390f, 45.000000f },
+ { -35.264390f, 135.000000f },
+ { -35.264390f, -135.000000f },
+ { 0.000000f, -20.905157f },
+ { 0.000000f, 20.905157f },
+ { 0.000000f, 159.094843f },
+ { 0.000000f, -159.094843f },
+ { 20.905157f, -90.000000f },
+ { -20.905157f, -90.000000f },
+ { -20.905157f, 90.000000f },
+ { 20.905157f, 90.000000f },
+ { 69.094843f, 0.000000f },
+ { -69.094843f, 0.000000f },
+ { -69.094843f, 180.000000f },
+ { 69.094843f, 180.000000f },
};
static constexpr ALfloat AmbiMatrix[][MAX_AMBI_COEFFS]{
{ 5.00000000e-02f, 5.00000000e-02f, 5.00000000e-02f, 5.00000000e-02f, 6.45497224e-02f, 6.45497224e-02f, 0.00000000e+00f, 6.45497224e-02f, 0.00000000e+00f, 1.48264644e-02f, 6.33865691e-02f, 1.01126676e-01f, -7.36485380e-02f, -1.09260065e-02f, 7.08683387e-02f, -1.01622099e-01f },