Debian Codegraph @

src/pt2_downsample2x.c

raw symbols SCIP
1 #cxx . . $ `<file>/src/pt2_downsample2x.c`/include <stdint.h>
2 #include <stdbool.h>
3 #include <stdlib.h>
4 #include <math.h>
5 #include "pt2_config.h"cxx . . $ `<file>/src/pt2_config.h`/ // config.maxSampleLength
6
7 #define NUM_TAPScxx . . $ `src/pt2_downsample2x.c:7:9`! 59 /* should be 4m+3 (3, 7, 11, 15, 19, ...) */
8 #define CENTER_TAPcxx . . $ `src/pt2_downsample2x.c:8:9`! ((NUM_TAPScxx . . $ `src/pt2_downsample2x.c:7:9`! - 1) / 2)
9
10 // half-band FIR coeffs (Remez algorithm - numtaps=59, bands=[0.0, 0.2, 0.3, 0.5], desired=[1.0, 0.0])
11 #define C00cxx . . $ `src/pt2_downsample2x.c:11:9`! 0.50000000000000f
12 #define C01cxx . . $ `src/pt2_downsample2x.c:12:9`! 0.31679609962928f
13 #define C03cxx . . $ `src/pt2_downsample2x.c:13:9`! -0.10163877066856f
14 #define C05cxx . . $ `src/pt2_downsample2x.c:14:9`! 0.05646939759172f
15 #define C07cxx . . $ `src/pt2_downsample2x.c:15:9`! -0.03589869172828f
16 #define C09cxx . . $ `src/pt2_downsample2x.c:16:9`! 0.02384893442862f
17 #define C11cxx . . $ `src/pt2_downsample2x.c:17:9`! -0.01596102646846f
18 #define C13cxx . . $ `src/pt2_downsample2x.c:18:9`! 0.01054794795196f
19 #define C15cxx . . $ `src/pt2_downsample2x.c:19:9`! -0.00678935474634f
20 #define C17cxx . . $ `src/pt2_downsample2x.c:20:9`! 0.00420731862183f
21 #define C19cxx . . $ `src/pt2_downsample2x.c:21:9`! -0.00248066436637f
22 #define C21cxx . . $ `src/pt2_downsample2x.c:22:9`! 0.00137207386220f
23 #define C23cxx . . $ `src/pt2_downsample2x.c:23:9`! -0.00069823637245f
24 #define C25cxx . . $ `src/pt2_downsample2x.c:24:9`! 0.00031710491117f
25 #define C27cxx . . $ `src/pt2_downsample2x.c:25:9`! -0.00012143320790f
26 #define C29cxx . . $ `src/pt2_downsample2x.c:26:9`! 0.00003501888526f
27
28 /* Python code for generating the Cxx coefficient constants:
29 **
30 ** import scipy
31 **
32 ** numtaps = 59 # should be 4m+3 (3, 7, 11, 15, 19, ...)
33 ** bands = [0.0, 0.2, 0.3, 0.5]
34 ** desired = [1.0, 0.0]
35 ** h = scipy.signal.remez(numtaps, bands, desired)
36 **
37 ** print('#define C00 % .14ff' % h[(numtaps-1)//2])
38 ** for i in range(1+(numtaps//4)):
39 ** print('#define C%02d % .14ff' % (1+(i*2), h[((numtaps-1)//2)+1+(i*2)]))
40 */
41
42 // ----------------------------------------------------------
43 // 2x downsampler for main audio mixer (simpler/faster, but has output sample delay)
44 // ----------------------------------------------------------
45
46 static float t01_Lcxx . . $ t01_L.,t02_Lcxx . . $ t02_L.,t03_Lcxx . . $ t03_L.,t04_Lcxx . . $ t04_L.,t05_Lcxx . . $ t05_L.,t06_Lcxx . . $ t06_L.,t07_Lcxx . . $ t07_L.,t08_Lcxx . . $ t08_L.,t09_Lcxx . . $ t09_L.,t10_Lcxx . . $ t10_L.,t11_Lcxx . . $ t11_L.,t12_Lcxx . . $ t12_L.,t13_Lcxx . . $ t13_L.,t14_Lcxx . . $ t14_L.;
47 static float t15_Lcxx . . $ t15_L.,t16_Lcxx . . $ t16_L.,t17_Lcxx . . $ t17_L.,t18_Lcxx . . $ t18_L.,t19_Lcxx . . $ t19_L.,t20_Lcxx . . $ t20_L.,t21_Lcxx . . $ t21_L.,t22_Lcxx . . $ t22_L.,t23_Lcxx . . $ t23_L.,t24_Lcxx . . $ t24_L.,t25_Lcxx . . $ t25_L.,t26_Lcxx . . $ t26_L.,t27_Lcxx . . $ t27_L.,t28_Lcxx . . $ t28_L.,t29_Lcxx . . $ t29_L.;
48 static float t01_Rcxx . . $ t01_R.,t02_Rcxx . . $ t02_R.,t03_Rcxx . . $ t03_R.,t04_Rcxx . . $ t04_R.,t05_Rcxx . . $ t05_R.,t06_Rcxx . . $ t06_R.,t07_Rcxx . . $ t07_R.,t08_Rcxx . . $ t08_R.,t09_Rcxx . . $ t09_R.,t10_Rcxx . . $ t10_R.,t11_Rcxx . . $ t11_R.,t12_Rcxx . . $ t12_R.,t13_Rcxx . . $ t13_R.,t14_Rcxx . . $ t14_R.;
49 static float t15_Rcxx . . $ t15_R.,t16_Rcxx . . $ t16_R.,t17_Rcxx . . $ t17_R.,t18_Rcxx . . $ t18_R.,t19_Rcxx . . $ t19_R.,t20_Rcxx . . $ t20_R.,t21_Rcxx . . $ t21_R.,t22_Rcxx . . $ t22_R.,t23_Rcxx . . $ t23_R.,t24_Rcxx . . $ t24_R.,t25_Rcxx . . $ t25_R.,t26_Rcxx . . $ t26_R.,t27_Rcxx . . $ t27_R.,t28_Rcxx . . $ t28_R.,t29_Rcxx . . $ t29_R.;
50
51 void clearDownsample2xStatescxx . . $ clearDownsample2xStates(49f6e7a06ebc5aa8).(void)
52 {
53 t01_Lcxx . . $ t01_L.=t02_Lcxx . . $ t02_L.=t03_Lcxx . . $ t03_L.=t04_Lcxx . . $ t04_L.=t05_Lcxx . . $ t05_L.=t06_Lcxx . . $ t06_L.=t07_Lcxx . . $ t07_L.=t08_Lcxx . . $ t08_L.=t09_Lcxx . . $ t09_L.=t10_Lcxx . . $ t10_L.=t11_Lcxx . . $ t11_L.=t12_Lcxx . . $ t12_L.=t13_Lcxx . . $ t13_L.=t14_Lcxx . . $ t14_L.=
54 t15_Lcxx . . $ t15_L.=t16_Lcxx . . $ t16_L.=t17_Lcxx . . $ t17_L.=t18_Lcxx . . $ t18_L.=t19_Lcxx . . $ t19_L.=t20_Lcxx . . $ t20_L.=t21_Lcxx . . $ t21_L.=t22_Lcxx . . $ t22_L.=t23_Lcxx . . $ t23_L.=t24_Lcxx . . $ t24_L.=t25_Lcxx . . $ t25_L.=t26_Lcxx . . $ t26_L.=t27_Lcxx . . $ t27_L.=t28_Lcxx . . $ t28_L.=t29_Lcxx . . $ t29_L. = 0.0f;
55
56 t01_Rcxx . . $ t01_R.=t02_Rcxx . . $ t02_R.=t03_Rcxx . . $ t03_R.=t04_Rcxx . . $ t04_R.=t05_Rcxx . . $ t05_R.=t06_Rcxx . . $ t06_R.=t07_Rcxx . . $ t07_R.=t08_Rcxx . . $ t08_R.=t09_Rcxx . . $ t09_R.=t10_Rcxx . . $ t10_R.=t11_Rcxx . . $ t11_R.=t12_Rcxx . . $ t12_R.=t13_Rcxx . . $ t13_R.=t14_Rcxx . . $ t14_R.=
57 t15_Rcxx . . $ t15_R.=t16_Rcxx . . $ t16_R.=t17_Rcxx . . $ t17_R.=t18_Rcxx . . $ t18_R.=t19_Rcxx . . $ t19_R.=t20_Rcxx . . $ t20_R.=t21_Rcxx . . $ t21_R.=t22_Rcxx . . $ t22_R.=t23_Rcxx . . $ t23_R.=t24_Rcxx . . $ t24_R.=t25_Rcxx . . $ t25_R.=t26_Rcxx . . $ t26_R.=t27_Rcxx . . $ t27_R.=t28_Rcxx . . $ t28_R.=t29_Rcxx . . $ t29_R. = 0.0f;
58 }
59
60 float downsample2x_Lcxx . . $ downsample2x_L(d59a45cd3bfd2eda).(float sample1, float sample2)
61 {
62 const float x00 = sample2 * C00cxx . . $ `src/pt2_downsample2x.c:11:9`!, x01 = sample1 * C01cxx . . $ `src/pt2_downsample2x.c:12:9`!;
63 const float x03 = sample1 * C03cxx . . $ `src/pt2_downsample2x.c:13:9`!, x05 = sample1 * C05cxx . . $ `src/pt2_downsample2x.c:14:9`!;
64 const float x07 = sample1 * C07cxx . . $ `src/pt2_downsample2x.c:15:9`!, x09 = sample1 * C09cxx . . $ `src/pt2_downsample2x.c:16:9`!;
65 const float x11 = sample1 * C11cxx . . $ `src/pt2_downsample2x.c:17:9`!, x13 = sample1 * C13cxx . . $ `src/pt2_downsample2x.c:18:9`!;
66 const float x15 = sample1 * C15cxx . . $ `src/pt2_downsample2x.c:19:9`!, x17 = sample1 * C17cxx . . $ `src/pt2_downsample2x.c:20:9`!;
67 const float x19 = sample1 * C19cxx . . $ `src/pt2_downsample2x.c:21:9`!, x21 = sample1 * C21cxx . . $ `src/pt2_downsample2x.c:22:9`!;
68 const float x23 = sample1 * C23cxx . . $ `src/pt2_downsample2x.c:23:9`!, x25 = sample1 * C25cxx . . $ `src/pt2_downsample2x.c:24:9`!;
69 const float x27 = sample1 * C27cxx . . $ `src/pt2_downsample2x.c:25:9`!, x29 = sample1 * C29cxx . . $ `src/pt2_downsample2x.c:26:9`!;
70
71 const float out = t29_Lcxx . . $ t29_L. + x29;
72
73 t29_Lcxx . . $ t29_L. = t28_Lcxx . . $ t28_L. + x27;
74 t28_Lcxx . . $ t28_L. = t27_Lcxx . . $ t27_L. + x25;
75 t27_Lcxx . . $ t27_L. = t26_Lcxx . . $ t26_L. + x23;
76 t26_Lcxx . . $ t26_L. = t25_Lcxx . . $ t25_L. + x21;
77 t25_Lcxx . . $ t25_L. = t24_Lcxx . . $ t24_L. + x19;
78 t24_Lcxx . . $ t24_L. = t23_Lcxx . . $ t23_L. + x17;
79 t23_Lcxx . . $ t23_L. = t22_Lcxx . . $ t22_L. + x15;
80 t22_Lcxx . . $ t22_L. = t21_Lcxx . . $ t21_L. + x13;
81 t21_Lcxx . . $ t21_L. = t20_Lcxx . . $ t20_L. + x11;
82 t20_Lcxx . . $ t20_L. = t19_Lcxx . . $ t19_L. + x09;
83 t19_Lcxx . . $ t19_L. = t18_Lcxx . . $ t18_L. + x07;
84 t18_Lcxx . . $ t18_L. = t17_Lcxx . . $ t17_L. + x05;
85 t17_Lcxx . . $ t17_L. = t16_Lcxx . . $ t16_L. + x03;
86 t16_Lcxx . . $ t16_L. = t15_Lcxx . . $ t15_L. + x01;
87 t15_Lcxx . . $ t15_L. = t14_Lcxx . . $ t14_L. + x01 + x00;
88 t14_Lcxx . . $ t14_L. = t13_Lcxx . . $ t13_L. + x03;
89 t13_Lcxx . . $ t13_L. = t12_Lcxx . . $ t12_L. + x05;
90 t12_Lcxx . . $ t12_L. = t11_Lcxx . . $ t11_L. + x07;
91 t11_Lcxx . . $ t11_L. = t10_Lcxx . . $ t10_L. + x09;
92 t10_Lcxx . . $ t10_L. = t09_Lcxx . . $ t09_L. + x11;
93 t09_Lcxx . . $ t09_L. = t08_Lcxx . . $ t08_L. + x13;
94 t08_Lcxx . . $ t08_L. = t07_Lcxx . . $ t07_L. + x15;
95 t07_Lcxx . . $ t07_L. = t06_Lcxx . . $ t06_L. + x17;
96 t06_Lcxx . . $ t06_L. = t05_Lcxx . . $ t05_L. + x19;
97 t05_Lcxx . . $ t05_L. = t04_Lcxx . . $ t04_L. + x21;
98 t04_Lcxx . . $ t04_L. = t03_Lcxx . . $ t03_L. + x23;
99 t03_Lcxx . . $ t03_L. = t02_Lcxx . . $ t02_L. + x25;
100 t02_Lcxx . . $ t02_L. = t01_Lcxx . . $ t01_L. + x27;
101 t01_Lcxx . . $ t01_L. = x29;
102
103 return out;
104 }
105
106 float downsample2x_Rcxx . . $ downsample2x_R(d59a45cd3bfd2eda).(float sample1, float sample2)
107 {
108 const float x00 = sample2 * C00cxx . . $ `src/pt2_downsample2x.c:11:9`!, x01 = sample1 * C01cxx . . $ `src/pt2_downsample2x.c:12:9`!;
109 const float x03 = sample1 * C03cxx . . $ `src/pt2_downsample2x.c:13:9`!, x05 = sample1 * C05cxx . . $ `src/pt2_downsample2x.c:14:9`!;
110 const float x07 = sample1 * C07cxx . . $ `src/pt2_downsample2x.c:15:9`!, x09 = sample1 * C09cxx . . $ `src/pt2_downsample2x.c:16:9`!;
111 const float x11 = sample1 * C11cxx . . $ `src/pt2_downsample2x.c:17:9`!, x13 = sample1 * C13cxx . . $ `src/pt2_downsample2x.c:18:9`!;
112 const float x15 = sample1 * C15cxx . . $ `src/pt2_downsample2x.c:19:9`!, x17 = sample1 * C17cxx . . $ `src/pt2_downsample2x.c:20:9`!;
113 const float x19 = sample1 * C19cxx . . $ `src/pt2_downsample2x.c:21:9`!, x21 = sample1 * C21cxx . . $ `src/pt2_downsample2x.c:22:9`!;
114 const float x23 = sample1 * C23cxx . . $ `src/pt2_downsample2x.c:23:9`!, x25 = sample1 * C25cxx . . $ `src/pt2_downsample2x.c:24:9`!;
115 const float x27 = sample1 * C27cxx . . $ `src/pt2_downsample2x.c:25:9`!, x29 = sample1 * C29cxx . . $ `src/pt2_downsample2x.c:26:9`!;
116
117 const float out = t29_Rcxx . . $ t29_R. + x29;
118
119 t29_Rcxx . . $ t29_R. = t28_Rcxx . . $ t28_R. + x27;
120 t28_Rcxx . . $ t28_R. = t27_Rcxx . . $ t27_R. + x25;
121 t27_Rcxx . . $ t27_R. = t26_Rcxx . . $ t26_R. + x23;
122 t26_Rcxx . . $ t26_R. = t25_Rcxx . . $ t25_R. + x21;
123 t25_Rcxx . . $ t25_R. = t24_Rcxx . . $ t24_R. + x19;
124 t24_Rcxx . . $ t24_R. = t23_Rcxx . . $ t23_R. + x17;
125 t23_Rcxx . . $ t23_R. = t22_Rcxx . . $ t22_R. + x15;
126 t22_Rcxx . . $ t22_R. = t21_Rcxx . . $ t21_R. + x13;
127 t21_Rcxx . . $ t21_R. = t20_Rcxx . . $ t20_R. + x11;
128 t20_Rcxx . . $ t20_R. = t19_Rcxx . . $ t19_R. + x09;
129 t19_Rcxx . . $ t19_R. = t18_Rcxx . . $ t18_R. + x07;
130 t18_Rcxx . . $ t18_R. = t17_Rcxx . . $ t17_R. + x05;
131 t17_Rcxx . . $ t17_R. = t16_Rcxx . . $ t16_R. + x03;
132 t16_Rcxx . . $ t16_R. = t15_Rcxx . . $ t15_R. + x01;
133 t15_Rcxx . . $ t15_R. = t14_Rcxx . . $ t14_R. + x01 + x00;
134 t14_Rcxx . . $ t14_R. = t13_Rcxx . . $ t13_R. + x03;
135 t13_Rcxx . . $ t13_R. = t12_Rcxx . . $ t12_R. + x05;
136 t12_Rcxx . . $ t12_R. = t11_Rcxx . . $ t11_R. + x07;
137 t11_Rcxx . . $ t11_R. = t10_Rcxx . . $ t10_R. + x09;
138 t10_Rcxx . . $ t10_R. = t09_Rcxx . . $ t09_R. + x11;
139 t09_Rcxx . . $ t09_R. = t08_Rcxx . . $ t08_R. + x13;
140 t08_Rcxx . . $ t08_R. = t07_Rcxx . . $ t07_R. + x15;
141 t07_Rcxx . . $ t07_R. = t06_Rcxx . . $ t06_R. + x17;
142 t06_Rcxx . . $ t06_R. = t05_Rcxx . . $ t05_R. + x19;
143 t05_Rcxx . . $ t05_R. = t04_Rcxx . . $ t04_R. + x21;
144 t04_Rcxx . . $ t04_R. = t03_Rcxx . . $ t03_R. + x23;
145 t03_Rcxx . . $ t03_R. = t02_Rcxx . . $ t02_R. + x25;
146 t02_Rcxx . . $ t02_R. = t01_Rcxx . . $ t01_R. + x27;
147 t01_Rcxx . . $ t01_R. = x29;
148
149 return out;
150 }
151
152 // ----------------------------------------------------------
153 // 2x downsamplers for sample loaders
154 // ----------------------------------------------------------
155
156 static const float fHalfbandKernelcxx . . $ fHalfbandKernel.[NUM_TAPScxx . . $ `src/pt2_downsample2x.c:7:9`!] =
157 {
158 C29cxx . . $ `src/pt2_downsample2x.c:26:9`!, 0.0f,
159 C27cxx . . $ `src/pt2_downsample2x.c:25:9`!, 0.0f,
160 C25cxx . . $ `src/pt2_downsample2x.c:24:9`!, 0.0f,
161 C23cxx . . $ `src/pt2_downsample2x.c:23:9`!, 0.0f,
162 C21cxx . . $ `src/pt2_downsample2x.c:22:9`!, 0.0f,
163 C19cxx . . $ `src/pt2_downsample2x.c:21:9`!, 0.0f,
164 C17cxx . . $ `src/pt2_downsample2x.c:20:9`!, 0.0f,
165 C15cxx . . $ `src/pt2_downsample2x.c:19:9`!, 0.0f,
166 C13cxx . . $ `src/pt2_downsample2x.c:18:9`!, 0.0f,
167 C11cxx . . $ `src/pt2_downsample2x.c:17:9`!, 0.0f,
168 C09cxx . . $ `src/pt2_downsample2x.c:16:9`!, 0.0f,
169 C07cxx . . $ `src/pt2_downsample2x.c:15:9`!, 0.0f,
170 C05cxx . . $ `src/pt2_downsample2x.c:14:9`!, 0.0f,
171 C03cxx . . $ `src/pt2_downsample2x.c:13:9`!, 0.0f,
172 C01cxx . . $ `src/pt2_downsample2x.c:12:9`!, C00cxx . . $ `src/pt2_downsample2x.c:11:9`!,
173 C01cxx . . $ `src/pt2_downsample2x.c:12:9`!, 0.0f,
174 C03cxx . . $ `src/pt2_downsample2x.c:13:9`!, 0.0f,
175 C05cxx . . $ `src/pt2_downsample2x.c:14:9`!, 0.0f,
176 C07cxx . . $ `src/pt2_downsample2x.c:15:9`!, 0.0f,
177 C09cxx . . $ `src/pt2_downsample2x.c:16:9`!, 0.0f,
178 C11cxx . . $ `src/pt2_downsample2x.c:17:9`!, 0.0f,
179 C13cxx . . $ `src/pt2_downsample2x.c:18:9`!, 0.0f,
180 C15cxx . . $ `src/pt2_downsample2x.c:19:9`!, 0.0f,
181 C17cxx . . $ `src/pt2_downsample2x.c:20:9`!, 0.0f,
182 C19cxx . . $ `src/pt2_downsample2x.c:21:9`!, 0.0f,
183 C21cxx . . $ `src/pt2_downsample2x.c:22:9`!, 0.0f,
184 C23cxx . . $ `src/pt2_downsample2x.c:23:9`!, 0.0f,
185 C25cxx . . $ `src/pt2_downsample2x.c:24:9`!, 0.0f,
186 C27cxx . . $ `src/pt2_downsample2x.c:25:9`!, 0.0f,
187 C29cxx . . $ `src/pt2_downsample2x.c:26:9`!
188 };
189
190 static double dDownsample2xcxx . . $ dDownsample2x(23d7d816a227b587).(double *fSamples, int32_tcxx . . $ int32_t# offset, int32_tcxx . . $ int32_t# sampleLength)
191 {
192 double dVal = 0.0;
193 for (int32_tcxx . . $ int32_t# i = 0; i < NUM_TAPScxx . . $ `src/pt2_downsample2x.c:7:9`!; i++)
194 {
195 const int32_tcxx . . $ int32_t# tapOffset = offset + (i - CENTER_TAPcxx . . $ `src/pt2_downsample2x.c:8:9`!);
196
197 double dSmp;
198 if (tapOffset < 0)
199 dSmp = fSamples[0];
200 else if (tapOffset >= sampleLength)
201 dSmp = fSamples[sampleLength-1];
202 else
203 dSmp = fSamples[tapOffset];
204
205 dVal += dSmp * (double)fHalfbandKernelcxx . . $ fHalfbandKernel.[i];
206 }
207
208 return dVal;
209 }
210
211 static float fDownsample2xcxx . . $ fDownsample2x(4c1d67ef81991b02).(float *fSamples, int32_tcxx . . $ int32_t# offset, int32_tcxx . . $ int32_t# sampleLength)
212 {
213 float fVal = 0.0f;
214 for (int32_tcxx . . $ int32_t# i = 0; i < NUM_TAPScxx . . $ `src/pt2_downsample2x.c:7:9`!; i++)
215 {
216 const int32_tcxx . . $ int32_t# tapOffset = offset + (i - CENTER_TAPcxx . . $ `src/pt2_downsample2x.c:8:9`!);
217
218 float fSmp;
219 if (tapOffset < 0)
220 fSmp = fSamples[0];
221 else if (tapOffset >= sampleLength)
222 fSmp = fSamples[sampleLength-1];
223 else
224 fSmp = fSamples[tapOffset];
225
226 fVal += fSmp * fHalfbandKernelcxx . . $ fHalfbandKernel.[i];
227 }
228
229 return fVal;
230 }
231
232 static float fDownsample2x_U8cxx . . $ fDownsample2x_U8(b4e47bec3e0e6e4b).(uint8_tcxx . . $ uint8_t# *samplesU8, int32_tcxx . . $ int32_t# offset, int32_tcxx . . $ int32_t# sampleLength)
233 {
234 float fVal = 0.0f;
235 for (int32_tcxx . . $ int32_t# i = 0; i < NUM_TAPScxx . . $ `src/pt2_downsample2x.c:7:9`!; i++)
236 {
237 const int32_tcxx . . $ int32_t# tapOffset = offset + (i - CENTER_TAPcxx . . $ `src/pt2_downsample2x.c:8:9`!);
238
239 float fSmp;
240 if (tapOffset < 0)
241 fSmp = samplesU8[0];
242 else if (tapOffset >= sampleLength)
243 fSmp = samplesU8[sampleLength-1];
244 else
245 fSmp = samplesU8[tapOffset];
246
247 fVal += (fSmp - 128.0f) * fHalfbandKernelcxx . . $ fHalfbandKernel.[i];
248 }
249
250 return fVal;
251 }
252
253 static float fDownsample2x_S8cxx . . $ fDownsample2x_S8(c4841c82dc4a1036).(int8_tcxx . . $ int8_t# *samplesS8, int32_tcxx . . $ int32_t# offset, int32_tcxx . . $ int32_t# sampleLength)
254 {
255 float fVal = 0.0f;
256 for (int32_tcxx . . $ int32_t# i = 0; i < NUM_TAPScxx . . $ `src/pt2_downsample2x.c:7:9`!; i++)
257 {
258 const int32_tcxx . . $ int32_t# tapOffset = offset + (i - CENTER_TAPcxx . . $ `src/pt2_downsample2x.c:8:9`!);
259
260 float fSmp;
261 if (tapOffset < 0)
262 fSmp = samplesS8[0];
263 else if (tapOffset >= sampleLength)
264 fSmp = samplesS8[sampleLength-1];
265 else
266 fSmp = samplesS8[tapOffset];
267
268 fVal += fSmp * fHalfbandKernelcxx . . $ fHalfbandKernel.[i];
269 }
270
271 return fVal;
272 }
273
274 static float fDownsample2x_S16cxx . . $ fDownsample2x_S16(650a2b25ddfefd98).(int16_tcxx . . $ int16_t# *samplesS16, int32_tcxx . . $ int32_t# offset, int32_tcxx . . $ int32_t# sampleLength)
275 {
276 float fVal = 0.0f;
277 for (int32_tcxx . . $ int32_t# i = 0; i < NUM_TAPScxx . . $ `src/pt2_downsample2x.c:7:9`!; i++)
278 {
279 const int32_tcxx . . $ int32_t# tapOffset = offset + (i - CENTER_TAPcxx . . $ `src/pt2_downsample2x.c:8:9`!);
280
281 float fSmp;
282 if (tapOffset < 0)
283 fSmp = samplesS16[0];
284 else if (tapOffset >= sampleLength)
285 fSmp = samplesS16[sampleLength-1];
286 else
287 fSmp = samplesS16[tapOffset];
288
289 fVal += fSmp * fHalfbandKernelcxx . . $ fHalfbandKernel.[i];
290 }
291
292 return fVal;
293 }
294
295 static double dDownsample2x_S32cxx . . $ dDownsample2x_S32(dfe38e08a381b74d).(int32_tcxx . . $ int32_t# *samplesS32, int32_tcxx . . $ int32_t# offset, int32_tcxx . . $ int32_t# sampleLength)
296 {
297 double dVal = 0.0;
298 for (int32_tcxx . . $ int32_t# i = 0; i < NUM_TAPScxx . . $ `src/pt2_downsample2x.c:7:9`!; i++)
299 {
300 const int32_tcxx . . $ int32_t# tapOffset = offset + (i - CENTER_TAPcxx . . $ `src/pt2_downsample2x.c:8:9`!);
301
302 double dSmp;
303 if (tapOffset < 0)
304 dSmp = samplesS32[0];
305 else if (tapOffset >= sampleLength)
306 dSmp = samplesS32[sampleLength-1];
307 else
308 dSmp = samplesS32[tapOffset];
309
310 dVal += dSmp * (double)fHalfbandKernelcxx . . $ fHalfbandKernel.[i];
311 }
312
313 return dVal;
314 }
315
316 // Warning: These can exceed original range because of undershoot/overshoot!
317
318 void downsample2xDoublecxx . . $ downsample2xDouble(b832380d3925cf6).(double *buffer, uint32_tcxx . . $ uint32_t# originalLength)
319 {
320 int32_tcxx . . $ int32_t# offset = 0;
321 for (uint32_tcxx . . $ uint32_t# i = 0; i < originalLength / 2; i++, offset += 2)
322 buffer[i] = dDownsample2xcxx . . $ dDownsample2x(23d7d816a227b587).(buffer, offset, originalLength);
323 }
324
325 void downsample2xFloatcxx . . $ downsample2xFloat(ac1d28a1859f2825).(float *buffer, uint32_tcxx . . $ uint32_t# originalLength)
326 {
327 int32_tcxx . . $ int32_t# offset = 0;
328 for (uint32_tcxx . . $ uint32_t# i = 0; i < originalLength / 2; i++, offset += 2)
329 buffer[i] = fDownsample2xcxx . . $ fDownsample2x(4c1d67ef81991b02).(buffer, offset, originalLength);
330 }
331
332 // Warning: These are slow and use normalization to prevent clipping from undershoot/overshoot!
333
334 boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! downsample2x8BitUcxx . . $ downsample2x8BitU(f3e7299796ab6c6f).(uint8_tcxx . . $ uint8_t# *buffer, uint32_tcxx . . $ uint32_t# originalLength)
335 {
336 uint32_tcxx . . $ uint32_t# newLength = originalLength / 2;
337 if (newLength > (uint32_tcxx . . $ uint32_t#)configcxx . . $ config..maxSampleLengthcxx . . $ config_t#maxSampleLength.)
338 newLength = configcxx . . $ config..maxSampleLengthcxx . . $ config_t#maxSampleLength.;
339
340 float *fBuffer = (float *)malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(newLength * sizeof (float));
341 if (fBuffer == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
342 return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
343
344 float fPeak = 0.0f;
345
346 int32_tcxx . . $ int32_t# offset = 0;
347 for (uint32_tcxx . . $ uint32_t# i = 0; i < newLength; i++, offset += 2)
348 {
349 fBuffer[i] = fDownsample2x_U8cxx . . $ fDownsample2x_U8(b4e47bec3e0e6e4b).(buffer, offset, originalLength);
350
351 const float fAbsSmp = fabsf(fBuffer[i]);
352 if (fAbsSmp > fPeak)
353 fPeak = fAbsSmp;
354 }
355
356 // normalize
357
358 float fAmp = 1.0f;
359 if (fPeak > 0.0f)
360 fAmp = INT8_MAXcxx . . $ `<external>/3415975807581488833/stdint.h:110:10`! / fPeak;
361
362 for (uint32_tcxx . . $ uint32_t# i = 0; i < newLength; i++)
363 buffer[i] = (uint8_tcxx . . $ uint8_t#)roundf(fBuffer[i] * fAmp) + 128;
364
365 freecxx . . $ free(5d22bdacc48458e8).(fBuffer);
366 return truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
367 }
368
369 boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! downsample2x8Bitcxx . . $ downsample2x8Bit(9b8781d28ee69655).(int8_tcxx . . $ int8_t# *buffer, uint32_tcxx . . $ uint32_t# originalLength)
370 {
371 uint32_tcxx . . $ uint32_t# newLength = originalLength / 2;
372 if (newLength > (uint32_tcxx . . $ uint32_t#)configcxx . . $ config..maxSampleLengthcxx . . $ config_t#maxSampleLength.)
373 newLength = configcxx . . $ config..maxSampleLengthcxx . . $ config_t#maxSampleLength.;
374
375 float *fBuffer = (float *)malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(newLength * sizeof (float));
376 if (fBuffer == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
377 return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
378
379 float fPeak = 0.0f;
380
381 int32_tcxx . . $ int32_t# offset = 0;
382 for (uint32_tcxx . . $ uint32_t# i = 0; i < newLength; i++, offset += 2)
383 {
384 fBuffer[i] = fDownsample2x_S8cxx . . $ fDownsample2x_S8(c4841c82dc4a1036).(buffer, offset, originalLength);
385
386 const float fAbsSmp = fabsf(fBuffer[i]);
387 if (fAbsSmp > fPeak)
388 fPeak = fAbsSmp;
389 }
390
391 // normalize
392
393 float fAmp = 1.0f;
394 if (fPeak > 0.0f)
395 fAmp = INT8_MAXcxx . . $ `<external>/3415975807581488833/stdint.h:110:10`! / fPeak;
396
397 for (uint32_tcxx . . $ uint32_t# i = 0; i < newLength; i++)
398 buffer[i] = (int8_tcxx . . $ int8_t#)roundf(fBuffer[i] * fAmp);
399
400 freecxx . . $ free(5d22bdacc48458e8).(fBuffer);
401 return truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
402 }
403
404 boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! downsample2x16Bitcxx . . $ downsample2x16Bit(6f0a599713eb5608).(int16_tcxx . . $ int16_t# *buffer, uint32_tcxx . . $ uint32_t# originalLength)
405 {
406 uint32_tcxx . . $ uint32_t# newLength = originalLength / 2;
407
408 if (newLength > (uint32_tcxx . . $ uint32_t#)configcxx . . $ config..maxSampleLengthcxx . . $ config_t#maxSampleLength.)
409 newLength = configcxx . . $ config..maxSampleLengthcxx . . $ config_t#maxSampleLength.;
410
411 float *fBuffer = (float *)malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(newLength * sizeof (float));
412 if (fBuffer == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
413 return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
414
415 float fPeak = 0.0f;
416
417 int32_tcxx . . $ int32_t# offset = 0;
418 for (uint32_tcxx . . $ uint32_t# i = 0; i < newLength; i++, offset += 2)
419 {
420 fBuffer[i] = fDownsample2x_S16cxx . . $ fDownsample2x_S16(650a2b25ddfefd98).(buffer, offset, originalLength);
421
422 const float fAbsSmp = fabsf(fBuffer[i]);
423 if (fAbsSmp > fPeak)
424 fPeak = fAbsSmp;
425 }
426
427 // normalize
428
429 float fAmp = 1.0f;
430 if (fPeak > 0.0f)
431 fAmp = INT16_MAXcxx . . $ `<external>/3415975807581488833/stdint.h:111:10`! / fPeak;
432
433 for (uint32_tcxx . . $ uint32_t# i = 0; i < newLength; i++)
434 buffer[i] = (int16_tcxx . . $ int16_t#)roundf(fBuffer[i] * fAmp);
435
436 freecxx . . $ free(5d22bdacc48458e8).(fBuffer);
437 return truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
438 }
439
440 boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! downsample2x32Bitcxx . . $ downsample2x32Bit(fdfc7b0a9f333dff).(int32_tcxx . . $ int32_t# *buffer, uint32_tcxx . . $ uint32_t# originalLength)
441 {
442 uint32_tcxx . . $ uint32_t# newLength = originalLength / 2;
443 if (newLength > (uint32_tcxx . . $ uint32_t#)configcxx . . $ config..maxSampleLengthcxx . . $ config_t#maxSampleLength.)
444 newLength = configcxx . . $ config..maxSampleLengthcxx . . $ config_t#maxSampleLength.;
445
446 double *dBuffer = (double *)malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(newLength * sizeof (double));
447 if (dBuffer == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
448 return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
449
450 double dPeak = 0.0;
451
452 int32_tcxx . . $ int32_t# offset = 0;
453 for (uint32_tcxx . . $ uint32_t# i = 0; i < newLength; i++, offset += 2)
454 {
455 dBuffer[i] = dDownsample2x_S32cxx . . $ dDownsample2x_S32(dfe38e08a381b74d).(buffer, offset, originalLength);
456
457 const double dAbsSmp = fabscxx . . $ fabs(447c67c6676f75c3).(dBuffer[i]);
458 if (dAbsSmp > dPeak)
459 dPeak = dAbsSmp;
460 }
461
462 // normalize
463
464 double dAmp = 1.0;
465 if (dPeak > 0.0)
466 dAmp = INT32_MAXcxx . . $ `<external>/3415975807581488833/stdint.h:112:10`! / dPeak;
467
468 for (uint32_tcxx . . $ uint32_t# i = 0; i < newLength; i++)
469 buffer[i] = (int32_tcxx . . $ int32_t#)roundcxx . . $ round(447c67c6676f75c3).(dBuffer[i] * dAmp);
470
471 freecxx . . $ free(5d22bdacc48458e8).(dBuffer);
472 return truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
473 }