summaryrefslogtreecommitdiff
path: root/src/contrib/SDL-3.2.20/build-scripts/gen_audio_channel_conversion.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/contrib/SDL-3.2.20/build-scripts/gen_audio_channel_conversion.c')
-rw-r--r--src/contrib/SDL-3.2.20/build-scripts/gen_audio_channel_conversion.c461
1 files changed, 461 insertions, 0 deletions
diff --git a/src/contrib/SDL-3.2.20/build-scripts/gen_audio_channel_conversion.c b/src/contrib/SDL-3.2.20/build-scripts/gen_audio_channel_conversion.c
new file mode 100644
index 0000000..85a856e
--- /dev/null
+++ b/src/contrib/SDL-3.2.20/build-scripts/gen_audio_channel_conversion.c
@@ -0,0 +1,461 @@
1/*
2 Simple DirectMedia Layer
3 Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
4
5 This software is provided 'as-is', without any express or implied
6 warranty. In no event will the authors be held liable for any damages
7 arising from the use of this software.
8
9 Permission is granted to anyone to use this software for any purpose,
10 including commercial applications, and to alter it and redistribute it
11 freely, subject to the following restrictions:
12
13 1. The origin of this software must not be misrepresented; you must not
14 claim that you wrote the original software. If you use this software
15 in a product, an acknowledgment in the product documentation would be
16 appreciated but is not required.
17 2. Altered source versions must be plainly marked as such, and must not be
18 misrepresented as being the original software.
19 3. This notice may not be removed or altered from any source distribution.
20*/
21
22#include <stdio.h>
23
24/*
25
26Built with:
27
28gcc -o genchancvt build-scripts/gen_audio_channel_conversion.c -lm && ./genchancvt > src/audio/SDL_audio_channel_converters.h
29
30*/
31
32#define NUM_CHANNELS 8
33
34static const char *layout_names[NUM_CHANNELS] = {
35 "Mono", "Stereo", "2.1", "Quad", "4.1", "5.1", "6.1", "7.1"
36};
37
38static const char *channel_names[NUM_CHANNELS][NUM_CHANNELS] = {
39 /* mono */ { "FC" },
40 /* stereo */ { "FL", "FR" },
41 /* 2.1 */ { "FL", "FR", "LFE" },
42 /* quad */ { "FL", "FR", "BL", "BR" },
43 /* 4.1 */ { "FL", "FR", "LFE", "BL", "BR" },
44 /* 5.1 */ { "FL", "FR", "FC", "LFE", "BL", "BR" },
45 /* 6.1 */ { "FL", "FR", "FC", "LFE", "BC", "SL", "SR" },
46 /* 7.1 */ { "FL", "FR", "FC", "LFE", "BL", "BR", "SL", "SR" },
47};
48
49
50/*
51 * This table is from FAudio:
52 *
53 * https://raw.githubusercontent.com/FNA-XNA/FAudio/master/src/matrix_defaults.inl
54 */
55static const float channel_conversion_matrix[8][8][64] = {
56{
57 /* 1 x 1 */
58 { 1.000000000f },
59 /* 1 x 2 */
60 { 1.000000000f, 1.000000000f },
61 /* 1 x 3 */
62 { 1.000000000f, 1.000000000f, 0.000000000f },
63 /* 1 x 4 */
64 { 1.000000000f, 1.000000000f, 0.000000000f, 0.000000000f },
65 /* 1 x 5 */
66 { 1.000000000f, 1.000000000f, 0.000000000f, 0.000000000f, 0.000000000f },
67 /* 1 x 6 */
68 { 1.000000000f, 1.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f },
69 /* 1 x 7 */
70 { 1.000000000f, 1.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f },
71 /* 1 x 8 */
72 { 1.000000000f, 1.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f }
73},
74{
75 /* 2 x 1 */
76 { 0.500000000f, 0.500000000f },
77 /* 2 x 2 */
78 { 1.000000000f, 0.000000000f, 0.000000000f, 1.000000000f },
79 /* 2 x 3 */
80 { 1.000000000f, 0.000000000f, 0.000000000f, 1.000000000f, 0.000000000f, 0.000000000f },
81 /* 2 x 4 */
82 { 1.000000000f, 0.000000000f, 0.000000000f, 1.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f },
83 /* 2 x 5 */
84 { 1.000000000f, 0.000000000f, 0.000000000f, 1.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f },
85 /* 2 x 6 */
86 { 1.000000000f, 0.000000000f, 0.000000000f, 1.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f },
87 /* 2 x 7 */
88 { 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 },
89 /* 2 x 8 */
90 { 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 }
91},
92{
93 /* 3 x 1 */
94 { 0.333333343f, 0.333333343f, 0.333333343f },
95 /* 3 x 2 */
96 { 0.800000012f, 0.000000000f, 0.200000003f, 0.000000000f, 0.800000012f, 0.200000003f },
97 /* 3 x 3 */
98 { 1.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 1.000000000f, 0.000000000f, 0.000000000f, 0.000000000f, 1.000000000f },
99 /* 3 x 4 */
100 { 0.888888896f, 0.000000000f, 0.111111112f, 0.000000000f, 0.888888896f, 0.111111112f, 0.000000000f, 0.000000000f, 0.111111112f, 0.000000000f, 0.000000000f, 0.111111112f },
101 /* 3 x 5 */
102 { 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 },
103 /* 3 x 6 */
104 { 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 },
105 /* 3 x 7 */
106 { 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 },
107 /* 3 x 8 */
108 { 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 }
109},
110{
111 /* 4 x 1 */
112 { 0.250000000f, 0.250000000f, 0.250000000f, 0.250000000f },
113 /* 4 x 2 */
114 { 0.421000004f, 0.000000000f, 0.358999997f, 0.219999999f, 0.000000000f, 0.421000004f, 0.219999999f, 0.358999997f },
115 /* 4 x 3 */
116 { 0.421000004f, 0.000000000f, 0.358999997f, 0.219999999f, 0.000000000f, 0.421000004f, 0.219999999f, 0.358999997f, 0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f },
117 /* 4 x 4 */
118 { 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 },
119 /* 4 x 5 */
120 { 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 },
121 /* 4 x 6 */
122 { 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 },
123 /* 4 x 7 */
124 { 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 },
125 /* 4 x 8 */
126 { 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 }
127},
128{
129 /* 5 x 1 */
130 { 0.200000003f, 0.200000003f, 0.200000003f, 0.200000003f, 0.200000003f },
131 /* 5 x 2 */
132 { 0.374222219f, 0.000000000f, 0.111111112f, 0.319111109f, 0.195555553f, 0.000000000f, 0.374222219f, 0.111111112f, 0.195555553f, 0.319111109f },
133 /* 5 x 3 */
134 { 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 },
135 /* 5 x 4 */
136 { 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 },
137 /* 5 x 5 */
138 { 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 },
139 /* 5 x 6 */
140 { 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 },
141 /* 5 x 7 */
142 { 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 },
143 /* 5 x 8 */
144 { 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 }
145},
146{
147 /* 6 x 1 */
148 { 0.166666672f, 0.166666672f, 0.166666672f, 0.166666672f, 0.166666672f, 0.166666672f },
149 /* 6 x 2 */
150 { 0.294545442f, 0.000000000f, 0.208181813f, 0.090909094f, 0.251818180f, 0.154545456f, 0.000000000f, 0.294545442f, 0.208181813f, 0.090909094f, 0.154545456f, 0.251818180f },
151 /* 6 x 3 */
152 { 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 },
153 /* 6 x 4 */
154 { 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 },
155 /* 6 x 5 */
156 { 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 },
157 /* 6 x 6 */
158 { 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 },
159 /* 6 x 7 */
160 { 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 },
161 /* 6 x 8 */
162 { 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 }
163},
164{
165 /* 7 x 1 */
166 { 0.143142849f, 0.143142849f, 0.143142849f, 0.142857149f, 0.143142849f, 0.143142849f, 0.143142849f },
167 /* 7 x 2 */
168 { 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 },
169 /* 7 x 3 */
170 { 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 },
171 /* 7 x 4 */
172 { 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 },
173 /* 7 x 5 */
174 { 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 },
175 /* 7 x 6 */
176 { 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 },
177 /* 7 x 7 */
178 { 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 },
179 /* 7 x 8 */
180 { 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 }
181},
182{
183 /* 8 x 1 */
184 { 0.125125006f, 0.125125006f, 0.125125006f, 0.125000000f, 0.125125006f, 0.125125006f, 0.125125006f, 0.125125006f },
185 /* 8 x 2 */
186 { 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 },
187 /* 8 x 3 */
188 { 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 },
189 /* 8 x 4 */
190 { 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 },
191 /* 8 x 5 */
192 { 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 },
193 /* 8 x 6 */
194 { 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 },
195 /* 8 x 7 */
196 { 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 },
197 /* 8 x 8 */
198 { 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 }
199}
200};
201
202static char *remove_dots(const char *str) /* this is NOT robust. */
203{
204 static char retval1[32];
205 static char retval2[32];
206 static int idx = 0;
207 char *retval = (idx++ & 1) ? retval1 : retval2;
208 char *ptr = retval;
209 while (*str) {
210 if (*str != '.') {
211 *(ptr++) = *str;
212 }
213 str++;
214 }
215 *ptr = '\0';
216 return retval;
217}
218
219static char *lowercase(const char *str) /* this is NOT robust. */
220{
221 static char retval1[32];
222 static char retval2[32];
223 static int idx = 0;
224 char *retval = (idx++ & 1) ? retval1 : retval2;
225 char *ptr = retval;
226 while (*str) {
227 const char ch = *(str++);
228 *(ptr++) = ((ch >= 'A') && (ch <= 'Z')) ? (ch - ('A' - 'a')) : ch;
229 }
230 *ptr = '\0';
231 return retval;
232}
233
234static void write_converter(const int fromchans, const int tochans)
235{
236 const char *fromstr = layout_names[fromchans-1];
237 const char *tostr = layout_names[tochans-1];
238 const float *cvtmatrix = channel_conversion_matrix[fromchans-1][tochans-1];
239 const float *fptr;
240 const int convert_backwards = (tochans > fromchans);
241 int input_channel_used[NUM_CHANNELS];
242 int i, j;
243
244 if (tochans == fromchans) {
245 return; /* nothing to convert, don't generate a converter. */
246 }
247
248 for (i = 0; i < fromchans; i++) {
249 input_channel_used[i] = 0;
250 }
251
252 fptr = cvtmatrix;
253 for (j = 0; j < tochans; j++) {
254 for (i = 0; i < fromchans; i++) {
255 #if 0
256 printf("to=%d, from=%d, coeff=%f\n", j, i, *fptr);
257 #endif
258 if (*(fptr++) != 0.0f) {
259 input_channel_used[i]++;
260 }
261 }
262 }
263
264 printf("static void SDL_Convert%sTo%s(float *dst, const float *src, int num_frames)\n{\n", remove_dots(fromstr), remove_dots(tostr));
265
266 printf(" int i;\n"
267 "\n"
268 " LOG_DEBUG_AUDIO_CONVERT(\"%s\", \"%s\");\n"
269 "\n", lowercase(fromstr), lowercase(tostr));
270
271 if (convert_backwards) { /* must convert backwards when growing the output in-place. */
272 printf(" // convert backwards, since output is growing in-place.\n");
273 printf(" src += (num_frames-1)");
274 if (fromchans != 1) {
275 printf(" * %d", fromchans);
276 }
277 printf(";\n");
278
279 printf(" dst += (num_frames-1)");
280 if (tochans != 1) {
281 printf(" * %d", tochans);
282 }
283 printf(";\n");
284 printf(" for (i = num_frames; i; i--, ");
285 if (fromchans == 1) {
286 printf("src--");
287 } else {
288 printf("src -= %d", fromchans);
289 }
290 printf(", ");
291 if (tochans == 1) {
292 printf("dst--");
293 } else {
294 printf("dst -= %d", tochans);
295 }
296 printf(") {\n");
297 fptr = cvtmatrix;
298 for (i = 0; i < fromchans; i++) {
299 if (input_channel_used[i] > 1) { /* don't read it from src more than once. */
300 printf(" const float src%s = src[%d];\n", channel_names[fromchans-1][i], i);
301 }
302 }
303
304 for (j = tochans - 1; j >= 0; j--) {
305 int has_input = 0;
306 fptr = cvtmatrix + (fromchans * j);
307 printf(" dst[%d] /* %s */ =", j, channel_names[tochans-1][j]);
308 for (i = fromchans - 1; i >= 0; i--) {
309 const float coefficient = fptr[i];
310 char srcname[32];
311 if (coefficient == 0.0f) {
312 continue;
313 } else if (input_channel_used[i] > 1) {
314 snprintf(srcname, sizeof (srcname), "src%s", channel_names[fromchans-1][i]);
315 } else {
316 snprintf(srcname, sizeof (srcname), "src[%d]", i);
317 }
318
319 if (has_input) {
320 printf(" +");
321 }
322
323 has_input = 1;
324
325 if (coefficient == 1.0f) {
326 printf(" %s", srcname);
327 } else {
328 printf(" (%s * %.9ff)", srcname, coefficient);
329 }
330 }
331
332 if (!has_input) {
333 printf(" 0.0f");
334 }
335
336 printf(";\n");
337 }
338
339 printf(" }\n");
340 } else {
341 printf(" for (i = num_frames; i; i--, ");
342 if (fromchans == 1) {
343 printf("src++");
344 } else {
345 printf("src += %d", fromchans);
346 }
347 printf(", ");
348 if (tochans == 1) {
349 printf("dst++");
350 } else {
351 printf("dst += %d", tochans);
352 }
353 printf(") {\n");
354
355 fptr = cvtmatrix;
356 for (i = 0; i < fromchans; i++) {
357 if (input_channel_used[i] > 1) { /* don't read it from src more than once. */
358 printf(" const float src%s = src[%d];\n", channel_names[fromchans-1][i], i);
359 }
360 }
361
362 for (j = 0; j < tochans; j++) {
363 int has_input = 0;
364 fptr = cvtmatrix + (fromchans * j);
365 printf(" dst[%d] /* %s */ =", j, channel_names[tochans-1][j]);
366 for (i = 0; i < fromchans; i++) {
367 const float coefficient = fptr[i];
368 char srcname[32];
369 if (coefficient == 0.0f) {
370 continue;
371 } else if (input_channel_used[i] > 1) {
372 snprintf(srcname, sizeof (srcname), "src%s", channel_names[fromchans-1][i]);
373 } else {
374 snprintf(srcname, sizeof (srcname), "src[%d]", i);
375 }
376
377 if (has_input) {
378 printf(" +");
379 }
380
381 has_input = 1;
382
383 if (coefficient == 1.0f) {
384 printf(" %s", srcname);
385 } else {
386 printf(" (%s * %.9ff)", srcname, coefficient);
387 }
388 }
389
390 if (!has_input) {
391 printf(" 0.0f");
392 }
393
394 printf(";\n");
395 }
396 printf(" }\n");
397 }
398
399 printf("\n}\n\n");
400}
401
402int main(void)
403{
404 int ini, outi;
405
406 printf(
407 "/*\n"
408 " Simple DirectMedia Layer\n"
409 " Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>\n"
410 "\n"
411 " This software is provided 'as-is', without any express or implied\n"
412 " warranty. In no event will the authors be held liable for any damages\n"
413 " arising from the use of this software.\n"
414 "\n"
415 " Permission is granted to anyone to use this software for any purpose,\n"
416 " including commercial applications, and to alter it and redistribute it\n"
417 " freely, subject to the following restrictions:\n"
418 "\n"
419 " 1. The origin of this software must not be misrepresented; you must not\n"
420 " claim that you wrote the original software. If you use this software\n"
421 " in a product, an acknowledgment in the product documentation would be\n"
422 " appreciated but is not required.\n"
423 " 2. Altered source versions must be plainly marked as such, and must not be\n"
424 " misrepresented as being the original software.\n"
425 " 3. This notice may not be removed or altered from any source distribution.\n"
426 "*/\n"
427 "\n"
428 "// DO NOT EDIT, THIS FILE WAS GENERATED BY build-scripts/gen_audio_channel_conversion.c\n"
429 "\n"
430 "\n"
431 "typedef void (*SDL_AudioChannelConverter)(float *dst, const float *src, int num_frames);\n"
432 "\n"
433 );
434
435 for (ini = 1; ini <= NUM_CHANNELS; ini++) {
436 for (outi = 1; outi <= NUM_CHANNELS; outi++) {
437 write_converter(ini, outi);
438 }
439 }
440
441 printf("static const SDL_AudioChannelConverter channel_converters[%d][%d] = { /* [from][to] */\n", NUM_CHANNELS, NUM_CHANNELS);
442 for (ini = 1; ini <= NUM_CHANNELS; ini++) {
443 const char *comma = "";
444 printf(" {");
445 for (outi = 1; outi <= NUM_CHANNELS; outi++) {
446 const char *fromstr = layout_names[ini-1];
447 const char *tostr = layout_names[outi-1];
448 if (ini == outi) {
449 printf("%s NULL", comma);
450 } else {
451 printf("%s SDL_Convert%sTo%s", comma, remove_dots(fromstr), remove_dots(tostr));
452 }
453 comma = ",";
454 }
455 printf(" }%s\n", (ini == NUM_CHANNELS) ? "" : ",");
456 }
457
458 printf("};\n\n");
459
460 return 0;
461}