11 using AmbiChannelFloatArray
= std::array
<float,MaxAmbiChannels
>;
13 constexpr auto inv_sqrt2f
= static_cast<float>(1.0/al::numbers::sqrt2
);
14 constexpr auto inv_sqrt3f
= static_cast<float>(1.0/al::numbers::sqrt3
);
17 /* These HF gains are derived from the same 32-point speaker array. The scale
18 * factor between orders represents the same scale factors for any (regular)
19 * speaker array decoder. e.g. Given a first-order source and second-order
20 * output, applying an HF scale of HFScales[1][0] / HFScales[2][0] to channel 0
21 * will result in that channel being subsequently decoded for second-order as
22 * if it was a first-order decoder for that same speaker array.
24 constexpr std::array
<std::array
<float,MaxAmbiOrder
+1>,MaxAmbiOrder
+1> HFScales
{{
25 {{ 4.000000000e+00f
, 2.309401077e+00f
, 1.192569588e+00f
, 7.189495850e-01f
}},
26 {{ 4.000000000e+00f
, 2.309401077e+00f
, 1.192569588e+00f
, 7.189495850e-01f
}},
27 {{ 2.981423970e+00f
, 2.309401077e+00f
, 1.192569588e+00f
, 7.189495850e-01f
}},
28 {{ 2.359168820e+00f
, 2.031565936e+00f
, 1.444598386e+00f
, 7.189495850e-01f
}},
29 /* 1.947005434e+00f, 1.764337084e+00f, 1.424707344e+00f, 9.755104127e-01f, 4.784482742e-01f */
32 /* Same as above, but using a 10-point horizontal-only speaker array. Should
33 * only be used when the device is mixing in 2D B-Format for horizontal-only
36 constexpr std::array
<std::array
<float,MaxAmbiOrder
+1>,MaxAmbiOrder
+1> HFScales2D
{{
37 {{ 2.236067977e+00f
, 1.581138830e+00f
, 9.128709292e-01f
, 6.050756345e-01f
}},
38 {{ 2.236067977e+00f
, 1.581138830e+00f
, 9.128709292e-01f
, 6.050756345e-01f
}},
39 {{ 1.825741858e+00f
, 1.581138830e+00f
, 9.128709292e-01f
, 6.050756345e-01f
}},
40 {{ 1.581138830e+00f
, 1.460781803e+00f
, 1.118033989e+00f
, 6.050756345e-01f
}},
41 /* 1.414213562e+00f, 1.344997024e+00f, 1.144122806e+00f, 8.312538756e-01f, 4.370160244e-01f */
45 /* This calculates a first-order "upsampler" matrix. It combines a first-order
46 * decoder matrix with a max-order encoder matrix, creating a matrix that
47 * behaves as if the B-Format input signal is first decoded to a speaker array
48 * at first-order, then those speaker feeds are encoded to a higher-order
49 * signal. While not perfect, this should accurately encode a lower-order
50 * signal into a higher-order signal.
52 constexpr std::array
<std::array
<float,4>,8> FirstOrderDecoder
{{
53 {{ 1.250000000e-01f
, 1.250000000e-01f
, 1.250000000e-01f
, 1.250000000e-01f
, }},
54 {{ 1.250000000e-01f
, 1.250000000e-01f
, 1.250000000e-01f
, -1.250000000e-01f
, }},
55 {{ 1.250000000e-01f
, -1.250000000e-01f
, 1.250000000e-01f
, 1.250000000e-01f
, }},
56 {{ 1.250000000e-01f
, -1.250000000e-01f
, 1.250000000e-01f
, -1.250000000e-01f
, }},
57 {{ 1.250000000e-01f
, 1.250000000e-01f
, -1.250000000e-01f
, 1.250000000e-01f
, }},
58 {{ 1.250000000e-01f
, 1.250000000e-01f
, -1.250000000e-01f
, -1.250000000e-01f
, }},
59 {{ 1.250000000e-01f
, -1.250000000e-01f
, -1.250000000e-01f
, 1.250000000e-01f
, }},
60 {{ 1.250000000e-01f
, -1.250000000e-01f
, -1.250000000e-01f
, -1.250000000e-01f
, }},
62 constexpr std::array
<AmbiChannelFloatArray
,8> FirstOrderEncoder
{{
63 CalcAmbiCoeffs( inv_sqrt3f
, inv_sqrt3f
, inv_sqrt3f
),
64 CalcAmbiCoeffs( inv_sqrt3f
, inv_sqrt3f
, -inv_sqrt3f
),
65 CalcAmbiCoeffs(-inv_sqrt3f
, inv_sqrt3f
, inv_sqrt3f
),
66 CalcAmbiCoeffs(-inv_sqrt3f
, inv_sqrt3f
, -inv_sqrt3f
),
67 CalcAmbiCoeffs( inv_sqrt3f
, -inv_sqrt3f
, inv_sqrt3f
),
68 CalcAmbiCoeffs( inv_sqrt3f
, -inv_sqrt3f
, -inv_sqrt3f
),
69 CalcAmbiCoeffs(-inv_sqrt3f
, -inv_sqrt3f
, inv_sqrt3f
),
70 CalcAmbiCoeffs(-inv_sqrt3f
, -inv_sqrt3f
, -inv_sqrt3f
),
72 static_assert(FirstOrderDecoder
.size() == FirstOrderEncoder
.size(), "First-order mismatch");
74 auto CalcFirstOrderUp()
76 std::array
<AmbiChannelFloatArray
,4> res
{};
78 for(size_t i
{0};i
< FirstOrderDecoder
[0].size();++i
)
80 for(size_t j
{0};j
< FirstOrderEncoder
[0].size();++j
)
83 for(size_t k
{0};k
< FirstOrderDecoder
.size();++k
)
84 sum
+= double{FirstOrderDecoder
[k
][i
]} * FirstOrderEncoder
[k
][j
];
85 res
[i
][j
] = static_cast<float>(sum
);
93 /* This calculates a 2D first-order "upsampler" matrix. Same as the first-order
94 * matrix, just using a more optimized speaker array for horizontal-only
97 constexpr std::array
<std::array
<float,4>,4> FirstOrder2DDecoder
{{
98 {{ 2.500000000e-01f
, 2.041241452e-01f
, 0.0f
, 2.041241452e-01f
, }},
99 {{ 2.500000000e-01f
, 2.041241452e-01f
, 0.0f
, -2.041241452e-01f
, }},
100 {{ 2.500000000e-01f
, -2.041241452e-01f
, 0.0f
, 2.041241452e-01f
, }},
101 {{ 2.500000000e-01f
, -2.041241452e-01f
, 0.0f
, -2.041241452e-01f
, }},
103 constexpr std::array
<AmbiChannelFloatArray
,4> FirstOrder2DEncoder
{{
104 CalcAmbiCoeffs( inv_sqrt2f
, 0.0f
, inv_sqrt2f
),
105 CalcAmbiCoeffs( inv_sqrt2f
, 0.0f
, -inv_sqrt2f
),
106 CalcAmbiCoeffs(-inv_sqrt2f
, 0.0f
, inv_sqrt2f
),
107 CalcAmbiCoeffs(-inv_sqrt2f
, 0.0f
, -inv_sqrt2f
),
109 static_assert(FirstOrder2DDecoder
.size() == FirstOrder2DEncoder
.size(), "First-order 2D mismatch");
111 auto CalcFirstOrder2DUp()
113 std::array
<AmbiChannelFloatArray
,4> res
{};
115 for(size_t i
{0};i
< FirstOrder2DDecoder
[0].size();++i
)
117 for(size_t j
{0};j
< FirstOrder2DEncoder
[0].size();++j
)
120 for(size_t k
{0};k
< FirstOrder2DDecoder
.size();++k
)
121 sum
+= double{FirstOrder2DDecoder
[k
][i
]} * FirstOrder2DEncoder
[k
][j
];
122 res
[i
][j
] = static_cast<float>(sum
);
130 /* This calculates a second-order "upsampler" matrix. Same as the first-order
131 * matrix, just using a slightly more dense speaker array suitable for second-
134 constexpr std::array
<std::array
<float,9>,12> SecondOrderDecoder
{{
135 {{ 8.333333333e-02f
, 0.000000000e+00f
, -7.588274978e-02f
, 1.227808683e-01f
, 0.000000000e+00f
, 0.000000000e+00f
, -1.591525047e-02f
, -1.443375673e-01f
, 1.167715449e-01f
, }},
136 {{ 8.333333333e-02f
, -1.227808683e-01f
, 0.000000000e+00f
, 7.588274978e-02f
, -1.443375673e-01f
, 0.000000000e+00f
, -9.316949906e-02f
, 0.000000000e+00f
, -7.216878365e-02f
, }},
137 {{ 8.333333333e-02f
, -7.588274978e-02f
, 1.227808683e-01f
, 0.000000000e+00f
, 0.000000000e+00f
, -1.443375673e-01f
, 1.090847495e-01f
, 0.000000000e+00f
, -4.460276122e-02f
, }},
138 {{ 8.333333333e-02f
, 0.000000000e+00f
, 7.588274978e-02f
, 1.227808683e-01f
, 0.000000000e+00f
, 0.000000000e+00f
, -1.591525047e-02f
, 1.443375673e-01f
, 1.167715449e-01f
, }},
139 {{ 8.333333333e-02f
, -1.227808683e-01f
, 0.000000000e+00f
, -7.588274978e-02f
, 1.443375673e-01f
, 0.000000000e+00f
, -9.316949906e-02f
, 0.000000000e+00f
, -7.216878365e-02f
, }},
140 {{ 8.333333333e-02f
, 7.588274978e-02f
, -1.227808683e-01f
, 0.000000000e+00f
, 0.000000000e+00f
, -1.443375673e-01f
, 1.090847495e-01f
, 0.000000000e+00f
, -4.460276122e-02f
, }},
141 {{ 8.333333333e-02f
, 0.000000000e+00f
, -7.588274978e-02f
, -1.227808683e-01f
, 0.000000000e+00f
, 0.000000000e+00f
, -1.591525047e-02f
, 1.443375673e-01f
, 1.167715449e-01f
, }},
142 {{ 8.333333333e-02f
, 1.227808683e-01f
, 0.000000000e+00f
, -7.588274978e-02f
, -1.443375673e-01f
, 0.000000000e+00f
, -9.316949906e-02f
, 0.000000000e+00f
, -7.216878365e-02f
, }},
143 {{ 8.333333333e-02f
, 7.588274978e-02f
, 1.227808683e-01f
, 0.000000000e+00f
, 0.000000000e+00f
, 1.443375673e-01f
, 1.090847495e-01f
, 0.000000000e+00f
, -4.460276122e-02f
, }},
144 {{ 8.333333333e-02f
, 0.000000000e+00f
, 7.588274978e-02f
, -1.227808683e-01f
, 0.000000000e+00f
, 0.000000000e+00f
, -1.591525047e-02f
, -1.443375673e-01f
, 1.167715449e-01f
, }},
145 {{ 8.333333333e-02f
, 1.227808683e-01f
, 0.000000000e+00f
, 7.588274978e-02f
, 1.443375673e-01f
, 0.000000000e+00f
, -9.316949906e-02f
, 0.000000000e+00f
, -7.216878365e-02f
, }},
146 {{ 8.333333333e-02f
, -7.588274978e-02f
, -1.227808683e-01f
, 0.000000000e+00f
, 0.000000000e+00f
, 1.443375673e-01f
, 1.090847495e-01f
, 0.000000000e+00f
, -4.460276122e-02f
, }},
148 constexpr std::array
<AmbiChannelFloatArray
,12> SecondOrderEncoder
{{
149 CalcAmbiCoeffs( 0.000000000e+00f
, -5.257311121e-01f
, 8.506508084e-01f
),
150 CalcAmbiCoeffs(-8.506508084e-01f
, 0.000000000e+00f
, 5.257311121e-01f
),
151 CalcAmbiCoeffs(-5.257311121e-01f
, 8.506508084e-01f
, 0.000000000e+00f
),
152 CalcAmbiCoeffs( 0.000000000e+00f
, 5.257311121e-01f
, 8.506508084e-01f
),
153 CalcAmbiCoeffs(-8.506508084e-01f
, 0.000000000e+00f
, -5.257311121e-01f
),
154 CalcAmbiCoeffs( 5.257311121e-01f
, -8.506508084e-01f
, 0.000000000e+00f
),
155 CalcAmbiCoeffs( 0.000000000e+00f
, -5.257311121e-01f
, -8.506508084e-01f
),
156 CalcAmbiCoeffs( 8.506508084e-01f
, 0.000000000e+00f
, -5.257311121e-01f
),
157 CalcAmbiCoeffs( 5.257311121e-01f
, 8.506508084e-01f
, 0.000000000e+00f
),
158 CalcAmbiCoeffs( 0.000000000e+00f
, 5.257311121e-01f
, -8.506508084e-01f
),
159 CalcAmbiCoeffs( 8.506508084e-01f
, 0.000000000e+00f
, 5.257311121e-01f
),
160 CalcAmbiCoeffs(-5.257311121e-01f
, -8.506508084e-01f
, 0.000000000e+00f
),
162 static_assert(SecondOrderDecoder
.size() == SecondOrderEncoder
.size(), "Second-order mismatch");
164 auto CalcSecondOrderUp()
166 std::array
<AmbiChannelFloatArray
,9> res
{};
168 for(size_t i
{0};i
< SecondOrderDecoder
[0].size();++i
)
170 for(size_t j
{0};j
< SecondOrderEncoder
[0].size();++j
)
173 for(size_t k
{0};k
< SecondOrderDecoder
.size();++k
)
174 sum
+= double{SecondOrderDecoder
[k
][i
]} * SecondOrderEncoder
[k
][j
];
175 res
[i
][j
] = static_cast<float>(sum
);
183 /* This calculates a 2D second-order "upsampler" matrix. Same as the second-
184 * order matrix, just using a more optimized speaker array for horizontal-only
187 constexpr std::array
<std::array
<float,9>,6> SecondOrder2DDecoder
{{
188 {{ 1.666666667e-01f
, -9.622504486e-02f
, 0.0f
, 1.666666667e-01f
, -1.490711985e-01f
, 0.0f
, 0.0f
, 0.0f
, 8.606629658e-02f
, }},
189 {{ 1.666666667e-01f
, -1.924500897e-01f
, 0.0f
, 0.000000000e+00f
, 0.000000000e+00f
, 0.0f
, 0.0f
, 0.0f
, -1.721325932e-01f
, }},
190 {{ 1.666666667e-01f
, -9.622504486e-02f
, 0.0f
, -1.666666667e-01f
, 1.490711985e-01f
, 0.0f
, 0.0f
, 0.0f
, 8.606629658e-02f
, }},
191 {{ 1.666666667e-01f
, 9.622504486e-02f
, 0.0f
, -1.666666667e-01f
, -1.490711985e-01f
, 0.0f
, 0.0f
, 0.0f
, 8.606629658e-02f
, }},
192 {{ 1.666666667e-01f
, 1.924500897e-01f
, 0.0f
, 0.000000000e+00f
, 0.000000000e+00f
, 0.0f
, 0.0f
, 0.0f
, -1.721325932e-01f
, }},
193 {{ 1.666666667e-01f
, 9.622504486e-02f
, 0.0f
, 1.666666667e-01f
, 1.490711985e-01f
, 0.0f
, 0.0f
, 0.0f
, 8.606629658e-02f
, }},
195 constexpr std::array
<AmbiChannelFloatArray
,6> SecondOrder2DEncoder
{{
196 CalcAmbiCoeffs(-0.50000000000f
, 0.0f
, 0.86602540379f
),
197 CalcAmbiCoeffs(-1.00000000000f
, 0.0f
, 0.00000000000f
),
198 CalcAmbiCoeffs(-0.50000000000f
, 0.0f
, -0.86602540379f
),
199 CalcAmbiCoeffs( 0.50000000000f
, 0.0f
, -0.86602540379f
),
200 CalcAmbiCoeffs( 1.00000000000f
, 0.0f
, 0.00000000000f
),
201 CalcAmbiCoeffs( 0.50000000000f
, 0.0f
, 0.86602540379f
),
203 static_assert(SecondOrder2DDecoder
.size() == SecondOrder2DEncoder
.size(),
204 "Second-order 2D mismatch");
206 auto CalcSecondOrder2DUp()
208 std::array
<AmbiChannelFloatArray
,9> res
{};
210 for(size_t i
{0};i
< SecondOrder2DDecoder
[0].size();++i
)
212 for(size_t j
{0};j
< SecondOrder2DEncoder
[0].size();++j
)
215 for(size_t k
{0};k
< SecondOrder2DDecoder
.size();++k
)
216 sum
+= double{SecondOrder2DDecoder
[k
][i
]} * SecondOrder2DEncoder
[k
][j
];
217 res
[i
][j
] = static_cast<float>(sum
);
225 /* This calculates a third-order "upsampler" matrix. Same as the first-order
226 * matrix, just using a more dense speaker array suitable for third-order
229 constexpr std::array
<std::array
<float,16>,20> ThirdOrderDecoder
{{
230 {{ 5.000000000e-02f
, 3.090169944e-02f
, 8.090169944e-02f
, 0.000000000e+00f
, 0.000000000e+00f
, 6.454972244e-02f
, 9.045084972e-02f
, 0.000000000e+00f
, -1.232790000e-02f
, -1.256118221e-01f
, 0.000000000e+00f
, 1.126112056e-01f
, 7.944389175e-02f
, 0.000000000e+00f
, 2.421151497e-02f
, 0.000000000e+00f
, }},
231 {{ 5.000000000e-02f
, -3.090169944e-02f
, 8.090169944e-02f
, 0.000000000e+00f
, 0.000000000e+00f
, -6.454972244e-02f
, 9.045084972e-02f
, 0.000000000e+00f
, -1.232790000e-02f
, 1.256118221e-01f
, 0.000000000e+00f
, -1.126112056e-01f
, 7.944389175e-02f
, 0.000000000e+00f
, 2.421151497e-02f
, 0.000000000e+00f
, }},
232 {{ 5.000000000e-02f
, 3.090169944e-02f
, -8.090169944e-02f
, 0.000000000e+00f
, 0.000000000e+00f
, -6.454972244e-02f
, 9.045084972e-02f
, 0.000000000e+00f
, -1.232790000e-02f
, -1.256118221e-01f
, 0.000000000e+00f
, 1.126112056e-01f
, -7.944389175e-02f
, 0.000000000e+00f
, -2.421151497e-02f
, 0.000000000e+00f
, }},
233 {{ 5.000000000e-02f
, -3.090169944e-02f
, -8.090169944e-02f
, 0.000000000e+00f
, 0.000000000e+00f
, 6.454972244e-02f
, 9.045084972e-02f
, 0.000000000e+00f
, -1.232790000e-02f
, 1.256118221e-01f
, 0.000000000e+00f
, -1.126112056e-01f
, -7.944389175e-02f
, 0.000000000e+00f
, -2.421151497e-02f
, 0.000000000e+00f
, }},
234 {{ 5.000000000e-02f
, 8.090169944e-02f
, 0.000000000e+00f
, 3.090169944e-02f
, 6.454972244e-02f
, 0.000000000e+00f
, -5.590169944e-02f
, 0.000000000e+00f
, -7.216878365e-02f
, -7.763237543e-02f
, 0.000000000e+00f
, -2.950836627e-02f
, 0.000000000e+00f
, -1.497759251e-01f
, 0.000000000e+00f
, -7.763237543e-02f
, }},
235 {{ 5.000000000e-02f
, 8.090169944e-02f
, 0.000000000e+00f
, -3.090169944e-02f
, -6.454972244e-02f
, 0.000000000e+00f
, -5.590169944e-02f
, 0.000000000e+00f
, -7.216878365e-02f
, -7.763237543e-02f
, 0.000000000e+00f
, -2.950836627e-02f
, 0.000000000e+00f
, 1.497759251e-01f
, 0.000000000e+00f
, 7.763237543e-02f
, }},
236 {{ 5.000000000e-02f
, -8.090169944e-02f
, 0.000000000e+00f
, 3.090169944e-02f
, -6.454972244e-02f
, 0.000000000e+00f
, -5.590169944e-02f
, 0.000000000e+00f
, -7.216878365e-02f
, 7.763237543e-02f
, 0.000000000e+00f
, 2.950836627e-02f
, 0.000000000e+00f
, -1.497759251e-01f
, 0.000000000e+00f
, -7.763237543e-02f
, }},
237 {{ 5.000000000e-02f
, -8.090169944e-02f
, 0.000000000e+00f
, -3.090169944e-02f
, 6.454972244e-02f
, 0.000000000e+00f
, -5.590169944e-02f
, 0.000000000e+00f
, -7.216878365e-02f
, 7.763237543e-02f
, 0.000000000e+00f
, 2.950836627e-02f
, 0.000000000e+00f
, 1.497759251e-01f
, 0.000000000e+00f
, 7.763237543e-02f
, }},
238 {{ 5.000000000e-02f
, 0.000000000e+00f
, 3.090169944e-02f
, 8.090169944e-02f
, 0.000000000e+00f
, 0.000000000e+00f
, -3.454915028e-02f
, 6.454972244e-02f
, 8.449668365e-02f
, 0.000000000e+00f
, 0.000000000e+00f
, 0.000000000e+00f
, 3.034486645e-02f
, -6.779013272e-02f
, 1.659481923e-01f
, 4.797944664e-02f
, }},
239 {{ 5.000000000e-02f
, 0.000000000e+00f
, 3.090169944e-02f
, -8.090169944e-02f
, 0.000000000e+00f
, 0.000000000e+00f
, -3.454915028e-02f
, -6.454972244e-02f
, 8.449668365e-02f
, 0.000000000e+00f
, 0.000000000e+00f
, 0.000000000e+00f
, 3.034486645e-02f
, 6.779013272e-02f
, 1.659481923e-01f
, -4.797944664e-02f
, }},
240 {{ 5.000000000e-02f
, 0.000000000e+00f
, -3.090169944e-02f
, 8.090169944e-02f
, 0.000000000e+00f
, 0.000000000e+00f
, -3.454915028e-02f
, -6.454972244e-02f
, 8.449668365e-02f
, 0.000000000e+00f
, 0.000000000e+00f
, 0.000000000e+00f
, -3.034486645e-02f
, -6.779013272e-02f
, -1.659481923e-01f
, 4.797944664e-02f
, }},
241 {{ 5.000000000e-02f
, 0.000000000e+00f
, -3.090169944e-02f
, -8.090169944e-02f
, 0.000000000e+00f
, 0.000000000e+00f
, -3.454915028e-02f
, 6.454972244e-02f
, 8.449668365e-02f
, 0.000000000e+00f
, 0.000000000e+00f
, 0.000000000e+00f
, -3.034486645e-02f
, 6.779013272e-02f
, -1.659481923e-01f
, -4.797944664e-02f
, }},
242 {{ 5.000000000e-02f
, 5.000000000e-02f
, 5.000000000e-02f
, 5.000000000e-02f
, 6.454972244e-02f
, 6.454972244e-02f
, 0.000000000e+00f
, 6.454972244e-02f
, 0.000000000e+00f
, 1.016220987e-01f
, 6.338656910e-02f
, -1.092600649e-02f
, -7.364853795e-02f
, 1.011266756e-01f
, -7.086833869e-02f
, -1.482646439e-02f
, }},
243 {{ 5.000000000e-02f
, 5.000000000e-02f
, 5.000000000e-02f
, -5.000000000e-02f
, -6.454972244e-02f
, 6.454972244e-02f
, 0.000000000e+00f
, -6.454972244e-02f
, 0.000000000e+00f
, 1.016220987e-01f
, -6.338656910e-02f
, -1.092600649e-02f
, -7.364853795e-02f
, -1.011266756e-01f
, -7.086833869e-02f
, 1.482646439e-02f
, }},
244 {{ 5.000000000e-02f
, -5.000000000e-02f
, 5.000000000e-02f
, 5.000000000e-02f
, -6.454972244e-02f
, -6.454972244e-02f
, 0.000000000e+00f
, 6.454972244e-02f
, 0.000000000e+00f
, -1.016220987e-01f
, -6.338656910e-02f
, 1.092600649e-02f
, -7.364853795e-02f
, 1.011266756e-01f
, -7.086833869e-02f
, -1.482646439e-02f
, }},
245 {{ 5.000000000e-02f
, -5.000000000e-02f
, 5.000000000e-02f
, -5.000000000e-02f
, 6.454972244e-02f
, -6.454972244e-02f
, 0.000000000e+00f
, -6.454972244e-02f
, 0.000000000e+00f
, -1.016220987e-01f
, 6.338656910e-02f
, 1.092600649e-02f
, -7.364853795e-02f
, -1.011266756e-01f
, -7.086833869e-02f
, 1.482646439e-02f
, }},
246 {{ 5.000000000e-02f
, 5.000000000e-02f
, -5.000000000e-02f
, 5.000000000e-02f
, 6.454972244e-02f
, -6.454972244e-02f
, 0.000000000e+00f
, -6.454972244e-02f
, 0.000000000e+00f
, 1.016220987e-01f
, -6.338656910e-02f
, -1.092600649e-02f
, 7.364853795e-02f
, 1.011266756e-01f
, 7.086833869e-02f
, -1.482646439e-02f
, }},
247 {{ 5.000000000e-02f
, 5.000000000e-02f
, -5.000000000e-02f
, -5.000000000e-02f
, -6.454972244e-02f
, -6.454972244e-02f
, 0.000000000e+00f
, 6.454972244e-02f
, 0.000000000e+00f
, 1.016220987e-01f
, 6.338656910e-02f
, -1.092600649e-02f
, 7.364853795e-02f
, -1.011266756e-01f
, 7.086833869e-02f
, 1.482646439e-02f
, }},
248 {{ 5.000000000e-02f
, -5.000000000e-02f
, -5.000000000e-02f
, 5.000000000e-02f
, -6.454972244e-02f
, 6.454972244e-02f
, 0.000000000e+00f
, -6.454972244e-02f
, 0.000000000e+00f
, -1.016220987e-01f
, 6.338656910e-02f
, 1.092600649e-02f
, 7.364853795e-02f
, 1.011266756e-01f
, 7.086833869e-02f
, -1.482646439e-02f
, }},
249 {{ 5.000000000e-02f
, -5.000000000e-02f
, -5.000000000e-02f
, -5.000000000e-02f
, 6.454972244e-02f
, 6.454972244e-02f
, 0.000000000e+00f
, 6.454972244e-02f
, 0.000000000e+00f
, -1.016220987e-01f
, -6.338656910e-02f
, 1.092600649e-02f
, 7.364853795e-02f
, -1.011266756e-01f
, 7.086833869e-02f
, 1.482646439e-02f
, }},
251 constexpr std::array
<AmbiChannelFloatArray
,20> ThirdOrderEncoder
{{
252 CalcAmbiCoeffs( 0.35682208976f
, 0.93417235897f
, 0.00000000000f
),
253 CalcAmbiCoeffs(-0.35682208976f
, 0.93417235897f
, 0.00000000000f
),
254 CalcAmbiCoeffs( 0.35682208976f
, -0.93417235897f
, 0.00000000000f
),
255 CalcAmbiCoeffs(-0.35682208976f
, -0.93417235897f
, 0.00000000000f
),
256 CalcAmbiCoeffs( 0.93417235897f
, 0.00000000000f
, 0.35682208976f
),
257 CalcAmbiCoeffs( 0.93417235897f
, 0.00000000000f
, -0.35682208976f
),
258 CalcAmbiCoeffs(-0.93417235897f
, 0.00000000000f
, 0.35682208976f
),
259 CalcAmbiCoeffs(-0.93417235897f
, 0.00000000000f
, -0.35682208976f
),
260 CalcAmbiCoeffs( 0.00000000000f
, 0.35682208976f
, 0.93417235897f
),
261 CalcAmbiCoeffs( 0.00000000000f
, 0.35682208976f
, -0.93417235897f
),
262 CalcAmbiCoeffs( 0.00000000000f
, -0.35682208976f
, 0.93417235897f
),
263 CalcAmbiCoeffs( 0.00000000000f
, -0.35682208976f
, -0.93417235897f
),
264 CalcAmbiCoeffs( inv_sqrt3f
, inv_sqrt3f
, inv_sqrt3f
),
265 CalcAmbiCoeffs( inv_sqrt3f
, inv_sqrt3f
, -inv_sqrt3f
),
266 CalcAmbiCoeffs( -inv_sqrt3f
, inv_sqrt3f
, inv_sqrt3f
),
267 CalcAmbiCoeffs( -inv_sqrt3f
, inv_sqrt3f
, -inv_sqrt3f
),
268 CalcAmbiCoeffs( inv_sqrt3f
, -inv_sqrt3f
, inv_sqrt3f
),
269 CalcAmbiCoeffs( inv_sqrt3f
, -inv_sqrt3f
, -inv_sqrt3f
),
270 CalcAmbiCoeffs( -inv_sqrt3f
, -inv_sqrt3f
, inv_sqrt3f
),
271 CalcAmbiCoeffs( -inv_sqrt3f
, -inv_sqrt3f
, -inv_sqrt3f
),
273 static_assert(ThirdOrderDecoder
.size() == ThirdOrderEncoder
.size(), "Third-order mismatch");
275 auto CalcThirdOrderUp()
277 std::array
<AmbiChannelFloatArray
,16> res
{};
279 for(size_t i
{0};i
< ThirdOrderDecoder
[0].size();++i
)
281 for(size_t j
{0};j
< ThirdOrderEncoder
[0].size();++j
)
284 for(size_t k
{0};k
< ThirdOrderDecoder
.size();++k
)
285 sum
+= double{ThirdOrderDecoder
[k
][i
]} * ThirdOrderEncoder
[k
][j
];
286 res
[i
][j
] = static_cast<float>(sum
);
294 /* This calculates a 2D third-order "upsampler" matrix. Same as the third-order
295 * matrix, just using a more optimized speaker array for horizontal-only
298 constexpr std::array
<std::array
<float,16>,8> ThirdOrder2DDecoder
{{
299 {{ 1.250000000e-01f
, -5.523559567e-02f
, 0.0f
, 1.333505242e-01f
, -9.128709292e-02f
, 0.0f
, 0.0f
, 0.0f
, 9.128709292e-02f
, -1.104247249e-01f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 4.573941867e-02f
, }},
300 {{ 1.250000000e-01f
, -1.333505242e-01f
, 0.0f
, 5.523559567e-02f
, -9.128709292e-02f
, 0.0f
, 0.0f
, 0.0f
, -9.128709292e-02f
, 4.573941867e-02f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, -1.104247249e-01f
, }},
301 {{ 1.250000000e-01f
, -1.333505242e-01f
, 0.0f
, -5.523559567e-02f
, 9.128709292e-02f
, 0.0f
, 0.0f
, 0.0f
, -9.128709292e-02f
, 4.573941867e-02f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 1.104247249e-01f
, }},
302 {{ 1.250000000e-01f
, -5.523559567e-02f
, 0.0f
, -1.333505242e-01f
, 9.128709292e-02f
, 0.0f
, 0.0f
, 0.0f
, 9.128709292e-02f
, -1.104247249e-01f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, -4.573941867e-02f
, }},
303 {{ 1.250000000e-01f
, 5.523559567e-02f
, 0.0f
, -1.333505242e-01f
, -9.128709292e-02f
, 0.0f
, 0.0f
, 0.0f
, 9.128709292e-02f
, 1.104247249e-01f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, -4.573941867e-02f
, }},
304 {{ 1.250000000e-01f
, 1.333505242e-01f
, 0.0f
, -5.523559567e-02f
, -9.128709292e-02f
, 0.0f
, 0.0f
, 0.0f
, -9.128709292e-02f
, -4.573941867e-02f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 1.104247249e-01f
, }},
305 {{ 1.250000000e-01f
, 1.333505242e-01f
, 0.0f
, 5.523559567e-02f
, 9.128709292e-02f
, 0.0f
, 0.0f
, 0.0f
, -9.128709292e-02f
, -4.573941867e-02f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, -1.104247249e-01f
, }},
306 {{ 1.250000000e-01f
, 5.523559567e-02f
, 0.0f
, 1.333505242e-01f
, 9.128709292e-02f
, 0.0f
, 0.0f
, 0.0f
, 9.128709292e-02f
, 1.104247249e-01f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 4.573941867e-02f
, }},
308 constexpr std::array
<AmbiChannelFloatArray
,8> ThirdOrder2DEncoder
{{
309 CalcAmbiCoeffs(-0.38268343237f
, 0.0f
, 0.92387953251f
),
310 CalcAmbiCoeffs(-0.92387953251f
, 0.0f
, 0.38268343237f
),
311 CalcAmbiCoeffs(-0.92387953251f
, 0.0f
, -0.38268343237f
),
312 CalcAmbiCoeffs(-0.38268343237f
, 0.0f
, -0.92387953251f
),
313 CalcAmbiCoeffs( 0.38268343237f
, 0.0f
, -0.92387953251f
),
314 CalcAmbiCoeffs( 0.92387953251f
, 0.0f
, -0.38268343237f
),
315 CalcAmbiCoeffs( 0.92387953251f
, 0.0f
, 0.38268343237f
),
316 CalcAmbiCoeffs( 0.38268343237f
, 0.0f
, 0.92387953251f
),
318 static_assert(ThirdOrder2DDecoder
.size() == ThirdOrder2DEncoder
.size(), "Third-order 2D mismatch");
320 auto CalcThirdOrder2DUp()
322 std::array
<AmbiChannelFloatArray
,16> res
{};
324 for(size_t i
{0};i
< ThirdOrder2DDecoder
[0].size();++i
)
326 for(size_t j
{0};j
< ThirdOrder2DEncoder
[0].size();++j
)
329 for(size_t k
{0};k
< ThirdOrder2DDecoder
.size();++k
)
330 sum
+= double{ThirdOrder2DDecoder
[k
][i
]} * ThirdOrder2DEncoder
[k
][j
];
331 res
[i
][j
] = static_cast<float>(sum
);
339 /* This calculates a 2D fourth-order "upsampler" matrix. There is no 3D fourth-
340 * order upsampler since fourth-order is the max order we'll be supporting for
341 * the foreseeable future. This is only necessary for mixing horizontal-only
342 * fourth-order content to 3D.
344 constexpr std::array
<std::array
<float,25>,10> FourthOrder2DDecoder
{{
345 {{ 1.000000000e-01f
, 3.568220898e-02f
, 0.0f
, 1.098185471e-01f
, 6.070619982e-02f
, 0.0f
, 0.0f
, 0.0f
, 8.355491589e-02f
, 7.735682057e-02f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 5.620301997e-02f
, 8.573754253e-02f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 2.785781628e-02f
, }},
346 {{ 1.000000000e-01f
, 9.341723590e-02f
, 0.0f
, 6.787159473e-02f
, 9.822469464e-02f
, 0.0f
, 0.0f
, 0.0f
, -3.191513794e-02f
, 2.954767620e-02f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, -9.093839659e-02f
, -5.298871540e-02f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, -7.293270986e-02f
, }},
347 {{ 1.000000000e-01f
, 1.154700538e-01f
, 0.0f
, 0.000000000e+00f
, 0.000000000e+00f
, 0.0f
, 0.0f
, 0.0f
, -1.032795559e-01f
, -9.561828875e-02f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.000000000e+00f
, 0.000000000e+00f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 9.014978717e-02f
, }},
348 {{ 1.000000000e-01f
, 9.341723590e-02f
, 0.0f
, -6.787159473e-02f
, -9.822469464e-02f
, 0.0f
, 0.0f
, 0.0f
, -3.191513794e-02f
, 2.954767620e-02f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 9.093839659e-02f
, 5.298871540e-02f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, -7.293270986e-02f
, }},
349 {{ 1.000000000e-01f
, 3.568220898e-02f
, 0.0f
, -1.098185471e-01f
, -6.070619982e-02f
, 0.0f
, 0.0f
, 0.0f
, 8.355491589e-02f
, 7.735682057e-02f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, -5.620301997e-02f
, -8.573754253e-02f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 2.785781628e-02f
, }},
350 {{ 1.000000000e-01f
, -3.568220898e-02f
, 0.0f
, -1.098185471e-01f
, 6.070619982e-02f
, 0.0f
, 0.0f
, 0.0f
, 8.355491589e-02f
, -7.735682057e-02f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, -5.620301997e-02f
, 8.573754253e-02f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 2.785781628e-02f
, }},
351 {{ 1.000000000e-01f
, -9.341723590e-02f
, 0.0f
, -6.787159473e-02f
, 9.822469464e-02f
, 0.0f
, 0.0f
, 0.0f
, -3.191513794e-02f
, -2.954767620e-02f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 9.093839659e-02f
, -5.298871540e-02f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, -7.293270986e-02f
, }},
352 {{ 1.000000000e-01f
, -1.154700538e-01f
, 0.0f
, 0.000000000e+00f
, 0.000000000e+00f
, 0.0f
, 0.0f
, 0.0f
, -1.032795559e-01f
, 9.561828875e-02f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.000000000e+00f
, 0.000000000e+00f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 9.014978717e-02f
, }},
353 {{ 1.000000000e-01f
, -9.341723590e-02f
, 0.0f
, 6.787159473e-02f
, -9.822469464e-02f
, 0.0f
, 0.0f
, 0.0f
, -3.191513794e-02f
, -2.954767620e-02f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, -9.093839659e-02f
, 5.298871540e-02f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, -7.293270986e-02f
, }},
354 {{ 1.000000000e-01f
, -3.568220898e-02f
, 0.0f
, 1.098185471e-01f
, -6.070619982e-02f
, 0.0f
, 0.0f
, 0.0f
, 8.355491589e-02f
, -7.735682057e-02f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 5.620301997e-02f
, -8.573754253e-02f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 2.785781628e-02f
, }},
356 constexpr std::array
<AmbiChannelFloatArray
,10> FourthOrder2DEncoder
{{
357 CalcAmbiCoeffs( 3.090169944e-01f
, 0.000000000e+00f
, 9.510565163e-01f
),
358 CalcAmbiCoeffs( 8.090169944e-01f
, 0.000000000e+00f
, 5.877852523e-01f
),
359 CalcAmbiCoeffs( 1.000000000e+00f
, 0.000000000e+00f
, 0.000000000e+00f
),
360 CalcAmbiCoeffs( 8.090169944e-01f
, 0.000000000e+00f
, -5.877852523e-01f
),
361 CalcAmbiCoeffs( 3.090169944e-01f
, 0.000000000e+00f
, -9.510565163e-01f
),
362 CalcAmbiCoeffs(-3.090169944e-01f
, 0.000000000e+00f
, -9.510565163e-01f
),
363 CalcAmbiCoeffs(-8.090169944e-01f
, 0.000000000e+00f
, -5.877852523e-01f
),
364 CalcAmbiCoeffs(-1.000000000e+00f
, 0.000000000e+00f
, 0.000000000e+00f
),
365 CalcAmbiCoeffs(-8.090169944e-01f
, 0.000000000e+00f
, 5.877852523e-01f
),
366 CalcAmbiCoeffs(-3.090169944e-01f
, 0.000000000e+00f
, 9.510565163e-01f
),
368 static_assert(FourthOrder2DDecoder
.size() == FourthOrder2DEncoder
.size(), "Fourth-order 2D mismatch");
370 auto CalcFourthOrder2DUp()
372 std::array
<AmbiChannelFloatArray
,25> res
{};
374 for(size_t i
{0};i
< FourthOrder2DDecoder
[0].size();++i
)
376 for(size_t j
{0};j
< FourthOrder2DEncoder
[0].size();++j
)
379 for(size_t k
{0};k
< FourthOrder2DDecoder
.size();++k
)
380 sum
+= double{FourthOrder2DDecoder
[k
][i
]} * FourthOrder2DEncoder
[k
][j
];
381 res
[i
][j
] = static_cast<float>(sum
);
390 const std::array
<AmbiChannelFloatArray
,4> AmbiScale::FirstOrderUp
{CalcFirstOrderUp()};
391 const std::array
<AmbiChannelFloatArray
,4> AmbiScale::FirstOrder2DUp
{CalcFirstOrder2DUp()};
392 const std::array
<AmbiChannelFloatArray
,9> AmbiScale::SecondOrderUp
{CalcSecondOrderUp()};
393 const std::array
<AmbiChannelFloatArray
,9> AmbiScale::SecondOrder2DUp
{CalcSecondOrder2DUp()};
394 const std::array
<AmbiChannelFloatArray
,16> AmbiScale::ThirdOrderUp
{CalcThirdOrderUp()};
395 const std::array
<AmbiChannelFloatArray
,16> AmbiScale::ThirdOrder2DUp
{CalcThirdOrder2DUp()};
396 const std::array
<AmbiChannelFloatArray
,25> AmbiScale::FourthOrder2DUp
{CalcFourthOrder2DUp()};
399 std::array
<float,MaxAmbiOrder
+1> AmbiScale::GetHFOrderScales(const uint src_order
,
400 const uint dev_order
, const bool horizontalOnly
) noexcept
402 std::array
<float,MaxAmbiOrder
+1> res
{};
406 for(size_t i
{0};i
< MaxAmbiOrder
+1;++i
)
407 res
[i
] = HFScales
[src_order
][i
] / HFScales
[dev_order
][i
];
411 for(size_t i
{0};i
< MaxAmbiOrder
+1;++i
)
412 res
[i
] = HFScales2D
[src_order
][i
] / HFScales2D
[dev_order
][i
];