11 using AmbiChannelFloatArray
= std::array
<float,MaxAmbiChannels
>;
13 constexpr auto inv_sqrt3f
= static_cast<float>(1.0/al::numbers::sqrt3
);
16 /* These HF gains are derived from the same 32-point speaker array. The scale
17 * factor between orders represents the same scale factors for any (regular)
18 * speaker array decoder. e.g. Given a first-order source and second-order
19 * output, applying an HF scale of HFScales[1][0] / HFScales[2][0] to channel 0
20 * will result in that channel being subsequently decoded for second-order as
21 * if it was a first-order decoder for that same speaker array.
23 constexpr std::array HFScales
{
24 std::array
{4.000000000e+00f
, 2.309401077e+00f
, 1.192569588e+00f
, 7.189495850e-01f
},
25 std::array
{4.000000000e+00f
, 2.309401077e+00f
, 1.192569588e+00f
, 7.189495850e-01f
},
26 std::array
{2.981423970e+00f
, 2.309401077e+00f
, 1.192569588e+00f
, 7.189495850e-01f
},
27 std::array
{2.359168820e+00f
, 2.031565936e+00f
, 1.444598386e+00f
, 7.189495850e-01f
},
28 /*std::array{1.947005434e+00f, 1.764337084e+00f, 1.424707344e+00f, 9.755104127e-01f, 4.784482742e-01f}, */
31 /* Same as above, but using a 10-point horizontal-only speaker array. Should
32 * only be used when the device is mixing in 2D B-Format for horizontal-only
35 constexpr std::array HFScales2D
{
36 std::array
{2.236067977e+00f
, 1.581138830e+00f
, 9.128709292e-01f
, 6.050756345e-01f
},
37 std::array
{2.236067977e+00f
, 1.581138830e+00f
, 9.128709292e-01f
, 6.050756345e-01f
},
38 std::array
{1.825741858e+00f
, 1.581138830e+00f
, 9.128709292e-01f
, 6.050756345e-01f
},
39 std::array
{1.581138830e+00f
, 1.460781803e+00f
, 1.118033989e+00f
, 6.050756345e-01f
},
40 /*std::array{1.414213562e+00f, 1.344997024e+00f, 1.144122806e+00f, 8.312538756e-01f, 4.370160244e-01f}, */
44 /* This calculates a first-order "upsampler" matrix. It combines a first-order
45 * decoder matrix with a max-order encoder matrix, creating a matrix that
46 * behaves as if the B-Format input signal is first decoded to a speaker array
47 * at first-order, then those speaker feeds are encoded to a higher-order
48 * signal. While not perfect, this should accurately encode a lower-order
49 * signal into a higher-order signal.
51 constexpr std::array FirstOrderDecoder
{
52 std::array
{1.250000000e-01f
, 1.250000000e-01f
, 1.250000000e-01f
, 1.250000000e-01f
},
53 std::array
{1.250000000e-01f
, 1.250000000e-01f
, 1.250000000e-01f
, -1.250000000e-01f
},
54 std::array
{1.250000000e-01f
, -1.250000000e-01f
, 1.250000000e-01f
, 1.250000000e-01f
},
55 std::array
{1.250000000e-01f
, -1.250000000e-01f
, 1.250000000e-01f
, -1.250000000e-01f
},
56 std::array
{1.250000000e-01f
, 1.250000000e-01f
, -1.250000000e-01f
, 1.250000000e-01f
},
57 std::array
{1.250000000e-01f
, 1.250000000e-01f
, -1.250000000e-01f
, -1.250000000e-01f
},
58 std::array
{1.250000000e-01f
, -1.250000000e-01f
, -1.250000000e-01f
, 1.250000000e-01f
},
59 std::array
{1.250000000e-01f
, -1.250000000e-01f
, -1.250000000e-01f
, -1.250000000e-01f
},
61 constexpr std::array FirstOrderEncoder
{
62 CalcAmbiCoeffs( inv_sqrt3f
, inv_sqrt3f
, inv_sqrt3f
),
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
),
71 static_assert(FirstOrderDecoder
.size() == FirstOrderEncoder
.size(), "First-order mismatch");
73 /* This calculates a 2D first-order "upsampler" matrix. Same as the first-order
74 * matrix, just using a more optimized speaker array for horizontal-only
77 constexpr std::array FirstOrder2DDecoder
{
78 std::array
{1.666666667e-01f
, -9.622504486e-02f
, 0.0f
, 1.666666667e-01f
},
79 std::array
{1.666666667e-01f
, -1.924500897e-01f
, 0.0f
, 0.000000000e+00f
},
80 std::array
{1.666666667e-01f
, -9.622504486e-02f
, 0.0f
, -1.666666667e-01f
},
81 std::array
{1.666666667e-01f
, 9.622504486e-02f
, 0.0f
, -1.666666667e-01f
},
82 std::array
{1.666666667e-01f
, 1.924500897e-01f
, 0.0f
, 0.000000000e+00f
},
83 std::array
{1.666666667e-01f
, 9.622504486e-02f
, 0.0f
, 1.666666667e-01f
},
85 constexpr std::array FirstOrder2DEncoder
{
86 CalcAmbiCoeffs(-0.50000000000f
, 0.0f
, 0.86602540379f
),
87 CalcAmbiCoeffs(-1.00000000000f
, 0.0f
, 0.00000000000f
),
88 CalcAmbiCoeffs(-0.50000000000f
, 0.0f
, -0.86602540379f
),
89 CalcAmbiCoeffs( 0.50000000000f
, 0.0f
, -0.86602540379f
),
90 CalcAmbiCoeffs( 1.00000000000f
, 0.0f
, 0.00000000000f
),
91 CalcAmbiCoeffs( 0.50000000000f
, 0.0f
, 0.86602540379f
),
93 static_assert(FirstOrder2DDecoder
.size() == FirstOrder2DEncoder
.size(), "First-order 2D mismatch");
96 /* This calculates a second-order "upsampler" matrix. Same as the first-order
97 * matrix, just using a slightly more dense speaker array suitable for second-
100 constexpr std::array SecondOrderDecoder
{
101 std::array
{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
},
102 std::array
{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
},
103 std::array
{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
},
104 std::array
{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
},
105 std::array
{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
},
106 std::array
{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
},
107 std::array
{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
},
108 std::array
{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
},
109 std::array
{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
},
110 std::array
{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
},
111 std::array
{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
},
112 std::array
{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
},
114 constexpr std::array SecondOrderEncoder
{
115 CalcAmbiCoeffs( 0.000000000e+00f
, -5.257311121e-01f
, 8.506508084e-01f
),
116 CalcAmbiCoeffs(-8.506508084e-01f
, 0.000000000e+00f
, 5.257311121e-01f
),
117 CalcAmbiCoeffs(-5.257311121e-01f
, 8.506508084e-01f
, 0.000000000e+00f
),
118 CalcAmbiCoeffs( 0.000000000e+00f
, 5.257311121e-01f
, 8.506508084e-01f
),
119 CalcAmbiCoeffs(-8.506508084e-01f
, 0.000000000e+00f
, -5.257311121e-01f
),
120 CalcAmbiCoeffs( 5.257311121e-01f
, -8.506508084e-01f
, 0.000000000e+00f
),
121 CalcAmbiCoeffs( 0.000000000e+00f
, -5.257311121e-01f
, -8.506508084e-01f
),
122 CalcAmbiCoeffs( 8.506508084e-01f
, 0.000000000e+00f
, -5.257311121e-01f
),
123 CalcAmbiCoeffs( 5.257311121e-01f
, 8.506508084e-01f
, 0.000000000e+00f
),
124 CalcAmbiCoeffs( 0.000000000e+00f
, 5.257311121e-01f
, -8.506508084e-01f
),
125 CalcAmbiCoeffs( 8.506508084e-01f
, 0.000000000e+00f
, 5.257311121e-01f
),
126 CalcAmbiCoeffs(-5.257311121e-01f
, -8.506508084e-01f
, 0.000000000e+00f
),
128 static_assert(SecondOrderDecoder
.size() == SecondOrderEncoder
.size(), "Second-order mismatch");
130 /* This calculates a 2D second-order "upsampler" matrix. Same as the second-
131 * order matrix, just using a more optimized speaker array for horizontal-only
134 constexpr std::array SecondOrder2DDecoder
{
135 std::array
{1.666666667e-01f
, -9.622504486e-02f
, 0.0f
, 1.666666667e-01f
, -1.490711985e-01f
, 0.0f
, 0.0f
, 0.0f
, 8.606629658e-02f
},
136 std::array
{1.666666667e-01f
, -1.924500897e-01f
, 0.0f
, 0.000000000e+00f
, 0.000000000e+00f
, 0.0f
, 0.0f
, 0.0f
, -1.721325932e-01f
},
137 std::array
{1.666666667e-01f
, -9.622504486e-02f
, 0.0f
, -1.666666667e-01f
, 1.490711985e-01f
, 0.0f
, 0.0f
, 0.0f
, 8.606629658e-02f
},
138 std::array
{1.666666667e-01f
, 9.622504486e-02f
, 0.0f
, -1.666666667e-01f
, -1.490711985e-01f
, 0.0f
, 0.0f
, 0.0f
, 8.606629658e-02f
},
139 std::array
{1.666666667e-01f
, 1.924500897e-01f
, 0.0f
, 0.000000000e+00f
, 0.000000000e+00f
, 0.0f
, 0.0f
, 0.0f
, -1.721325932e-01f
},
140 std::array
{1.666666667e-01f
, 9.622504486e-02f
, 0.0f
, 1.666666667e-01f
, 1.490711985e-01f
, 0.0f
, 0.0f
, 0.0f
, 8.606629658e-02f
},
142 constexpr std::array SecondOrder2DEncoder
{
143 CalcAmbiCoeffs(-0.50000000000f
, 0.0f
, 0.86602540379f
),
144 CalcAmbiCoeffs(-1.00000000000f
, 0.0f
, 0.00000000000f
),
145 CalcAmbiCoeffs(-0.50000000000f
, 0.0f
, -0.86602540379f
),
146 CalcAmbiCoeffs( 0.50000000000f
, 0.0f
, -0.86602540379f
),
147 CalcAmbiCoeffs( 1.00000000000f
, 0.0f
, 0.00000000000f
),
148 CalcAmbiCoeffs( 0.50000000000f
, 0.0f
, 0.86602540379f
),
150 static_assert(SecondOrder2DDecoder
.size() == SecondOrder2DEncoder
.size(),
151 "Second-order 2D mismatch");
154 /* This calculates a third-order "upsampler" matrix. Same as the first-order
155 * matrix, just using a more dense speaker array suitable for third-order
158 constexpr std::array ThirdOrderDecoder
{
159 std::array
{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
},
160 std::array
{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
},
161 std::array
{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
},
162 std::array
{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
},
163 std::array
{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
},
164 std::array
{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
},
165 std::array
{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
},
166 std::array
{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
},
167 std::array
{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
},
168 std::array
{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
},
169 std::array
{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
},
170 std::array
{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
},
171 std::array
{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
},
172 std::array
{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
},
173 std::array
{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
},
174 std::array
{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
},
175 std::array
{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
},
176 std::array
{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
},
177 std::array
{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
},
178 std::array
{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
},
180 constexpr std::array ThirdOrderEncoder
{
181 CalcAmbiCoeffs( 0.35682208976f
, 0.93417235897f
, 0.00000000000f
),
182 CalcAmbiCoeffs(-0.35682208976f
, 0.93417235897f
, 0.00000000000f
),
183 CalcAmbiCoeffs( 0.35682208976f
, -0.93417235897f
, 0.00000000000f
),
184 CalcAmbiCoeffs(-0.35682208976f
, -0.93417235897f
, 0.00000000000f
),
185 CalcAmbiCoeffs( 0.93417235897f
, 0.00000000000f
, 0.35682208976f
),
186 CalcAmbiCoeffs( 0.93417235897f
, 0.00000000000f
, -0.35682208976f
),
187 CalcAmbiCoeffs(-0.93417235897f
, 0.00000000000f
, 0.35682208976f
),
188 CalcAmbiCoeffs(-0.93417235897f
, 0.00000000000f
, -0.35682208976f
),
189 CalcAmbiCoeffs( 0.00000000000f
, 0.35682208976f
, 0.93417235897f
),
190 CalcAmbiCoeffs( 0.00000000000f
, 0.35682208976f
, -0.93417235897f
),
191 CalcAmbiCoeffs( 0.00000000000f
, -0.35682208976f
, 0.93417235897f
),
192 CalcAmbiCoeffs( 0.00000000000f
, -0.35682208976f
, -0.93417235897f
),
193 CalcAmbiCoeffs( inv_sqrt3f
, inv_sqrt3f
, inv_sqrt3f
),
194 CalcAmbiCoeffs( inv_sqrt3f
, inv_sqrt3f
, -inv_sqrt3f
),
195 CalcAmbiCoeffs( -inv_sqrt3f
, inv_sqrt3f
, inv_sqrt3f
),
196 CalcAmbiCoeffs( -inv_sqrt3f
, inv_sqrt3f
, -inv_sqrt3f
),
197 CalcAmbiCoeffs( inv_sqrt3f
, -inv_sqrt3f
, inv_sqrt3f
),
198 CalcAmbiCoeffs( inv_sqrt3f
, -inv_sqrt3f
, -inv_sqrt3f
),
199 CalcAmbiCoeffs( -inv_sqrt3f
, -inv_sqrt3f
, inv_sqrt3f
),
200 CalcAmbiCoeffs( -inv_sqrt3f
, -inv_sqrt3f
, -inv_sqrt3f
),
202 static_assert(ThirdOrderDecoder
.size() == ThirdOrderEncoder
.size(), "Third-order mismatch");
204 /* This calculates a 2D third-order "upsampler" matrix. Same as the third-order
205 * matrix, just using a more optimized speaker array for horizontal-only
208 constexpr std::array ThirdOrder2DDecoder
{
209 std::array
{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
},
210 std::array
{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
},
211 std::array
{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
},
212 std::array
{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
},
213 std::array
{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
},
214 std::array
{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
},
215 std::array
{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
},
216 std::array
{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
},
218 constexpr std::array ThirdOrder2DEncoder
{
219 CalcAmbiCoeffs(-0.38268343237f
, 0.0f
, 0.92387953251f
),
220 CalcAmbiCoeffs(-0.92387953251f
, 0.0f
, 0.38268343237f
),
221 CalcAmbiCoeffs(-0.92387953251f
, 0.0f
, -0.38268343237f
),
222 CalcAmbiCoeffs(-0.38268343237f
, 0.0f
, -0.92387953251f
),
223 CalcAmbiCoeffs( 0.38268343237f
, 0.0f
, -0.92387953251f
),
224 CalcAmbiCoeffs( 0.92387953251f
, 0.0f
, -0.38268343237f
),
225 CalcAmbiCoeffs( 0.92387953251f
, 0.0f
, 0.38268343237f
),
226 CalcAmbiCoeffs( 0.38268343237f
, 0.0f
, 0.92387953251f
),
228 static_assert(ThirdOrder2DDecoder
.size() == ThirdOrder2DEncoder
.size(), "Third-order 2D mismatch");
231 /* This calculates a 2D fourth-order "upsampler" matrix. There is no 3D fourth-
232 * order upsampler since fourth-order is the max order we'll be supporting for
233 * the foreseeable future. This is only necessary for mixing horizontal-only
234 * fourth-order content to 3D.
236 constexpr std::array FourthOrder2DDecoder
{
237 std::array
{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
},
238 std::array
{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
},
239 std::array
{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
},
240 std::array
{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
},
241 std::array
{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
},
242 std::array
{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
},
243 std::array
{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
},
244 std::array
{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
},
245 std::array
{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
},
246 std::array
{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
},
248 constexpr std::array FourthOrder2DEncoder
{
249 CalcAmbiCoeffs( 3.090169944e-01f
, 0.000000000e+00f
, 9.510565163e-01f
),
250 CalcAmbiCoeffs( 8.090169944e-01f
, 0.000000000e+00f
, 5.877852523e-01f
),
251 CalcAmbiCoeffs( 1.000000000e+00f
, 0.000000000e+00f
, 0.000000000e+00f
),
252 CalcAmbiCoeffs( 8.090169944e-01f
, 0.000000000e+00f
, -5.877852523e-01f
),
253 CalcAmbiCoeffs( 3.090169944e-01f
, 0.000000000e+00f
, -9.510565163e-01f
),
254 CalcAmbiCoeffs(-3.090169944e-01f
, 0.000000000e+00f
, -9.510565163e-01f
),
255 CalcAmbiCoeffs(-8.090169944e-01f
, 0.000000000e+00f
, -5.877852523e-01f
),
256 CalcAmbiCoeffs(-1.000000000e+00f
, 0.000000000e+00f
, 0.000000000e+00f
),
257 CalcAmbiCoeffs(-8.090169944e-01f
, 0.000000000e+00f
, 5.877852523e-01f
),
258 CalcAmbiCoeffs(-3.090169944e-01f
, 0.000000000e+00f
, 9.510565163e-01f
),
260 static_assert(FourthOrder2DDecoder
.size() == FourthOrder2DEncoder
.size(), "Fourth-order 2D mismatch");
263 template<size_t N
, size_t M
>
264 constexpr auto CalcAmbiUpsampler(const std::array
<std::array
<float,N
>,M
> &decoder
,
265 const std::array
<AmbiChannelFloatArray
,M
> &encoder
)
267 std::array
<AmbiChannelFloatArray
,N
> res
{};
269 for(size_t i
{0};i
< decoder
[0].size();++i
)
271 for(size_t j
{0};j
< encoder
[0].size();++j
)
274 for(size_t k
{0};k
< decoder
.size();++k
)
275 sum
+= double{decoder
[k
][i
]} * encoder
[k
][j
];
276 res
[i
][j
] = static_cast<float>(sum
);
285 const std::array
<std::array
<float,MaxAmbiChannels
>,4> AmbiScale::FirstOrderUp
{CalcAmbiUpsampler(FirstOrderDecoder
, FirstOrderEncoder
)};
286 const std::array
<std::array
<float,MaxAmbiChannels
>,4> AmbiScale::FirstOrder2DUp
{CalcAmbiUpsampler(FirstOrder2DDecoder
, FirstOrder2DEncoder
)};
287 const std::array
<std::array
<float,MaxAmbiChannels
>,9> AmbiScale::SecondOrderUp
{CalcAmbiUpsampler(SecondOrderDecoder
, SecondOrderEncoder
)};
288 const std::array
<std::array
<float,MaxAmbiChannels
>,9> AmbiScale::SecondOrder2DUp
{CalcAmbiUpsampler(SecondOrder2DDecoder
, SecondOrder2DEncoder
)};
289 const std::array
<std::array
<float,MaxAmbiChannels
>,16> AmbiScale::ThirdOrderUp
{CalcAmbiUpsampler(ThirdOrderDecoder
, ThirdOrderEncoder
)};
290 const std::array
<std::array
<float,MaxAmbiChannels
>,16> AmbiScale::ThirdOrder2DUp
{CalcAmbiUpsampler(ThirdOrder2DDecoder
, ThirdOrder2DEncoder
)};
291 const std::array
<std::array
<float,MaxAmbiChannels
>,25> AmbiScale::FourthOrder2DUp
{CalcAmbiUpsampler(FourthOrder2DDecoder
, FourthOrder2DEncoder
)};
294 std::array
<float,MaxAmbiOrder
+1> AmbiScale::GetHFOrderScales(const uint src_order
,
295 const uint dev_order
, const bool horizontalOnly
) noexcept
297 std::array
<float,MaxAmbiOrder
+1> res
{};
301 for(size_t i
{0};i
< MaxAmbiOrder
+1;++i
)
302 res
[i
] = HFScales
[src_order
][i
] / HFScales
[dev_order
][i
];
306 for(size_t i
{0};i
< MaxAmbiOrder
+1;++i
)
307 res
[i
] = HFScales2D
[src_order
][i
] / HFScales2D
[dev_order
][i
];