Skip to content

Commit

Permalink
Improve ambisonic rotator coefficient accuracy
Browse files Browse the repository at this point in the history
  • Loading branch information
kcat committed Oct 3, 2023
1 parent 32b89db commit 340a22b
Showing 1 changed file with 38 additions and 17 deletions.
55 changes: 38 additions & 17 deletions alc/alu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -627,17 +627,38 @@ struct RotatorCoeffs {
{
for(int m{-l};m <= l;++m)
{
// compute u,v,w terms of Eq.8.1 (Table I)
const bool d{m == 0}; // the delta function d_m0
const float denom{static_cast<float>((std::abs(n) == l) ?
(2*l) * (2*l - 1) : (l*l - n*n))};

const int abs_m{std::abs(m)};
coeffs->u = std::sqrt(static_cast<float>(l*l - m*m)/denom);
coeffs->v = std::sqrt(static_cast<float>(l+abs_m-1) *
static_cast<float>(l+abs_m) / denom) * (1.0f+d) * (1.0f - 2.0f*d) * 0.5f;
coeffs->w = std::sqrt(static_cast<float>(l-abs_m-1) *
static_cast<float>(l-abs_m) / denom) * (1.0f-d) * -0.5f;
/* compute u,v,w terms of Eq.8.1 (Table I)
*
* const bool d{m == 0}; // the delta function d_m0
* const double denom{(std::abs(n) == l) ?
* (2*l) * (2*l - 1) : (l*l - n*n)};
*
* const int abs_m{std::abs(m)};
* coeffs->u = std::sqrt((l*l - m*m) / denom);
* coeffs->v = std::sqrt((l+abs_m-1) * (l+abs_m) / denom) *
* (1.0+d) * (1.0 - 2.0*d) * 0.5;
* coeffs->w = std::sqrt((l-abs_m-1) * (l-abs_m) / denom) *
* (1.0-d) * -0.5;
*/

const double denom{static_cast<double>((std::abs(n) == l) ?
(2*l) * (2*l - 1) : (l*l - n*n))};

if(m == 0)
{
coeffs->u = static_cast<float>(std::sqrt(l * l / denom));
coeffs->v = static_cast<float>(std::sqrt((l-1) * l / denom) * -1.0);
coeffs->w = 0.0f;
}
else
{
const int abs_m{std::abs(m)};
coeffs->u = static_cast<float>(std::sqrt((l*l - m*m) / denom));
coeffs->v = static_cast<float>(std::sqrt((l+abs_m-1) * (l+abs_m) / denom) *
0.5);
coeffs->w = static_cast<float>(std::sqrt((l-abs_m-1) * (l-abs_m) / denom) *
-0.5);
}
++coeffs;
}
}
Expand Down Expand Up @@ -721,12 +742,12 @@ void AmbiRotator(AmbiRotateMatrix &matrix, const int order)
float r{0.0f};

// computes Eq.8.1
const float u{coeffs->u};
if(u != 0.0f) r += u * U(l, m, n, last_band, matrix);
const float v{coeffs->v};
if(v != 0.0f) r += v * V(l, m, n, last_band, matrix);
const float w{coeffs->w};
if(w != 0.0f) r += w * W(l, m, n, last_band, matrix);
if(const float u{coeffs->u}; u != 0.0f)
r += u * U(l, m, n, last_band, matrix);
if(const float v{coeffs->v}; v != 0.0f)
r += v * V(l, m, n, last_band, matrix);
if(const float w{coeffs->w}; w != 0.0f)
r += w * W(l, m, n, last_band, matrix);

matrix[y][x] = r;
++coeffs;
Expand Down

0 comments on commit 340a22b

Please sign in to comment.