🛠️🐜 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.

450 lines
29 KiB

  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
  4. This software is provided 'as-is', without any express or implied
  5. warranty. In no event will the authors be held liable for any damages
  6. arising from the use of this software.
  7. Permission is granted to anyone to use this software for any purpose,
  8. including commercial applications, and to alter it and redistribute it
  9. freely, subject to the following restrictions:
  10. 1. The origin of this software must not be misrepresented; you must not
  11. claim that you wrote the original software. If you use this software
  12. in a product, an acknowledgment in the product documentation would be
  13. appreciated but is not required.
  14. 2. Altered source versions must be plainly marked as such, and must not be
  15. misrepresented as being the original software.
  16. 3. This notice may not be removed or altered from any source distribution.
  17. */
  18. #include <stdio.h>
  19. /*
  20. Built with:
  21. gcc -o genchancvt build-scripts/gen_audio_channel_conversion.c -lm && ./genchancvt > src/audio/SDL_audio_channel_converters.h
  22. */
  23. #define NUM_CHANNELS 8
  24. static const char *layout_names[NUM_CHANNELS] = {
  25. "Mono", "Stereo", "2.1", "Quad", "4.1", "5.1", "6.1", "7.1"
  26. };
  27. static const char *channel_names[NUM_CHANNELS][NUM_CHANNELS] = {
  28. /* mono */ { "FC" },
  29. /* stereo */ { "FL", "FR" },
  30. /* 2.1 */ { "FL", "FR", "LFE" },
  31. /* quad */ { "FL", "FR", "BL", "BR" },
  32. /* 4.1 */ { "FL", "FR", "LFE", "BL", "BR" },
  33. /* 5.1 */ { "FL", "FR", "FC", "LFE", "BL", "BR" },
  34. /* 6.1 */ { "FL", "FR", "FC", "LFE", "BC", "SL", "SR" },
  35. /* 7.1 */ { "FL", "FR", "FC", "LFE", "BL", "BR", "SL", "SR" },
  36. };
  37. /*
  38. * This table is from FAudio:
  39. *
  40. * https://raw.githubusercontent.com/FNA-XNA/FAudio/master/src/matrix_defaults.inl
  41. */
  42. static const float channel_conversion_matrix[8][8][64] = {
  43. {
  44. /* 1 x 1 */
  45. { 1.000000000f },
  46. /* 1 x 2 */
  47. { 1.000000000f, 1.000000000f },
  48. /* 1 x 3 */
  49. { 1.000000000f, 1.000000000f, 0.000000000f },
  50. /* 1 x 4 */
  51. { 1.000000000f, 1.000000000f, 0.000000000f, 0.000000000f },
  52. /* 1 x 5 */
  53. { 1.000000000f, 1.000000000f, 0.000000000f, 0.000000000f, 0.000000000f },
  54. /* 1 x 6 */
  55. { 1.000000000f, 1.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f },
  56. /* 1 x 7 */
  57. { 1.000000000f, 1.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f },
  58. /* 1 x 8 */
  59. { 1.000000000f, 1.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f }
  60. },
  61. {
  62. /* 2 x 1 */
  63. { 0.500000000f, 0.500000000f },
  64. /* 2 x 2 */
  65. { 1.000000000f, 0.000000000f, 0.000000000f, 1.000000000f },
  66. /* 2 x 3 */
  67. { 1.000000000f, 0.000000000f, 0.000000000f, 1.000000000f, 0.000000000f, 0.000000000f },
  68. /* 2 x 4 */
  69. { 1.000000000f, 0.000000000f, 0.000000000f, 1.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f },
  70. /* 2 x 5 */
  71. { 1.000000000f, 0.000000000f, 0.000000000f, 1.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f },
  72. /* 2 x 6 */
  73. { 1.000000000f, 0.000000000f, 0.000000000f, 1.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f },
  74. /* 2 x 7 */
  75. { 1.000000000f, 0.000000000f, 0.000000000f, 1.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f },
  76. /* 2 x 8 */
  77. { 1.000000000f, 0.000000000f, 0.000000000f, 1.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f }
  78. },
  79. {
  80. /* 3 x 1 */
  81. { 0.333333343f, 0.333333343f, 0.333333343f },
  82. /* 3 x 2 */
  83. { 0.800000012f, 0.000000000f, 0.200000003f, 0.000000000f, 0.800000012f, 0.200000003f },
  84. /* 3 x 3 */
  85. { 1.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 1.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 1.000000000f },
  86. /* 3 x 4 */
  87. { 0.888888896f, 0.000000000f, 0.111111112f, 0.000000000f, 0.888888896f, 0.111111112f, 0.000000000f, 0.000000000f, 0.111111112f, 0.000000000f, 0.000000000f, 0.111111112f },
  88. /* 3 x 5 */
  89. { 1.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 1.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 1.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f },
  90. /* 3 x 6 */
  91. { 1.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 1.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 1.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f },
  92. /* 3 x 7 */
  93. { 1.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 1.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 1.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f },
  94. /* 3 x 8 */
  95. { 1.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 1.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 1.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f }
  96. },
  97. {
  98. /* 4 x 1 */
  99. { 0.250000000f, 0.250000000f, 0.250000000f, 0.250000000f },
  100. /* 4 x 2 */
  101. { 0.421000004f, 0.000000000f, 0.358999997f, 0.219999999f, 0.000000000f, 0.421000004f, 0.219999999f, 0.358999997f },
  102. /* 4 x 3 */
  103. { 0.421000004f, 0.000000000f, 0.358999997f, 0.219999999f, 0.000000000f, 0.421000004f, 0.219999999f, 0.358999997f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f },
  104. /* 4 x 4 */
  105. { 1.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 1.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 1.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 1.000000000f },
  106. /* 4 x 5 */
  107. { 1.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 1.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 1.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 1.000000000f },
  108. /* 4 x 6 */
  109. { 1.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 1.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 1.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 1.000000000f },
  110. /* 4 x 7 */
  111. { 0.939999998f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.939999998f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.500000000f, 0.500000000f, 0.000000000f, 0.000000000f, 0.796000004f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.796000004f },
  112. /* 4 x 8 */
  113. { 1.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 1.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 1.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 1.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f }
  114. },
  115. {
  116. /* 5 x 1 */
  117. { 0.200000003f, 0.200000003f, 0.200000003f, 0.200000003f, 0.200000003f },
  118. /* 5 x 2 */
  119. { 0.374222219f, 0.000000000f, 0.111111112f, 0.319111109f, 0.195555553f, 0.000000000f, 0.374222219f, 0.111111112f, 0.195555553f, 0.319111109f },
  120. /* 5 x 3 */
  121. { 0.421000004f, 0.000000000f, 0.000000000f, 0.358999997f, 0.219999999f, 0.000000000f, 0.421000004f, 0.000000000f, 0.219999999f, 0.358999997f, 0.000000000f, 0.000000000f, 1.000000000f, 0.000000000f, 0.000000000f },
  122. /* 5 x 4 */
  123. { 0.941176474f, 0.000000000f, 0.058823530f, 0.000000000f, 0.000000000f, 0.000000000f, 0.941176474f, 0.058823530f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.058823530f, 0.941176474f, 0.000000000f, 0.000000000f, 0.000000000f, 0.058823530f, 0.000000000f, 0.941176474f },
  124. /* 5 x 5 */
  125. { 1.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 1.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 1.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 1.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 1.000000000f },
  126. /* 5 x 6 */
  127. { 1.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 1.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 1.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 1.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 1.000000000f },
  128. /* 5 x 7 */
  129. { 0.939999998f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.939999998f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 1.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.500000000f, 0.500000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.796000004f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.796000004f },
  130. /* 5 x 8 */
  131. { 1.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 1.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 1.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 1.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 1.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f }
  132. },
  133. {
  134. /* 6 x 1 */
  135. { 0.166666672f, 0.166666672f, 0.166666672f, 0.166666672f, 0.166666672f, 0.166666672f },
  136. /* 6 x 2 */
  137. { 0.294545442f, 0.000000000f, 0.208181813f, 0.090909094f, 0.251818180f, 0.154545456f, 0.000000000f, 0.294545442f, 0.208181813f, 0.090909094f, 0.154545456f, 0.251818180f },
  138. /* 6 x 3 */
  139. { 0.324000001f, 0.000000000f, 0.229000002f, 0.000000000f, 0.277000010f, 0.170000002f, 0.000000000f, 0.324000001f, 0.229000002f, 0.000000000f, 0.170000002f, 0.277000010f, 0.000000000f, 0.000000000f, 0.000000000f, 1.000000000f, 0.000000000f, 0.000000000f },
  140. /* 6 x 4 */
  141. { 0.558095276f, 0.000000000f, 0.394285709f, 0.047619049f, 0.000000000f, 0.000000000f, 0.000000000f, 0.558095276f, 0.394285709f, 0.047619049f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.047619049f, 0.558095276f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.047619049f, 0.000000000f, 0.558095276f },
  142. /* 6 x 5 */
  143. { 0.586000025f, 0.000000000f, 0.414000005f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.586000025f, 0.414000005f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 1.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.586000025f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.586000025f },
  144. /* 6 x 6 */
  145. { 1.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 1.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 1.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 1.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 1.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 1.000000000f },
  146. /* 6 x 7 */
  147. { 0.939999998f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.939999998f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.939999998f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 1.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.500000000f, 0.500000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.796000004f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.796000004f },
  148. /* 6 x 8 */
  149. { 1.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 1.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 1.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 1.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 1.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 1.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f }
  150. },
  151. {
  152. /* 7 x 1 */
  153. { 0.143142849f, 0.143142849f, 0.143142849f, 0.142857149f, 0.143142849f, 0.143142849f, 0.143142849f },
  154. /* 7 x 2 */
  155. { 0.247384623f, 0.000000000f, 0.174461529f, 0.076923080f, 0.174461529f, 0.226153851f, 0.100615382f, 0.000000000f, 0.247384623f, 0.174461529f, 0.076923080f, 0.174461529f, 0.100615382f, 0.226153851f },
  156. /* 7 x 3 */
  157. { 0.268000007f, 0.000000000f, 0.188999996f, 0.000000000f, 0.188999996f, 0.245000005f, 0.108999997f, 0.000000000f, 0.268000007f, 0.188999996f, 0.000000000f, 0.188999996f, 0.108999997f, 0.245000005f, 0.000000000f, 0.000000000f, 0.000000000f, 1.000000000f, 0.000000000f, 0.000000000f, 0.000000000f },
  158. /* 7 x 4 */
  159. { 0.463679999f, 0.000000000f, 0.327360004f, 0.040000003f, 0.000000000f, 0.168960005f, 0.000000000f, 0.000000000f, 0.463679999f, 0.327360004f, 0.040000003f, 0.000000000f, 0.000000000f, 0.168960005f, 0.000000000f, 0.000000000f, 0.000000000f, 0.040000003f, 0.327360004f, 0.431039989f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.040000003f, 0.327360004f, 0.000000000f, 0.431039989f },
  160. /* 7 x 5 */
  161. { 0.483000010f, 0.000000000f, 0.340999991f, 0.000000000f, 0.000000000f, 0.175999999f, 0.000000000f, 0.000000000f, 0.483000010f, 0.340999991f, 0.000000000f, 0.000000000f, 0.000000000f, 0.175999999f, 0.000000000f, 0.000000000f, 0.000000000f, 1.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.340999991f, 0.449000001f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.340999991f, 0.000000000f, 0.449000001f },
  162. /* 7 x 6 */
  163. { 0.611000001f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.223000005f, 0.000000000f, 0.000000000f, 0.611000001f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.223000005f, 0.000000000f, 0.000000000f, 0.611000001f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 1.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.432000011f, 0.568000019f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.432000011f, 0.000000000f, 0.568000019f },
  164. /* 7 x 7 */
  165. { 1.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 1.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 1.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 1.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 1.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 1.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 1.000000000f },
  166. /* 7 x 8 */
  167. { 1.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 1.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 1.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 1.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.707000017f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.707000017f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 1.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 1.000000000f }
  168. },
  169. {
  170. /* 8 x 1 */
  171. { 0.125125006f, 0.125125006f, 0.125125006f, 0.125000000f, 0.125125006f, 0.125125006f, 0.125125006f, 0.125125006f },
  172. /* 8 x 2 */
  173. { 0.211866662f, 0.000000000f, 0.150266662f, 0.066666670f, 0.181066677f, 0.111066669f, 0.194133341f, 0.085866667f, 0.000000000f, 0.211866662f, 0.150266662f, 0.066666670f, 0.111066669f, 0.181066677f, 0.085866667f, 0.194133341f },
  174. /* 8 x 3 */
  175. { 0.226999998f, 0.000000000f, 0.160999998f, 0.000000000f, 0.194000006f, 0.119000003f, 0.208000004f, 0.092000000f, 0.000000000f, 0.226999998f, 0.160999998f, 0.000000000f, 0.119000003f, 0.194000006f, 0.092000000f, 0.208000004f, 0.000000000f, 0.000000000f, 0.000000000f, 1.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f },
  176. /* 8 x 4 */
  177. { 0.466344833f, 0.000000000f, 0.329241365f, 0.034482758f, 0.000000000f, 0.000000000f, 0.169931039f, 0.000000000f, 0.000000000f, 0.466344833f, 0.329241365f, 0.034482758f, 0.000000000f, 0.000000000f, 0.000000000f, 0.169931039f, 0.000000000f, 0.000000000f, 0.000000000f, 0.034482758f, 0.466344833f, 0.000000000f, 0.433517247f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.034482758f, 0.000000000f, 0.466344833f, 0.000000000f, 0.433517247f },
  178. /* 8 x 5 */
  179. { 0.483000010f, 0.000000000f, 0.340999991f, 0.000000000f, 0.000000000f, 0.000000000f, 0.175999999f, 0.000000000f, 0.000000000f, 0.483000010f, 0.340999991f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.175999999f, 0.000000000f, 0.000000000f, 0.000000000f, 1.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.483000010f, 0.000000000f, 0.449000001f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.483000010f, 0.000000000f, 0.449000001f },
  180. /* 8 x 6 */
  181. { 0.518000007f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.188999996f, 0.000000000f, 0.000000000f, 0.518000007f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.188999996f, 0.000000000f, 0.000000000f, 0.518000007f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 1.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.518000007f, 0.000000000f, 0.481999993f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.518000007f, 0.000000000f, 0.481999993f },
  182. /* 8 x 7 */
  183. { 0.541000009f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.541000009f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.541000009f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 1.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.287999988f, 0.287999988f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.458999991f, 0.000000000f, 0.541000009f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.458999991f, 0.000000000f, 0.541000009f },
  184. /* 8 x 8 */
  185. { 1.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 1.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 1.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 1.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 1.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 1.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 1.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 1.000000000f }
  186. }
  187. };
  188. static char *remove_dots(const char *str) /* this is NOT robust. */
  189. {
  190. static char retval1[32];
  191. static char retval2[32];
  192. static int idx = 0;
  193. char *retval = (idx++ & 1) ? retval1 : retval2;
  194. char *ptr = retval;
  195. while (*str) {
  196. if (*str != '.') {
  197. *(ptr++) = *str;
  198. }
  199. str++;
  200. }
  201. *ptr = '\0';
  202. return retval;
  203. }
  204. static char *lowercase(const char *str) /* this is NOT robust. */
  205. {
  206. static char retval1[32];
  207. static char retval2[32];
  208. static int idx = 0;
  209. char *retval = (idx++ & 1) ? retval1 : retval2;
  210. char *ptr = retval;
  211. while (*str) {
  212. const char ch = *(str++);
  213. *(ptr++) = ((ch >= 'A') && (ch <= 'Z')) ? (ch - ('A' - 'a')) : ch;
  214. }
  215. *ptr = '\0';
  216. return retval;
  217. }
  218. static void write_converter(const int fromchans, const int tochans)
  219. {
  220. const char *fromstr = layout_names[fromchans-1];
  221. const char *tostr = layout_names[tochans-1];
  222. const float *cvtmatrix = channel_conversion_matrix[fromchans-1][tochans-1];
  223. const float *fptr;
  224. const int convert_backwards = (tochans > fromchans);
  225. int input_channel_used[NUM_CHANNELS];
  226. int i, j;
  227. if (tochans == fromchans) {
  228. return; /* nothing to convert, don't generate a converter. */
  229. }
  230. for (i = 0; i < fromchans; i++) {
  231. input_channel_used[i] = 0;
  232. }
  233. fptr = cvtmatrix;
  234. for (j = 0; j < tochans; j++) {
  235. for (i = 0; i < fromchans; i++) {
  236. #if 0
  237. printf("to=%d, from=%d, coeff=%f\n", j, i, *fptr);
  238. #endif
  239. if (*(fptr++) != 0.0f) {
  240. input_channel_used[i]++;
  241. }
  242. }
  243. }
  244. printf("static void SDLCALL\n"
  245. "SDL_Convert%sTo%s(SDL_AudioCVT *cvt, SDL_AudioFormat format)\n"
  246. "{\n", remove_dots(fromstr), remove_dots(tostr));
  247. if (convert_backwards) { /* must convert backwards when growing the output in-place. */
  248. printf(" float *dst = ((float *) (cvt->buf + ((cvt->len_cvt / %d) * %d))) - %d;\n", fromchans, tochans, tochans);
  249. printf(" const float *src = ((const float *) (cvt->buf + cvt->len_cvt)) - %d;\n", fromchans);
  250. } else {
  251. printf(" float *dst = (float *) cvt->buf;\n");
  252. printf(" const float *src = dst;\n");
  253. }
  254. printf(" int i;\n"
  255. "\n"
  256. " LOG_DEBUG_CONVERT(\"%s\", \"%s\");\n"
  257. " SDL_assert(format == AUDIO_F32SYS);\n"
  258. "\n", lowercase(fromstr), lowercase(tostr));
  259. if (convert_backwards) {
  260. printf(" /* convert backwards, since output is growing in-place. */\n");
  261. printf(" for (i = cvt->len_cvt / (sizeof (float) * %d); i; i--, src -= %d, dst -= %d) {\n", fromchans, fromchans, tochans);
  262. fptr = cvtmatrix;
  263. for (i = 0; i < fromchans; i++) {
  264. if (input_channel_used[i] > 1) { /* don't read it from src more than once. */
  265. printf(" const float src%s = src[%d];\n", channel_names[fromchans-1][i], i);
  266. }
  267. }
  268. for (j = tochans - 1; j >= 0; j--) {
  269. int has_input = 0;
  270. fptr = cvtmatrix + (fromchans * j);
  271. printf(" dst[%d] /* %s */ =", j, channel_names[tochans-1][j]);
  272. for (i = fromchans - 1; i >= 0; i--) {
  273. const float coefficient = fptr[i];
  274. char srcname[32];
  275. if (coefficient == 0.0f) {
  276. continue;
  277. } else if (input_channel_used[i] > 1) {
  278. snprintf(srcname, sizeof (srcname), "src%s", channel_names[fromchans-1][i]);
  279. } else {
  280. snprintf(srcname, sizeof (srcname), "src[%d]", i);
  281. }
  282. if (has_input) {
  283. printf(" +");
  284. }
  285. has_input = 1;
  286. if (coefficient == 1.0f) {
  287. printf(" %s", srcname);
  288. } else {
  289. printf(" (%s * %.9ff)", srcname, coefficient);
  290. }
  291. }
  292. if (!has_input) {
  293. printf(" 0.0f");
  294. }
  295. printf(";\n");
  296. }
  297. printf(" }\n");
  298. } else {
  299. printf(" for (i = cvt->len_cvt / (sizeof (float) * %d); i; i--, src += %d, dst += %d) {\n", fromchans, fromchans, tochans);
  300. fptr = cvtmatrix;
  301. for (i = 0; i < fromchans; i++) {
  302. if (input_channel_used[i] > 1) { /* don't read it from src more than once. */
  303. printf(" const float src%s = src[%d];\n", channel_names[fromchans-1][i], i);
  304. }
  305. }
  306. for (j = 0; j < tochans; j++) {
  307. int has_input = 0;
  308. fptr = cvtmatrix + (fromchans * j);
  309. printf(" dst[%d] /* %s */ =", j, channel_names[tochans-1][j]);
  310. for (i = 0; i < fromchans; i++) {
  311. const float coefficient = fptr[i];
  312. char srcname[32];
  313. if (coefficient == 0.0f) {
  314. continue;
  315. } else if (input_channel_used[i] > 1) {
  316. snprintf(srcname, sizeof (srcname), "src%s", channel_names[fromchans-1][i]);
  317. } else {
  318. snprintf(srcname, sizeof (srcname), "src[%d]", i);
  319. }
  320. if (has_input) {
  321. printf(" +");
  322. }
  323. has_input = 1;
  324. if (coefficient == 1.0f) {
  325. printf(" %s", srcname);
  326. } else {
  327. printf(" (%s * %.9ff)", srcname, coefficient);
  328. }
  329. }
  330. if (!has_input) {
  331. printf(" 0.0f");
  332. }
  333. printf(";\n");
  334. }
  335. printf(" }\n");
  336. }
  337. printf("\n");
  338. if ((fromchans > 1) && (tochans > 1)) {
  339. printf(" cvt->len_cvt = (cvt->len_cvt / %d) * %d;\n", fromchans, tochans);
  340. } else if (tochans == 1) {
  341. printf(" cvt->len_cvt = cvt->len_cvt / %d;\n", fromchans);
  342. } else /* if (fromchans == 1) */ {
  343. printf(" cvt->len_cvt = cvt->len_cvt * %d;\n", tochans);
  344. }
  345. printf(" if (cvt->filters[++cvt->filter_index]) {\n"
  346. " cvt->filters[cvt->filter_index] (cvt, format);\n"
  347. " }\n"
  348. "}\n\n");
  349. }
  350. int main(void)
  351. {
  352. int ini, outi;
  353. printf(
  354. "/*\n"
  355. " Simple DirectMedia Layer\n"
  356. " Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>\n"
  357. "\n"
  358. " This software is provided 'as-is', without any express or implied\n"
  359. " warranty. In no event will the authors be held liable for any damages\n"
  360. " arising from the use of this software.\n"
  361. "\n"
  362. " Permission is granted to anyone to use this software for any purpose,\n"
  363. " including commercial applications, and to alter it and redistribute it\n"
  364. " freely, subject to the following restrictions:\n"
  365. "\n"
  366. " 1. The origin of this software must not be misrepresented; you must not\n"
  367. " claim that you wrote the original software. If you use this software\n"
  368. " in a product, an acknowledgment in the product documentation would be\n"
  369. " appreciated but is not required.\n"
  370. " 2. Altered source versions must be plainly marked as such, and must not be\n"
  371. " misrepresented as being the original software.\n"
  372. " 3. This notice may not be removed or altered from any source distribution.\n"
  373. "*/\n"
  374. "\n"
  375. "/* DO NOT EDIT, THIS FILE WAS GENERATED BY build-scripts/gen_audio_channel_conversion.c */\n"
  376. "\n"
  377. );
  378. for (ini = 1; ini <= NUM_CHANNELS; ini++) {
  379. for (outi = 1; outi <= NUM_CHANNELS; outi++) {
  380. write_converter(ini, outi);
  381. }
  382. }
  383. printf("static const SDL_AudioFilter channel_converters[%d][%d] = { /* [from][to] */\n", NUM_CHANNELS, NUM_CHANNELS);
  384. for (ini = 1; ini <= NUM_CHANNELS; ini++) {
  385. const char *comma = "";
  386. printf(" {");
  387. for (outi = 1; outi <= NUM_CHANNELS; outi++) {
  388. const char *fromstr = layout_names[ini-1];
  389. const char *tostr = layout_names[outi-1];
  390. if (ini == outi) {
  391. printf("%s NULL", comma);
  392. } else {
  393. printf("%s SDL_Convert%sTo%s", comma, remove_dots(fromstr), remove_dots(tostr));
  394. }
  395. comma = ",";
  396. }
  397. printf(" }%s\n", (ini == NUM_CHANNELS) ? "" : ",");
  398. }
  399. printf("};\n\n");
  400. printf("/* vi: set ts=4 sw=4 expandtab: */\n\n");
  401. return 0;
  402. }
  403. /* vi: set ts=4 sw=4 expandtab: */