Only ASSUME values where a variable is used
[openal-soft.git] / alc / ambidefs.h
blob17a9815bcaabf64be3b220522e3d357cacb3ca91
1 #ifndef AMBIDEFS_H
2 #define AMBIDEFS_H
4 #include <array>
6 /* The maximum number of Ambisonics channels. For a given order (o), the size
7 * needed will be (o+1)**2, thus zero-order has 1, first-order has 4, second-
8 * order has 9, third-order has 16, and fourth-order has 25.
9 */
10 #define MAX_AMBI_ORDER 3
11 constexpr inline size_t AmbiChannelsFromOrder(size_t order) noexcept
12 { return (order+1) * (order+1); }
13 #define MAX_AMBI_CHANNELS AmbiChannelsFromOrder(MAX_AMBI_ORDER)
15 /* A bitmask of ambisonic channels for 0 to 4th order. This only specifies up
16 * to 4th order, which is the highest order a 32-bit mask value can specify (a
17 * 64-bit mask could handle up to 7th order).
19 #define AMBI_0ORDER_MASK 0x00000001
20 #define AMBI_1ORDER_MASK 0x0000000f
21 #define AMBI_2ORDER_MASK 0x000001ff
22 #define AMBI_3ORDER_MASK 0x0000ffff
23 #define AMBI_4ORDER_MASK 0x01ffffff
25 /* A bitmask of ambisonic channels with height information. If none of these
26 * channels are used/needed, there's no height (e.g. with most surround sound
27 * speaker setups). This is ACN ordering, with bit 0 being ACN 0, etc.
29 #define AMBI_PERIPHONIC_MASK (0xfe7ce4)
31 /* The maximum number of ambisonic channels for 2D (non-periphonic)
32 * representation. This is 2 per each order above zero-order, plus 1 for zero-
33 * order. Or simply, o*2 + 1.
35 constexpr inline size_t Ambi2DChannelsFromOrder(size_t order) noexcept
36 { return order*2 + 1; }
37 #define MAX_AMBI2D_CHANNELS Ambi2DChannelsFromOrder(MAX_AMBI_ORDER)
40 /* NOTE: These are scale factors as applied to Ambisonics content. Decoder
41 * coefficients should be divided by these values to get proper scalings.
43 struct AmbiScale {
44 static constexpr std::array<float,MAX_AMBI_CHANNELS> FromN3D{{
45 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f,
46 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f
47 }};
48 static constexpr std::array<float,MAX_AMBI_CHANNELS> FromSN3D{{
49 1.000000000f, /* ACN 0, sqrt(1) */
50 1.732050808f, /* ACN 1, sqrt(3) */
51 1.732050808f, /* ACN 2, sqrt(3) */
52 1.732050808f, /* ACN 3, sqrt(3) */
53 2.236067978f, /* ACN 4, sqrt(5) */
54 2.236067978f, /* ACN 5, sqrt(5) */
55 2.236067978f, /* ACN 6, sqrt(5) */
56 2.236067978f, /* ACN 7, sqrt(5) */
57 2.236067978f, /* ACN 8, sqrt(5) */
58 2.645751311f, /* ACN 9, sqrt(7) */
59 2.645751311f, /* ACN 10, sqrt(7) */
60 2.645751311f, /* ACN 11, sqrt(7) */
61 2.645751311f, /* ACN 12, sqrt(7) */
62 2.645751311f, /* ACN 13, sqrt(7) */
63 2.645751311f, /* ACN 14, sqrt(7) */
64 2.645751311f, /* ACN 15, sqrt(7) */
65 }};
66 static constexpr std::array<float,MAX_AMBI_CHANNELS> FromFuMa{{
67 1.414213562f, /* ACN 0 (W), sqrt(2) */
68 1.732050808f, /* ACN 1 (Y), sqrt(3) */
69 1.732050808f, /* ACN 2 (Z), sqrt(3) */
70 1.732050808f, /* ACN 3 (X), sqrt(3) */
71 1.936491673f, /* ACN 4 (V), sqrt(15)/2 */
72 1.936491673f, /* ACN 5 (T), sqrt(15)/2 */
73 2.236067978f, /* ACN 6 (R), sqrt(5) */
74 1.936491673f, /* ACN 7 (S), sqrt(15)/2 */
75 1.936491673f, /* ACN 8 (U), sqrt(15)/2 */
76 2.091650066f, /* ACN 9 (Q), sqrt(35/8) */
77 1.972026594f, /* ACN 10 (O), sqrt(35)/3 */
78 2.231093404f, /* ACN 11 (M), sqrt(224/45) */
79 2.645751311f, /* ACN 12 (K), sqrt(7) */
80 2.231093404f, /* ACN 13 (L), sqrt(224/45) */
81 1.972026594f, /* ACN 14 (N), sqrt(35)/3 */
82 2.091650066f, /* ACN 15 (P), sqrt(35/8) */
83 }};
86 struct AmbiIndex {
87 static constexpr std::array<int,MAX_AMBI_CHANNELS> FromFuMa{{
88 0, /* W */
89 3, /* X */
90 1, /* Y */
91 2, /* Z */
92 6, /* R */
93 7, /* S */
94 5, /* T */
95 8, /* U */
96 4, /* V */
97 12, /* K */
98 13, /* L */
99 11, /* M */
100 14, /* N */
101 10, /* O */
102 15, /* P */
103 9, /* Q */
105 static constexpr std::array<int,MAX_AMBI_CHANNELS> FromACN{{
106 0, 1, 2, 3, 4, 5, 6, 7,
107 8, 9, 10, 11, 12, 13, 14, 15
110 static constexpr std::array<int,MAX_AMBI2D_CHANNELS> From2D{{
111 0, 1,3, 4,8, 9,15
113 static constexpr std::array<int,MAX_AMBI_CHANNELS> From3D{{
114 0, 1, 2, 3, 4, 5, 6, 7,
115 8, 9, 10, 11, 12, 13, 14, 15
119 #endif /* AMBIDEFS_H */