🛠️🐜 Antkeeper superbuild with dependencies included https://antkeeper.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

119 lines
4.2 KiB

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