1 /* Spa
2 *
3 * Copyright © 2018 Wim Taymans
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
14 * Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 */
24
25 #include <string.h>
26 #include <stdio.h>
27 #include <math.h>
28
29 #include <spa/support/cpu.h>
30 #include <spa/utils/defs.h>
31 #include <spa/param/audio/format-utils.h>
32
33 #include "fmt-ops.h"
34 #include "law.h"
35
36 void
conv_copy8d_c(struct convert * conv,void * SPA_RESTRICT dst[],const void * SPA_RESTRICT src[],uint32_t n_samples)37 conv_copy8d_c(struct convert *conv, void * SPA_RESTRICT dst[], const void * SPA_RESTRICT src[],
38 uint32_t n_samples)
39 {
40 uint32_t i, n_channels = conv->n_channels;
41 for (i = 0; i < n_channels; i++)
42 spa_memcpy(dst[i], src[i], n_samples);
43 }
44
45 void
conv_copy8_c(struct convert * conv,void * SPA_RESTRICT dst[],const void * SPA_RESTRICT src[],uint32_t n_samples)46 conv_copy8_c(struct convert *conv, void * SPA_RESTRICT dst[], const void * SPA_RESTRICT src[],
47 uint32_t n_samples)
48 {
49 spa_memcpy(dst[0], src[0], n_samples * conv->n_channels);
50 }
51
52
53 void
conv_copy16d_c(struct convert * conv,void * SPA_RESTRICT dst[],const void * SPA_RESTRICT src[],uint32_t n_samples)54 conv_copy16d_c(struct convert *conv, void * SPA_RESTRICT dst[], const void * SPA_RESTRICT src[],
55 uint32_t n_samples)
56 {
57 uint32_t i, n_channels = conv->n_channels;
58 for (i = 0; i < n_channels; i++)
59 spa_memcpy(dst[i], src[i], n_samples * sizeof(int16_t));
60 }
61
62 void
conv_copy16_c(struct convert * conv,void * SPA_RESTRICT dst[],const void * SPA_RESTRICT src[],uint32_t n_samples)63 conv_copy16_c(struct convert *conv, void * SPA_RESTRICT dst[], const void * SPA_RESTRICT src[],
64 uint32_t n_samples)
65 {
66 spa_memcpy(dst[0], src[0], n_samples * sizeof(int16_t) * conv->n_channels);
67 }
68
69 void
conv_copy24d_c(struct convert * conv,void * SPA_RESTRICT dst[],const void * SPA_RESTRICT src[],uint32_t n_samples)70 conv_copy24d_c(struct convert *conv, void * SPA_RESTRICT dst[], const void * SPA_RESTRICT src[],
71 uint32_t n_samples)
72 {
73 uint32_t i, n_channels = conv->n_channels;
74 for (i = 0; i < n_channels; i++)
75 spa_memcpy(dst[i], src[i], n_samples * 3);
76 }
77
78 void
conv_copy24_c(struct convert * conv,void * SPA_RESTRICT dst[],const void * SPA_RESTRICT src[],uint32_t n_samples)79 conv_copy24_c(struct convert *conv, void * SPA_RESTRICT dst[], const void * SPA_RESTRICT src[],
80 uint32_t n_samples)
81 {
82 spa_memcpy(dst[0], src[0], n_samples * 3 * conv->n_channels);
83 }
84
85 void
conv_copy32d_c(struct convert * conv,void * SPA_RESTRICT dst[],const void * SPA_RESTRICT src[],uint32_t n_samples)86 conv_copy32d_c(struct convert *conv, void * SPA_RESTRICT dst[], const void * SPA_RESTRICT src[],
87 uint32_t n_samples)
88 {
89 uint32_t i, n_channels = conv->n_channels;
90 for (i = 0; i < n_channels; i++)
91 spa_memcpy(dst[i], src[i], n_samples * sizeof(int32_t));
92 }
93
94 void
conv_copy32_c(struct convert * conv,void * SPA_RESTRICT dst[],const void * SPA_RESTRICT src[],uint32_t n_samples)95 conv_copy32_c(struct convert *conv, void * SPA_RESTRICT dst[], const void * SPA_RESTRICT src[],
96 uint32_t n_samples)
97 {
98 spa_memcpy(dst[0], src[0], n_samples * sizeof(int32_t) * conv->n_channels);
99 }
100
101 void
conv_u8d_to_f32d_c(struct convert * conv,void * SPA_RESTRICT dst[],const void * SPA_RESTRICT src[],uint32_t n_samples)102 conv_u8d_to_f32d_c(struct convert *conv, void * SPA_RESTRICT dst[], const void * SPA_RESTRICT src[],
103 uint32_t n_samples)
104 {
105 uint32_t i, j, n_channels = conv->n_channels;
106
107 for (i = 0; i < n_channels; i++) {
108 const uint8_t *s = src[i];
109 float *d = dst[i];
110
111 for (j = 0; j < n_samples; j++)
112 d[j] = U8_TO_F32(s[j]);
113 }
114 }
115
116 void
conv_u8_to_f32_c(struct convert * conv,void * SPA_RESTRICT dst[],const void * SPA_RESTRICT src[],uint32_t n_samples)117 conv_u8_to_f32_c(struct convert *conv, void * SPA_RESTRICT dst[], const void * SPA_RESTRICT src[],
118 uint32_t n_samples)
119 {
120 uint32_t i, n_channels = conv->n_channels;
121 const uint8_t *s = src[0];
122 float *d = dst[0];
123
124 n_samples *= n_channels;
125
126 for (i = 0; i < n_samples; i++)
127 d[i] = U8_TO_F32(s[i]);
128 }
129
130 void
conv_u8_to_f32d_c(struct convert * conv,void * SPA_RESTRICT dst[],const void * SPA_RESTRICT src[],uint32_t n_samples)131 conv_u8_to_f32d_c(struct convert *conv, void * SPA_RESTRICT dst[], const void * SPA_RESTRICT src[],
132 uint32_t n_samples)
133 {
134 const uint8_t *s = src[0];
135 float **d = (float **) dst;
136 uint32_t i, j, n_channels = conv->n_channels;
137
138 for (j = 0; j < n_samples; j++) {
139 for (i = 0; i < n_channels; i++)
140 d[i][j] = U8_TO_F32(*s++);
141 }
142 }
143
144 void
conv_u8d_to_f32_c(struct convert * conv,void * SPA_RESTRICT dst[],const void * SPA_RESTRICT src[],uint32_t n_samples)145 conv_u8d_to_f32_c(struct convert *conv, void * SPA_RESTRICT dst[], const void * SPA_RESTRICT src[],
146 uint32_t n_samples)
147 {
148 const uint8_t **s = (const uint8_t **) src;
149 float *d = dst[0];
150 uint32_t i, j, n_channels = conv->n_channels;
151
152 for (j = 0; j < n_samples; j++) {
153 for (i = 0; i < n_channels; i++)
154 *d++ = U8_TO_F32(s[i][j]);
155 }
156 }
157
158 void
conv_s8d_to_f32d_c(struct convert * conv,void * SPA_RESTRICT dst[],const void * SPA_RESTRICT src[],uint32_t n_samples)159 conv_s8d_to_f32d_c(struct convert *conv, void * SPA_RESTRICT dst[], const void * SPA_RESTRICT src[],
160 uint32_t n_samples)
161 {
162 uint32_t i, j, n_channels = conv->n_channels;
163
164 for (i = 0; i < n_channels; i++) {
165 const int8_t *s = src[i];
166 float *d = dst[i];
167 for (j = 0; j < n_samples; j++)
168 d[j] = S8_TO_F32(s[j]);
169 }
170 }
171
172 void
conv_s8_to_f32_c(struct convert * conv,void * SPA_RESTRICT dst[],const void * SPA_RESTRICT src[],uint32_t n_samples)173 conv_s8_to_f32_c(struct convert *conv, void * SPA_RESTRICT dst[], const void * SPA_RESTRICT src[],
174 uint32_t n_samples)
175 {
176 uint32_t i, n_channels = conv->n_channels;
177 const int8_t *s = src[0];
178 float *d = dst[0];
179
180 n_samples *= n_channels;
181
182 for (i = 0; i < n_samples; i++)
183 d[i] = S8_TO_F32(s[i]);
184 }
185
186 void
conv_s8_to_f32d_c(struct convert * conv,void * SPA_RESTRICT dst[],const void * SPA_RESTRICT src[],uint32_t n_samples)187 conv_s8_to_f32d_c(struct convert *conv, void * SPA_RESTRICT dst[], const void * SPA_RESTRICT src[],
188 uint32_t n_samples)
189 {
190 const int8_t *s = src[0];
191 float **d = (float **) dst;
192 uint32_t i, j, n_channels = conv->n_channels;
193
194 for (j = 0; j < n_samples; j++) {
195 for (i = 0; i < n_channels; i++)
196 d[i][j] = S8_TO_F32(*s++);
197 }
198 }
199
200 void
conv_s8d_to_f32_c(struct convert * conv,void * SPA_RESTRICT dst[],const void * SPA_RESTRICT src[],uint32_t n_samples)201 conv_s8d_to_f32_c(struct convert *conv, void * SPA_RESTRICT dst[], const void * SPA_RESTRICT src[],
202 uint32_t n_samples)
203 {
204 const int8_t **s = (const int8_t **) src;
205 float *d = dst[0];
206 uint32_t i, j, n_channels = conv->n_channels;
207
208 for (j = 0; j < n_samples; j++) {
209 for (i = 0; i < n_channels; i++)
210 *d++ = S8_TO_F32(s[i][j]);
211 }
212 }
213
214 void
conv_alaw_to_f32d_c(struct convert * conv,void * SPA_RESTRICT dst[],const void * SPA_RESTRICT src[],uint32_t n_samples)215 conv_alaw_to_f32d_c(struct convert *conv, void * SPA_RESTRICT dst[], const void * SPA_RESTRICT src[],
216 uint32_t n_samples)
217 {
218 const uint8_t *s = src[0];
219 float **d = (float **) dst;
220 uint32_t i, j, n_channels = conv->n_channels;
221
222 for (j = 0; j < n_samples; j++) {
223 for (i = 0; i < n_channels; i++)
224 d[i][j] = alaw_to_f32(*s++);
225 }
226 }
227
228 void
conv_ulaw_to_f32d_c(struct convert * conv,void * SPA_RESTRICT dst[],const void * SPA_RESTRICT src[],uint32_t n_samples)229 conv_ulaw_to_f32d_c(struct convert *conv, void * SPA_RESTRICT dst[], const void * SPA_RESTRICT src[],
230 uint32_t n_samples)
231 {
232 const uint8_t *s = src[0];
233 float **d = (float **) dst;
234 uint32_t i, j, n_channels = conv->n_channels;
235
236 for (j = 0; j < n_samples; j++) {
237 for (i = 0; i < n_channels; i++)
238 d[i][j] = ulaw_to_f32(*s++);
239 }
240 }
241
242 void
conv_u16_to_f32_c(struct convert * conv,void * SPA_RESTRICT dst[],const void * SPA_RESTRICT src[],uint32_t n_samples)243 conv_u16_to_f32_c(struct convert *conv, void * SPA_RESTRICT dst[], const void * SPA_RESTRICT src[],
244 uint32_t n_samples)
245 {
246 uint32_t i, n_channels = conv->n_channels;
247 const uint16_t *s = src[0];
248 float *d = dst[0];
249
250 n_samples *= n_channels;
251
252 for (i = 0; i < n_samples; i++)
253 d[i] = U16_TO_F32(s[i]);
254 }
255
256 void
conv_u16_to_f32d_c(struct convert * conv,void * SPA_RESTRICT dst[],const void * SPA_RESTRICT src[],uint32_t n_samples)257 conv_u16_to_f32d_c(struct convert *conv, void * SPA_RESTRICT dst[], const void * SPA_RESTRICT src[],
258 uint32_t n_samples)
259 {
260 const uint16_t *s = src[0];
261 float **d = (float **) dst;
262 uint32_t i, j, n_channels = conv->n_channels;
263
264 for (j = 0; j < n_samples; j++) {
265 for (i = 0; i < n_channels; i++)
266 d[i][j] = U16_TO_F32(*s++);
267 }
268 }
269
270 void
conv_s16d_to_f32d_c(struct convert * conv,void * SPA_RESTRICT dst[],const void * SPA_RESTRICT src[],uint32_t n_samples)271 conv_s16d_to_f32d_c(struct convert *conv, void * SPA_RESTRICT dst[], const void * SPA_RESTRICT src[],
272 uint32_t n_samples)
273 {
274 uint32_t i, j, n_channels = conv->n_channels;
275
276 for (i = 0; i < n_channels; i++) {
277 const int16_t *s = src[i];
278 float *d = dst[i];
279 for (j = 0; j < n_samples; j++)
280 d[j] = S16_TO_F32(s[j]);
281 }
282 }
283
284 void
conv_s16_to_f32_c(struct convert * conv,void * SPA_RESTRICT dst[],const void * SPA_RESTRICT src[],uint32_t n_samples)285 conv_s16_to_f32_c(struct convert *conv, void * SPA_RESTRICT dst[], const void * SPA_RESTRICT src[],
286 uint32_t n_samples)
287 {
288 uint32_t i, n_channels = conv->n_channels;
289 const int16_t *s = src[0];
290 float *d = dst[0];
291
292 n_samples *= n_channels;
293
294 for (i = 0; i < n_samples; i++)
295 d[i] = S16_TO_F32(s[i]);
296 }
297
298 void
conv_s16_to_f32d_c(struct convert * conv,void * SPA_RESTRICT dst[],const void * SPA_RESTRICT src[],uint32_t n_samples)299 conv_s16_to_f32d_c(struct convert *conv, void * SPA_RESTRICT dst[], const void * SPA_RESTRICT src[],
300 uint32_t n_samples)
301 {
302 const int16_t *s = src[0];
303 float **d = (float **) dst;
304 uint32_t i, j, n_channels = conv->n_channels;
305
306 for (j = 0; j < n_samples; j++) {
307 for (i = 0; i < n_channels; i++)
308 d[i][j] = S16_TO_F32(*s++);
309 }
310 }
311
312 void
conv_s16s_to_f32d_c(struct convert * conv,void * SPA_RESTRICT dst[],const void * SPA_RESTRICT src[],uint32_t n_samples)313 conv_s16s_to_f32d_c(struct convert *conv, void * SPA_RESTRICT dst[], const void * SPA_RESTRICT src[],
314 uint32_t n_samples)
315 {
316 const int16_t *s = src[0];
317 float **d = (float **) dst;
318 uint32_t i, j, n_channels = conv->n_channels;
319
320 for (j = 0; j < n_samples; j++) {
321 for (i = 0; i < n_channels; i++)
322 d[i][j] = S16S_TO_F32(*s++);
323 }
324 }
325
326 void
conv_s16d_to_f32_c(struct convert * conv,void * SPA_RESTRICT dst[],const void * SPA_RESTRICT src[],uint32_t n_samples)327 conv_s16d_to_f32_c(struct convert *conv, void * SPA_RESTRICT dst[], const void * SPA_RESTRICT src[],
328 uint32_t n_samples)
329 {
330 const int16_t **s = (const int16_t **) src;
331 float *d = dst[0];
332 uint32_t i, j, n_channels = conv->n_channels;
333
334 for (j = 0; j < n_samples; j++) {
335 for (i = 0; i < n_channels; i++)
336 *d++ = S16_TO_F32(s[i][j]);
337 }
338 }
339
340 void
conv_u32_to_f32_c(struct convert * conv,void * SPA_RESTRICT dst[],const void * SPA_RESTRICT src[],uint32_t n_samples)341 conv_u32_to_f32_c(struct convert *conv, void * SPA_RESTRICT dst[], const void * SPA_RESTRICT src[],
342 uint32_t n_samples)
343 {
344 uint32_t i, n_channels = conv->n_channels;
345 const uint32_t *s = src[0];
346 float *d = dst[0];
347
348 n_samples *= n_channels;
349
350 for (i = 0; i < n_samples; i++)
351 d[i] = U32_TO_F32(s[i]);
352 }
353
354 void
conv_u32_to_f32d_c(struct convert * conv,void * SPA_RESTRICT dst[],const void * SPA_RESTRICT src[],uint32_t n_samples)355 conv_u32_to_f32d_c(struct convert *conv, void * SPA_RESTRICT dst[], const void * SPA_RESTRICT src[],
356 uint32_t n_samples)
357 {
358 const uint32_t *s = src[0];
359 float **d = (float **) dst;
360 uint32_t i, j, n_channels = conv->n_channels;
361
362 for (j = 0; j < n_samples; j++) {
363 for (i = 0; i < n_channels; i++)
364 d[i][j] = U32_TO_F32(*s++);
365 }
366 }
367
368 void
conv_s32d_to_f32d_c(struct convert * conv,void * SPA_RESTRICT dst[],const void * SPA_RESTRICT src[],uint32_t n_samples)369 conv_s32d_to_f32d_c(struct convert *conv, void * SPA_RESTRICT dst[], const void * SPA_RESTRICT src[],
370 uint32_t n_samples)
371 {
372 uint32_t i, j, n_channels = conv->n_channels;
373
374 for (i = 0; i < n_channels; i++) {
375 const int32_t *s = src[i];
376 float *d = dst[i];
377
378 for (j = 0; j < n_samples; j++)
379 d[j] = S32_TO_F32(s[j]);
380 }
381 }
382
383 void
conv_s32_to_f32_c(struct convert * conv,void * SPA_RESTRICT dst[],const void * SPA_RESTRICT src[],uint32_t n_samples)384 conv_s32_to_f32_c(struct convert *conv, void * SPA_RESTRICT dst[], const void * SPA_RESTRICT src[],
385 uint32_t n_samples)
386 {
387 uint32_t i, n_channels = conv->n_channels;
388 const int32_t *s = src[0];
389 float *d = dst[0];
390
391 n_samples *= n_channels;
392
393 for (i = 0; i < n_samples; i++)
394 d[i] = S32_TO_F32(s[i]);
395 }
396
397 void
conv_s32_to_f32d_c(struct convert * conv,void * SPA_RESTRICT dst[],const void * SPA_RESTRICT src[],uint32_t n_samples)398 conv_s32_to_f32d_c(struct convert *conv, void * SPA_RESTRICT dst[], const void * SPA_RESTRICT src[],
399 uint32_t n_samples)
400 {
401 const int32_t *s = src[0];
402 float **d = (float **) dst;
403 uint32_t i, j, n_channels = conv->n_channels;
404
405 for (j = 0; j < n_samples; j++) {
406 for (i = 0; i < n_channels; i++)
407 d[i][j] = S32_TO_F32(*s++);
408 }
409 }
410
411 void
conv_s32s_to_f32d_c(struct convert * conv,void * SPA_RESTRICT dst[],const void * SPA_RESTRICT src[],uint32_t n_samples)412 conv_s32s_to_f32d_c(struct convert *conv, void * SPA_RESTRICT dst[], const void * SPA_RESTRICT src[],
413 uint32_t n_samples)
414 {
415 const int32_t *s = src[0];
416 float **d = (float **) dst;
417 uint32_t i, j, n_channels = conv->n_channels;
418
419 for (j = 0; j < n_samples; j++) {
420 for (i = 0; i < n_channels; i++)
421 d[i][j] = S32S_TO_F32(*s++);
422 }
423 }
424
425 void
conv_s32d_to_f32_c(struct convert * conv,void * SPA_RESTRICT dst[],const void * SPA_RESTRICT src[],uint32_t n_samples)426 conv_s32d_to_f32_c(struct convert *conv, void * SPA_RESTRICT dst[], const void * SPA_RESTRICT src[],
427 uint32_t n_samples)
428 {
429 const int32_t **s = (const int32_t **) src;
430 float *d = dst[0];
431 uint32_t i, j, n_channels = conv->n_channels;
432
433 for (j = 0; j < n_samples; j++) {
434 for (i = 0; i < n_channels; i++)
435 *d++ = S32_TO_F32(s[i][j]);
436 }
437 }
438
439 void
conv_u24_to_f32_c(struct convert * conv,void * SPA_RESTRICT dst[],const void * SPA_RESTRICT src[],uint32_t n_samples)440 conv_u24_to_f32_c(struct convert *conv, void * SPA_RESTRICT dst[], const void * SPA_RESTRICT src[],
441 uint32_t n_samples)
442 {
443 uint32_t i, n_channels = conv->n_channels;
444 const uint8_t *s = src[0];
445 float *d = dst[0];
446
447 n_samples *= n_channels;
448
449 for (i = 0; i < n_samples; i++) {
450 d[i] = U24_TO_F32(read_u24(s));
451 s += 3;
452 }
453 }
454
455 void
conv_u24_to_f32d_c(struct convert * conv,void * SPA_RESTRICT dst[],const void * SPA_RESTRICT src[],uint32_t n_samples)456 conv_u24_to_f32d_c(struct convert *conv, void * SPA_RESTRICT dst[], const void * SPA_RESTRICT src[],
457 uint32_t n_samples)
458 {
459 const uint8_t *s = src[0];
460 float **d = (float **) dst;
461 uint32_t i, j, n_channels = conv->n_channels;
462
463 for (j = 0; j < n_samples; j++) {
464 for (i = 0; i < n_channels; i++) {
465 d[i][j] = U24_TO_F32(read_u24(s));
466 s += 3;
467 }
468 }
469 }
470
471 void
conv_s24d_to_f32d_c(struct convert * conv,void * SPA_RESTRICT dst[],const void * SPA_RESTRICT src[],uint32_t n_samples)472 conv_s24d_to_f32d_c(struct convert *conv, void * SPA_RESTRICT dst[], const void * SPA_RESTRICT src[],
473 uint32_t n_samples)
474 {
475 uint32_t i, j, n_channels = conv->n_channels;
476
477 for (i = 0; i < n_channels; i++) {
478 const int8_t *s = src[i];
479 float *d = dst[i];
480
481 for (j = 0; j < n_samples; j++) {
482 d[j] = S24_TO_F32(read_s24(s));
483 s += 3;
484 }
485 }
486 }
487
488 void
conv_s24_to_f32_c(struct convert * conv,void * SPA_RESTRICT dst[],const void * SPA_RESTRICT src[],uint32_t n_samples)489 conv_s24_to_f32_c(struct convert *conv, void * SPA_RESTRICT dst[], const void * SPA_RESTRICT src[],
490 uint32_t n_samples)
491 {
492 uint32_t i, n_channels = conv->n_channels;
493 const int8_t *s = src[0];
494 float *d = dst[0];
495
496 n_samples *= n_channels;
497
498 for (i = 0; i < n_samples; i++) {
499 d[i] = S24_TO_F32(read_s24(s));
500 s += 3;
501 }
502 }
503
504 void
conv_s24_to_f32d_c(struct convert * conv,void * SPA_RESTRICT dst[],const void * SPA_RESTRICT src[],uint32_t n_samples)505 conv_s24_to_f32d_c(struct convert *conv, void * SPA_RESTRICT dst[], const void * SPA_RESTRICT src[],
506 uint32_t n_samples)
507 {
508 const uint8_t *s = src[0];
509 float **d = (float **) dst;
510 uint32_t i, j, n_channels = conv->n_channels;
511
512 for (j = 0; j < n_samples; j++) {
513 for (i = 0; i < n_channels; i++) {
514 d[i][j] = S24_TO_F32(read_s24(s));
515 s += 3;
516 }
517 }
518 }
519
520 void
conv_s24s_to_f32d_c(struct convert * conv,void * SPA_RESTRICT dst[],const void * SPA_RESTRICT src[],uint32_t n_samples)521 conv_s24s_to_f32d_c(struct convert *conv, void * SPA_RESTRICT dst[], const void * SPA_RESTRICT src[],
522 uint32_t n_samples)
523 {
524 const uint8_t *s = src[0];
525 float **d = (float **) dst;
526 uint32_t i, j, n_channels = conv->n_channels;
527
528 for (j = 0; j < n_samples; j++) {
529 for (i = 0; i < n_channels; i++) {
530 d[i][j] = S24_TO_F32(read_s24s(s));
531 s += 3;
532 }
533 }
534 }
535
536 void
conv_s24d_to_f32_c(struct convert * conv,void * SPA_RESTRICT dst[],const void * SPA_RESTRICT src[],uint32_t n_samples)537 conv_s24d_to_f32_c(struct convert *conv, void * SPA_RESTRICT dst[], const void * SPA_RESTRICT src[],
538 uint32_t n_samples)
539 {
540 const uint8_t **s = (const uint8_t **) src;
541 float *d = dst[0];
542 uint32_t i, j, n_channels = conv->n_channels;
543
544 for (j = 0; j < n_samples; j++) {
545 for (i = 0; i < n_channels; i++) {
546 *d++ = S24_TO_F32(read_s24(&s[i][j*3]));
547 }
548 }
549 }
550
551 void
conv_u24_32_to_f32_c(struct convert * conv,void * SPA_RESTRICT dst[],const void * SPA_RESTRICT src[],uint32_t n_samples)552 conv_u24_32_to_f32_c(struct convert *conv, void * SPA_RESTRICT dst[], const void * SPA_RESTRICT src[],
553 uint32_t n_samples)
554 {
555 uint32_t i, n_channels = conv->n_channels;
556 const uint32_t *s = src[0];
557 float *d = dst[0];
558
559 n_samples *= n_channels;
560
561 for (i = 0; i < n_samples; i++) {
562 d[i] = U24_32_TO_F32(s[i]);
563 }
564 }
565
566 void
conv_u24_32_to_f32d_c(struct convert * conv,void * SPA_RESTRICT dst[],const void * SPA_RESTRICT src[],uint32_t n_samples)567 conv_u24_32_to_f32d_c(struct convert *conv, void * SPA_RESTRICT dst[], const void * SPA_RESTRICT src[],
568 uint32_t n_samples)
569 {
570 const uint32_t *s = src[0];
571 float **d = (float **) dst;
572 uint32_t i, j, n_channels = conv->n_channels;
573
574 for (j = 0; j < n_samples; j++) {
575 for (i = 0; i < n_channels; i++)
576 d[i][j] = U24_32_TO_F32(*s++);
577 }
578 }
579
580 void
conv_s24_32d_to_f32d_c(struct convert * conv,void * SPA_RESTRICT dst[],const void * SPA_RESTRICT src[],uint32_t n_samples)581 conv_s24_32d_to_f32d_c(struct convert *conv, void * SPA_RESTRICT dst[], const void * SPA_RESTRICT src[],
582 uint32_t n_samples)
583 {
584 uint32_t i, j, n_channels = conv->n_channels;
585
586 for (i = 0; i < n_channels; i++) {
587 const int32_t *s = src[i];
588 float *d = dst[i];
589
590 for (j = 0; j < n_samples; j++)
591 d[j] = S24_32_TO_F32(s[j]);
592 }
593 }
594
595 void
conv_s24_32_to_f32_c(struct convert * conv,void * SPA_RESTRICT dst[],const void * SPA_RESTRICT src[],uint32_t n_samples)596 conv_s24_32_to_f32_c(struct convert *conv, void * SPA_RESTRICT dst[], const void * SPA_RESTRICT src[],
597 uint32_t n_samples)
598 {
599 uint32_t i, n_channels = conv->n_channels;
600 const int32_t *s = src[0];
601 float *d = dst[0];
602
603 n_samples *= n_channels;
604
605 for (i = 0; i < n_samples; i++) {
606 d[i] = S24_32_TO_F32(s[i]);
607 }
608 }
609
610 void
conv_s24_32_to_f32d_c(struct convert * conv,void * SPA_RESTRICT dst[],const void * SPA_RESTRICT src[],uint32_t n_samples)611 conv_s24_32_to_f32d_c(struct convert *conv, void * SPA_RESTRICT dst[], const void * SPA_RESTRICT src[],
612 uint32_t n_samples)
613 {
614 const int32_t *s = src[0];
615 float **d = (float **) dst;
616 uint32_t i, j, n_channels = conv->n_channels;
617
618 for (j = 0; j < n_samples; j++) {
619 for (i = 0; i < n_channels; i++)
620 d[i][j] = S24_32_TO_F32(*s++);
621 }
622 }
623
624 void
conv_s24_32s_to_f32d_c(struct convert * conv,void * SPA_RESTRICT dst[],const void * SPA_RESTRICT src[],uint32_t n_samples)625 conv_s24_32s_to_f32d_c(struct convert *conv, void * SPA_RESTRICT dst[], const void * SPA_RESTRICT src[],
626 uint32_t n_samples)
627 {
628 const int32_t *s = src[0];
629 float **d = (float **) dst;
630 uint32_t i, j, n_channels = conv->n_channels;
631
632 for (j = 0; j < n_samples; j++) {
633 for (i = 0; i < n_channels; i++)
634 d[i][j] = S24_32S_TO_F32(*s++);
635 }
636 }
637
638 void
conv_s24_32d_to_f32_c(struct convert * conv,void * SPA_RESTRICT dst[],const void * SPA_RESTRICT src[],uint32_t n_samples)639 conv_s24_32d_to_f32_c(struct convert *conv, void * SPA_RESTRICT dst[], const void * SPA_RESTRICT src[],
640 uint32_t n_samples)
641 {
642 const int32_t **s = (const int32_t **) src;
643 float *d = dst[0];
644 uint32_t i, j, n_channels = conv->n_channels;
645
646 for (j = 0; j < n_samples; j++) {
647 for (i = 0; i < n_channels; i++)
648 *d++ = S24_32_TO_F32(s[i][j]);
649 }
650 }
651
652 void
conv_f32d_to_u8d_c(struct convert * conv,void * SPA_RESTRICT dst[],const void * SPA_RESTRICT src[],uint32_t n_samples)653 conv_f32d_to_u8d_c(struct convert *conv, void * SPA_RESTRICT dst[], const void * SPA_RESTRICT src[],
654 uint32_t n_samples)
655 {
656 uint32_t i, j, n_channels = conv->n_channels;
657
658 for (i = 0; i < n_channels; i++) {
659 const float *s = src[i];
660 uint8_t *d = dst[i];
661
662 for (j = 0; j < n_samples; j++)
663 d[j] = F32_TO_U8(s[j]);
664 }
665 }
666
667 void
conv_f32_to_u8_c(struct convert * conv,void * SPA_RESTRICT dst[],const void * SPA_RESTRICT src[],uint32_t n_samples)668 conv_f32_to_u8_c(struct convert *conv, void * SPA_RESTRICT dst[], const void * SPA_RESTRICT src[],
669 uint32_t n_samples)
670 {
671 uint32_t i, n_channels = conv->n_channels;
672 const float *s = src[0];
673 uint8_t *d = dst[0];
674
675 n_samples *= n_channels;
676
677 for (i = 0; i < n_samples; i++)
678 d[i] = F32_TO_U8(s[i]);
679 }
680
681 void
conv_f32_to_u8d_c(struct convert * conv,void * SPA_RESTRICT dst[],const void * SPA_RESTRICT src[],uint32_t n_samples)682 conv_f32_to_u8d_c(struct convert *conv, void * SPA_RESTRICT dst[], const void * SPA_RESTRICT src[],
683 uint32_t n_samples)
684 {
685 const float *s = src[0];
686 uint8_t **d = (uint8_t **) dst;
687 uint32_t i, j, n_channels = conv->n_channels;
688
689 for (j = 0; j < n_samples; j++) {
690 for (i = 0; i < n_channels; i++)
691 d[i][j] = F32_TO_U8(*s++);
692 }
693 }
694
695 void
conv_f32d_to_u8_c(struct convert * conv,void * SPA_RESTRICT dst[],const void * SPA_RESTRICT src[],uint32_t n_samples)696 conv_f32d_to_u8_c(struct convert *conv, void * SPA_RESTRICT dst[], const void * SPA_RESTRICT src[],
697 uint32_t n_samples)
698 {
699 const float **s = (const float **) src;
700 uint8_t *d = dst[0];
701 uint32_t i, j, n_channels = conv->n_channels;
702
703 for (j = 0; j < n_samples; j++) {
704 for (i = 0; i < n_channels; i++)
705 *d++ = F32_TO_U8(s[i][j]);
706 }
707 }
708
709 void
conv_f32d_to_s8d_c(struct convert * conv,void * SPA_RESTRICT dst[],const void * SPA_RESTRICT src[],uint32_t n_samples)710 conv_f32d_to_s8d_c(struct convert *conv, void * SPA_RESTRICT dst[], const void * SPA_RESTRICT src[],
711 uint32_t n_samples)
712 {
713 uint32_t i, j, n_channels = conv->n_channels;
714
715 for (i = 0; i < n_channels; i++) {
716 const float *s = src[i];
717 int8_t *d = dst[i];
718
719 for (j = 0; j < n_samples; j++)
720 d[j] = F32_TO_S8(s[j]);
721 }
722 }
723
724 void
conv_f32_to_s8_c(struct convert * conv,void * SPA_RESTRICT dst[],const void * SPA_RESTRICT src[],uint32_t n_samples)725 conv_f32_to_s8_c(struct convert *conv, void * SPA_RESTRICT dst[], const void * SPA_RESTRICT src[],
726 uint32_t n_samples)
727 {
728 uint32_t i, n_channels = conv->n_channels;
729 const float *s = src[0];
730 int8_t *d = dst[0];
731
732 n_samples *= n_channels;
733
734 for (i = 0; i < n_samples; i++)
735 d[i] = F32_TO_S8(s[i]);
736 }
737
738 void
conv_f32_to_s8d_c(struct convert * conv,void * SPA_RESTRICT dst[],const void * SPA_RESTRICT src[],uint32_t n_samples)739 conv_f32_to_s8d_c(struct convert *conv, void * SPA_RESTRICT dst[], const void * SPA_RESTRICT src[],
740 uint32_t n_samples)
741 {
742 const float *s = src[0];
743 int8_t **d = (int8_t **) dst;
744 uint32_t i, j, n_channels = conv->n_channels;
745
746 for (j = 0; j < n_samples; j++) {
747 for (i = 0; i < n_channels; i++)
748 d[i][j] = F32_TO_S8(*s++);
749 }
750 }
751
752 void
conv_f32d_to_s8_c(struct convert * conv,void * SPA_RESTRICT dst[],const void * SPA_RESTRICT src[],uint32_t n_samples)753 conv_f32d_to_s8_c(struct convert *conv, void * SPA_RESTRICT dst[], const void * SPA_RESTRICT src[],
754 uint32_t n_samples)
755 {
756 const float **s = (const float **) src;
757 int8_t *d = dst[0];
758 uint32_t i, j, n_channels = conv->n_channels;
759
760 for (j = 0; j < n_samples; j++) {
761 for (i = 0; i < n_channels; i++)
762 *d++ = F32_TO_S8(s[i][j]);
763 }
764 }
765
766 void
conv_f32d_to_alaw_c(struct convert * conv,void * SPA_RESTRICT dst[],const void * SPA_RESTRICT src[],uint32_t n_samples)767 conv_f32d_to_alaw_c(struct convert *conv, void * SPA_RESTRICT dst[], const void * SPA_RESTRICT src[],
768 uint32_t n_samples)
769 {
770 const float **s = (const float **) src;
771 int8_t *d = dst[0];
772 uint32_t i, j, n_channels = conv->n_channels;
773
774 for (j = 0; j < n_samples; j++) {
775 for (i = 0; i < n_channels; i++)
776 *d++ = f32_to_alaw(s[i][j]);
777 }
778 }
779
780 void
conv_f32d_to_ulaw_c(struct convert * conv,void * SPA_RESTRICT dst[],const void * SPA_RESTRICT src[],uint32_t n_samples)781 conv_f32d_to_ulaw_c(struct convert *conv, void * SPA_RESTRICT dst[], const void * SPA_RESTRICT src[],
782 uint32_t n_samples)
783 {
784 const float **s = (const float **) src;
785 int8_t *d = dst[0];
786 uint32_t i, j, n_channels = conv->n_channels;
787
788 for (j = 0; j < n_samples; j++) {
789 for (i = 0; i < n_channels; i++)
790 *d++ = f32_to_ulaw(s[i][j]);
791 }
792 }
793
794 void
conv_f32_to_u16_c(struct convert * conv,void * SPA_RESTRICT dst[],const void * SPA_RESTRICT src[],uint32_t n_samples)795 conv_f32_to_u16_c(struct convert *conv, void * SPA_RESTRICT dst[], const void * SPA_RESTRICT src[],
796 uint32_t n_samples)
797 {
798 uint32_t i, n_channels = conv->n_channels;
799 const float *s = src[0];
800 uint16_t *d = dst[0];
801
802 n_samples *= n_channels;
803
804 for (i = 0; i < n_samples; i++)
805 d[i] = F32_TO_U16(s[i]);
806 }
807 void
conv_f32d_to_u16_c(struct convert * conv,void * SPA_RESTRICT dst[],const void * SPA_RESTRICT src[],uint32_t n_samples)808 conv_f32d_to_u16_c(struct convert *conv, void * SPA_RESTRICT dst[], const void * SPA_RESTRICT src[],
809 uint32_t n_samples)
810 {
811 const float **s = (const float **) src;
812 uint16_t *d = dst[0];
813 uint32_t i, j, n_channels = conv->n_channels;
814
815 for (j = 0; j < n_samples; j++) {
816 for (i = 0; i < n_channels; i++)
817 *d++ = F32_TO_U16(s[i][j]);
818 }
819 }
820
821 void
conv_f32d_to_s16d_c(struct convert * conv,void * SPA_RESTRICT dst[],const void * SPA_RESTRICT src[],uint32_t n_samples)822 conv_f32d_to_s16d_c(struct convert *conv, void * SPA_RESTRICT dst[], const void * SPA_RESTRICT src[],
823 uint32_t n_samples)
824 {
825 uint32_t i, j, n_channels = conv->n_channels;
826
827 for (i = 0; i < n_channels; i++) {
828 const float *s = src[i];
829 int16_t *d = dst[i];
830
831 for (j = 0; j < n_samples; j++)
832 d[j] = F32_TO_S16(s[j]);
833 }
834 }
835
836 void
conv_f32_to_s16_c(struct convert * conv,void * SPA_RESTRICT dst[],const void * SPA_RESTRICT src[],uint32_t n_samples)837 conv_f32_to_s16_c(struct convert *conv, void * SPA_RESTRICT dst[], const void * SPA_RESTRICT src[],
838 uint32_t n_samples)
839 {
840 uint32_t i, n_channels = conv->n_channels;
841 const float *s = src[0];
842 int16_t *d = dst[0];
843
844 n_samples *= n_channels;
845
846 for (i = 0; i < n_samples; i++)
847 d[i] = F32_TO_S16(s[i]);
848 }
849
850 void
conv_f32_to_s16d_c(struct convert * conv,void * SPA_RESTRICT dst[],const void * SPA_RESTRICT src[],uint32_t n_samples)851 conv_f32_to_s16d_c(struct convert *conv, void * SPA_RESTRICT dst[], const void * SPA_RESTRICT src[],
852 uint32_t n_samples)
853 {
854 const float *s = src[0];
855 int16_t **d = (int16_t **) dst;
856 uint32_t i, j, n_channels = conv->n_channels;
857
858 for (j = 0; j < n_samples; j++) {
859 for (i = 0; i < n_channels; i++)
860 d[i][j] = F32_TO_S16(*s++);
861 }
862 }
863
864 void
conv_f32d_to_s16_c(struct convert * conv,void * SPA_RESTRICT dst[],const void * SPA_RESTRICT src[],uint32_t n_samples)865 conv_f32d_to_s16_c(struct convert *conv, void * SPA_RESTRICT dst[], const void * SPA_RESTRICT src[],
866 uint32_t n_samples)
867 {
868 const float **s = (const float **) src;
869 int16_t *d = dst[0];
870 uint32_t i, j, n_channels = conv->n_channels;
871
872 for (j = 0; j < n_samples; j++) {
873 for (i = 0; i < n_channels; i++)
874 *d++ = F32_TO_S16(s[i][j]);
875 }
876 }
877
878 void
conv_f32d_to_s16s_c(struct convert * conv,void * SPA_RESTRICT dst[],const void * SPA_RESTRICT src[],uint32_t n_samples)879 conv_f32d_to_s16s_c(struct convert *conv, void * SPA_RESTRICT dst[], const void * SPA_RESTRICT src[],
880 uint32_t n_samples)
881 {
882 const float **s = (const float **) src;
883 int16_t *d = dst[0];
884 uint32_t i, j, n_channels = conv->n_channels;
885
886 for (j = 0; j < n_samples; j++) {
887 for (i = 0; i < n_channels; i++)
888 *d++ = F32_TO_S16S(s[i][j]);
889 }
890 }
891
892 void
conv_f32_to_u32_c(struct convert * conv,void * SPA_RESTRICT dst[],const void * SPA_RESTRICT src[],uint32_t n_samples)893 conv_f32_to_u32_c(struct convert *conv, void * SPA_RESTRICT dst[], const void * SPA_RESTRICT src[],
894 uint32_t n_samples)
895 {
896 uint32_t i, n_channels = conv->n_channels;
897 const float *s = src[0];
898 uint32_t *d = dst[0];
899
900 n_samples *= n_channels;
901
902 for (i = 0; i < n_samples; i++)
903 d[i] = F32_TO_U32(s[i]);
904 }
905
906 void
conv_f32d_to_u32_c(struct convert * conv,void * SPA_RESTRICT dst[],const void * SPA_RESTRICT src[],uint32_t n_samples)907 conv_f32d_to_u32_c(struct convert *conv, void * SPA_RESTRICT dst[], const void * SPA_RESTRICT src[],
908 uint32_t n_samples)
909 {
910 const float **s = (const float **) src;
911 uint32_t *d = dst[0];
912 uint32_t i, j, n_channels = conv->n_channels;
913
914 for (j = 0; j < n_samples; j++) {
915 for (i = 0; i < n_channels; i++)
916 *d++ = F32_TO_U32(s[i][j]);
917 }
918 }
919
920 void
conv_f32d_to_s32d_c(struct convert * conv,void * SPA_RESTRICT dst[],const void * SPA_RESTRICT src[],uint32_t n_samples)921 conv_f32d_to_s32d_c(struct convert *conv, void * SPA_RESTRICT dst[], const void * SPA_RESTRICT src[],
922 uint32_t n_samples)
923 {
924 uint32_t i, j, n_channels = conv->n_channels;
925
926 for (i = 0; i < n_channels; i++) {
927 const float *s = src[i];
928 int32_t *d = dst[i];
929
930 for (j = 0; j < n_samples; j++)
931 d[j] = F32_TO_S32(s[j]);
932 }
933 }
934
935 void
conv_f32_to_s32_c(struct convert * conv,void * SPA_RESTRICT dst[],const void * SPA_RESTRICT src[],uint32_t n_samples)936 conv_f32_to_s32_c(struct convert *conv, void * SPA_RESTRICT dst[], const void * SPA_RESTRICT src[],
937 uint32_t n_samples)
938 {
939 uint32_t i, n_channels = conv->n_channels;
940 const float *s = src[0];
941 int32_t *d = dst[0];
942
943 n_samples *= n_channels;
944
945 for (i = 0; i < n_samples; i++)
946 d[i] = F32_TO_S32(s[i]);
947 }
948
949 void
conv_f32_to_s32d_c(struct convert * conv,void * SPA_RESTRICT dst[],const void * SPA_RESTRICT src[],uint32_t n_samples)950 conv_f32_to_s32d_c(struct convert *conv, void * SPA_RESTRICT dst[], const void * SPA_RESTRICT src[],
951 uint32_t n_samples)
952 {
953 const float *s = src[0];
954 int32_t **d = (int32_t **) dst;
955 uint32_t i, j, n_channels = conv->n_channels;
956
957 for (j = 0; j < n_samples; j++) {
958 for (i = 0; i < n_channels; i++)
959 d[i][j] = F32_TO_S32(*s++);
960 }
961 }
962
963 void
conv_f32d_to_s32_c(struct convert * conv,void * SPA_RESTRICT dst[],const void * SPA_RESTRICT src[],uint32_t n_samples)964 conv_f32d_to_s32_c(struct convert *conv, void * SPA_RESTRICT dst[], const void * SPA_RESTRICT src[],
965 uint32_t n_samples)
966 {
967 const float **s = (const float **) src;
968 int32_t *d = dst[0];
969 uint32_t i, j, n_channels = conv->n_channels;
970
971 for (j = 0; j < n_samples; j++) {
972 for (i = 0; i < n_channels; i++)
973 *d++ = F32_TO_S32(s[i][j]);
974 }
975 }
976
977 void
conv_f32d_to_s32s_c(struct convert * conv,void * SPA_RESTRICT dst[],const void * SPA_RESTRICT src[],uint32_t n_samples)978 conv_f32d_to_s32s_c(struct convert *conv, void * SPA_RESTRICT dst[], const void * SPA_RESTRICT src[],
979 uint32_t n_samples)
980 {
981 const float **s = (const float **) src;
982 int32_t *d = dst[0];
983 uint32_t i, j, n_channels = conv->n_channels;
984
985 for (j = 0; j < n_samples; j++) {
986 for (i = 0; i < n_channels; i++)
987 *d++ = F32_TO_S32S(s[i][j]);
988 }
989 }
990
991 void
conv_f32_to_u24_c(struct convert * conv,void * SPA_RESTRICT dst[],const void * SPA_RESTRICT src[],uint32_t n_samples)992 conv_f32_to_u24_c(struct convert *conv, void * SPA_RESTRICT dst[], const void * SPA_RESTRICT src[],
993 uint32_t n_samples)
994 {
995 uint32_t i, n_channels = conv->n_channels;
996 const float *s = src[0];
997 uint8_t *d = dst[0];
998
999 n_samples *= n_channels;
1000
1001 for (i = 0; i < n_samples; i++) {
1002 write_u24(d, F32_TO_U24(s[i]));
1003 d += 3;
1004 }
1005 }
1006
1007 void
conv_f32d_to_u24_c(struct convert * conv,void * SPA_RESTRICT dst[],const void * SPA_RESTRICT src[],uint32_t n_samples)1008 conv_f32d_to_u24_c(struct convert *conv, void * SPA_RESTRICT dst[], const void * SPA_RESTRICT src[],
1009 uint32_t n_samples)
1010 {
1011 const float **s = (const float **) src;
1012 uint8_t *d = dst[0];
1013 uint32_t i, j, n_channels = conv->n_channels;
1014
1015 for (j = 0; j < n_samples; j++) {
1016 for (i = 0; i < n_channels; i++) {
1017 write_u24(d, F32_TO_U24(s[i][j]));
1018 d += 3;
1019 }
1020 }
1021 }
1022
1023 void
conv_f32d_to_s24d_c(struct convert * conv,void * SPA_RESTRICT dst[],const void * SPA_RESTRICT src[],uint32_t n_samples)1024 conv_f32d_to_s24d_c(struct convert *conv, void * SPA_RESTRICT dst[], const void * SPA_RESTRICT src[],
1025 uint32_t n_samples)
1026 {
1027 uint32_t i, j, n_channels = conv->n_channels;
1028
1029 for (i = 0; i < n_channels; i++) {
1030 const float *s = src[i];
1031 uint8_t *d = dst[i];
1032
1033 for (j = 0; j < n_samples; j++) {
1034 write_s24(d, F32_TO_S24(s[j]));
1035 d += 3;
1036 }
1037 }
1038 }
1039
1040 void
conv_f32_to_s24_c(struct convert * conv,void * SPA_RESTRICT dst[],const void * SPA_RESTRICT src[],uint32_t n_samples)1041 conv_f32_to_s24_c(struct convert *conv, void * SPA_RESTRICT dst[], const void * SPA_RESTRICT src[],
1042 uint32_t n_samples)
1043 {
1044 uint32_t i, n_channels = conv->n_channels;
1045 const float *s = src[0];
1046 uint8_t *d = dst[0];
1047
1048 n_samples *= n_channels;
1049
1050 for (i = 0; i < n_samples; i++) {
1051 write_s24(d, F32_TO_S24(s[i]));
1052 d += 3;
1053 }
1054 }
1055
1056 void
conv_f32_to_s24d_c(struct convert * conv,void * SPA_RESTRICT dst[],const void * SPA_RESTRICT src[],uint32_t n_samples)1057 conv_f32_to_s24d_c(struct convert *conv, void * SPA_RESTRICT dst[], const void * SPA_RESTRICT src[],
1058 uint32_t n_samples)
1059 {
1060 const float *s = src[0];
1061 uint8_t **d = (uint8_t **) dst;
1062 uint32_t i, j, n_channels = conv->n_channels;
1063
1064 for (j = 0; j < n_samples; j++) {
1065 for (i = 0; i < n_channels; i++) {
1066 write_s24(&d[i][j*3], F32_TO_S24(*s++));
1067 }
1068 }
1069 }
1070
1071 void
conv_f32d_to_s24_c(struct convert * conv,void * SPA_RESTRICT dst[],const void * SPA_RESTRICT src[],uint32_t n_samples)1072 conv_f32d_to_s24_c(struct convert *conv, void * SPA_RESTRICT dst[], const void * SPA_RESTRICT src[],
1073 uint32_t n_samples)
1074 {
1075 const float **s = (const float **) src;
1076 uint8_t *d = dst[0];
1077 uint32_t i, j, n_channels = conv->n_channels;
1078
1079 for (j = 0; j < n_samples; j++) {
1080 for (i = 0; i < n_channels; i++) {
1081 write_s24(d, F32_TO_S24(s[i][j]));
1082 d += 3;
1083 }
1084 }
1085 }
1086
1087 void
conv_f32d_to_s24s_c(struct convert * conv,void * SPA_RESTRICT dst[],const void * SPA_RESTRICT src[],uint32_t n_samples)1088 conv_f32d_to_s24s_c(struct convert *conv, void * SPA_RESTRICT dst[], const void * SPA_RESTRICT src[],
1089 uint32_t n_samples)
1090 {
1091 const float **s = (const float **) src;
1092 uint8_t *d = dst[0];
1093 uint32_t i, j, n_channels = conv->n_channels;
1094
1095 for (j = 0; j < n_samples; j++) {
1096 for (i = 0; i < n_channels; i++) {
1097 write_s24s(d, F32_TO_S24(s[i][j]));
1098 d += 3;
1099 }
1100 }
1101 }
1102
1103
1104 void
conv_f32d_to_s24_32d_c(struct convert * conv,void * SPA_RESTRICT dst[],const void * SPA_RESTRICT src[],uint32_t n_samples)1105 conv_f32d_to_s24_32d_c(struct convert *conv, void * SPA_RESTRICT dst[], const void * SPA_RESTRICT src[],
1106 uint32_t n_samples)
1107 {
1108 uint32_t i, j, n_channels = conv->n_channels;
1109
1110 for (i = 0; i < n_channels; i++) {
1111 const float *s = src[i];
1112 int32_t *d = dst[i];
1113
1114 for (j = 0; j < n_samples; j++)
1115 d[j] = F32_TO_S24_32(s[j]);
1116 }
1117 }
1118
1119 void
conv_f32_to_u24_32_c(struct convert * conv,void * SPA_RESTRICT dst[],const void * SPA_RESTRICT src[],uint32_t n_samples)1120 conv_f32_to_u24_32_c(struct convert *conv, void * SPA_RESTRICT dst[], const void * SPA_RESTRICT src[],
1121 uint32_t n_samples)
1122 {
1123 uint32_t i, n_channels = conv->n_channels;
1124 const float *s = src[0];
1125 uint32_t *d = dst[0];
1126
1127 n_samples *= n_channels;
1128
1129 for (i = 0; i < n_samples; i++)
1130 d[i] = F32_TO_U24_32(s[i]);
1131 }
1132
1133 void
conv_f32d_to_u24_32_c(struct convert * conv,void * SPA_RESTRICT dst[],const void * SPA_RESTRICT src[],uint32_t n_samples)1134 conv_f32d_to_u24_32_c(struct convert *conv, void * SPA_RESTRICT dst[], const void * SPA_RESTRICT src[],
1135 uint32_t n_samples)
1136 {
1137 const float **s = (const float **) src;
1138 uint32_t *d = dst[0];
1139 uint32_t i, j, n_channels = conv->n_channels;
1140
1141 for (j = 0; j < n_samples; j++) {
1142 for (i = 0; i < n_channels; i++)
1143 *d++ = F32_TO_U24_32(s[i][j]);
1144 }
1145 }
1146
1147 void
conv_f32_to_s24_32_c(struct convert * conv,void * SPA_RESTRICT dst[],const void * SPA_RESTRICT src[],uint32_t n_samples)1148 conv_f32_to_s24_32_c(struct convert *conv, void * SPA_RESTRICT dst[], const void * SPA_RESTRICT src[],
1149 uint32_t n_samples)
1150 {
1151 uint32_t i, n_channels = conv->n_channels;
1152 const float *s = src[0];
1153 int32_t *d = dst[0];
1154
1155 n_samples *= n_channels;
1156
1157 for (i = 0; i < n_samples; i++)
1158 d[i] = F32_TO_S24_32(s[i]);
1159 }
1160
1161 void
conv_f32_to_s24_32d_c(struct convert * conv,void * SPA_RESTRICT dst[],const void * SPA_RESTRICT src[],uint32_t n_samples)1162 conv_f32_to_s24_32d_c(struct convert *conv, void * SPA_RESTRICT dst[], const void * SPA_RESTRICT src[],
1163 uint32_t n_samples)
1164 {
1165 const float *s = src[0];
1166 int32_t **d = (int32_t **) dst;
1167 uint32_t i, j, n_channels = conv->n_channels;
1168
1169 for (j = 0; j < n_samples; j++) {
1170 for (i = 0; i < n_channels; i++)
1171 d[i][j] = F32_TO_S24_32(*s++);
1172 }
1173 }
1174
1175 void
conv_f32d_to_s24_32_c(struct convert * conv,void * SPA_RESTRICT dst[],const void * SPA_RESTRICT src[],uint32_t n_samples)1176 conv_f32d_to_s24_32_c(struct convert *conv, void * SPA_RESTRICT dst[], const void * SPA_RESTRICT src[],
1177 uint32_t n_samples)
1178 {
1179 const float **s = (const float **) src;
1180 int32_t *d = dst[0];
1181 uint32_t i, j, n_channels = conv->n_channels;
1182
1183 for (j = 0; j < n_samples; j++) {
1184 for (i = 0; i < n_channels; i++)
1185 *d++ = F32_TO_S24_32(s[i][j]);
1186 }
1187 }
1188
1189 void
conv_f32d_to_s24_32s_c(struct convert * conv,void * SPA_RESTRICT dst[],const void * SPA_RESTRICT src[],uint32_t n_samples)1190 conv_f32d_to_s24_32s_c(struct convert *conv, void * SPA_RESTRICT dst[], const void * SPA_RESTRICT src[],
1191 uint32_t n_samples)
1192 {
1193 const float **s = (const float **) src;
1194 int32_t *d = dst[0];
1195 uint32_t i, j, n_channels = conv->n_channels;
1196
1197 for (j = 0; j < n_samples; j++) {
1198 for (i = 0; i < n_channels; i++)
1199 *d++ = F32_TO_S24_32S(s[i][j]);
1200 }
1201 }
1202
1203 void
conv_deinterleave_8_c(struct convert * conv,void * SPA_RESTRICT dst[],const void * SPA_RESTRICT src[],uint32_t n_samples)1204 conv_deinterleave_8_c(struct convert *conv, void * SPA_RESTRICT dst[], const void * SPA_RESTRICT src[],
1205 uint32_t n_samples)
1206 {
1207 const uint8_t *s = src[0];
1208 uint8_t **d = (uint8_t **) dst;
1209 uint32_t i, j, n_channels = conv->n_channels;
1210
1211 for (j = 0; j < n_samples; j++) {
1212 for (i = 0; i < n_channels; i++)
1213 d[i][j] = *s++;
1214 }
1215 }
1216
1217 void
conv_deinterleave_16_c(struct convert * conv,void * SPA_RESTRICT dst[],const void * SPA_RESTRICT src[],uint32_t n_samples)1218 conv_deinterleave_16_c(struct convert *conv, void * SPA_RESTRICT dst[], const void * SPA_RESTRICT src[],
1219 uint32_t n_samples)
1220 {
1221 const uint16_t *s = src[0];
1222 uint16_t **d = (uint16_t **) dst;
1223 uint32_t i, j, n_channels = conv->n_channels;
1224
1225 for (j = 0; j < n_samples; j++) {
1226 for (i = 0; i < n_channels; i++)
1227 d[i][j] = *s++;
1228 }
1229 }
1230
1231 void
conv_deinterleave_24_c(struct convert * conv,void * SPA_RESTRICT dst[],const void * SPA_RESTRICT src[],uint32_t n_samples)1232 conv_deinterleave_24_c(struct convert *conv, void * SPA_RESTRICT dst[], const void * SPA_RESTRICT src[],
1233 uint32_t n_samples)
1234 {
1235 const uint8_t *s = src[0];
1236 uint8_t **d = (uint8_t **) dst;
1237 uint32_t i, j, n_channels = conv->n_channels;
1238
1239 for (j = 0; j < n_samples; j++) {
1240 for (i = 0; i < n_channels; i++) {
1241 write_s24(&d[i][j*3], read_s24(s));
1242 s += 3;
1243 }
1244 }
1245 }
1246
1247 void
conv_deinterleave_32_c(struct convert * conv,void * SPA_RESTRICT dst[],const void * SPA_RESTRICT src[],uint32_t n_samples)1248 conv_deinterleave_32_c(struct convert *conv, void * SPA_RESTRICT dst[], const void * SPA_RESTRICT src[],
1249 uint32_t n_samples)
1250 {
1251 const uint32_t *s = src[0];
1252 uint32_t **d = (uint32_t **) dst;
1253 uint32_t i, j, n_channels = conv->n_channels;
1254
1255 for (j = 0; j < n_samples; j++) {
1256 for (i = 0; i < n_channels; i++)
1257 d[i][j] = *s++;
1258 }
1259 }
1260
1261 void
conv_deinterleave_32s_c(struct convert * conv,void * SPA_RESTRICT dst[],const void * SPA_RESTRICT src[],uint32_t n_samples)1262 conv_deinterleave_32s_c(struct convert *conv, void * SPA_RESTRICT dst[], const void * SPA_RESTRICT src[],
1263 uint32_t n_samples)
1264 {
1265 const uint32_t *s = src[0];
1266 uint32_t **d = (uint32_t **) dst;
1267 uint32_t i, j, n_channels = conv->n_channels;
1268
1269 for (j = 0; j < n_samples; j++) {
1270 for (i = 0; i < n_channels; i++)
1271 d[i][j] = bswap_32(*s++);
1272 }
1273 }
1274
1275 void
conv_interleave_8_c(struct convert * conv,void * SPA_RESTRICT dst[],const void * SPA_RESTRICT src[],uint32_t n_samples)1276 conv_interleave_8_c(struct convert *conv, void * SPA_RESTRICT dst[], const void * SPA_RESTRICT src[],
1277 uint32_t n_samples)
1278 {
1279 const int8_t **s = (const int8_t **) src;
1280 uint8_t *d = dst[0];
1281 uint32_t i, j, n_channels = conv->n_channels;
1282
1283 for (j = 0; j < n_samples; j++) {
1284 for (i = 0; i < n_channels; i++)
1285 *d++ = s[i][j];
1286 }
1287 }
1288
1289 void
conv_interleave_16_c(struct convert * conv,void * SPA_RESTRICT dst[],const void * SPA_RESTRICT src[],uint32_t n_samples)1290 conv_interleave_16_c(struct convert *conv, void * SPA_RESTRICT dst[], const void * SPA_RESTRICT src[],
1291 uint32_t n_samples)
1292 {
1293 const int16_t **s = (const int16_t **) src;
1294 uint16_t *d = dst[0];
1295 uint32_t i, j, n_channels = conv->n_channels;
1296
1297 for (j = 0; j < n_samples; j++) {
1298 for (i = 0; i < n_channels; i++)
1299 *d++ = s[i][j];
1300 }
1301 }
1302
1303 void
conv_interleave_24_c(struct convert * conv,void * SPA_RESTRICT dst[],const void * SPA_RESTRICT src[],uint32_t n_samples)1304 conv_interleave_24_c(struct convert *conv, void * SPA_RESTRICT dst[], const void * SPA_RESTRICT src[],
1305 uint32_t n_samples)
1306 {
1307 const int8_t **s = (const int8_t **) src;
1308 uint8_t *d = dst[0];
1309 uint32_t i, j, n_channels = conv->n_channels;
1310
1311 for (j = 0; j < n_samples; j++) {
1312 for (i = 0; i < n_channels; i++) {
1313 write_s24(d, read_s24(&s[i][j*3]));
1314 d += 3;
1315 }
1316 }
1317 }
1318
1319 void
conv_interleave_32_c(struct convert * conv,void * SPA_RESTRICT dst[],const void * SPA_RESTRICT src[],uint32_t n_samples)1320 conv_interleave_32_c(struct convert *conv, void * SPA_RESTRICT dst[], const void * SPA_RESTRICT src[],
1321 uint32_t n_samples)
1322 {
1323 const int32_t **s = (const int32_t **) src;
1324 uint32_t *d = dst[0];
1325 uint32_t i, j, n_channels = conv->n_channels;
1326
1327 for (j = 0; j < n_samples; j++) {
1328 for (i = 0; i < n_channels; i++)
1329 *d++ = s[i][j];
1330 }
1331 }
1332
1333 void
conv_interleave_32s_c(struct convert * conv,void * SPA_RESTRICT dst[],const void * SPA_RESTRICT src[],uint32_t n_samples)1334 conv_interleave_32s_c(struct convert *conv, void * SPA_RESTRICT dst[], const void * SPA_RESTRICT src[],
1335 uint32_t n_samples)
1336 {
1337 const int32_t **s = (const int32_t **) src;
1338 uint32_t *d = dst[0];
1339 uint32_t i, j, n_channels = conv->n_channels;
1340
1341 for (j = 0; j < n_samples; j++) {
1342 for (i = 0; i < n_channels; i++)
1343 *d++ = bswap_32(s[i][j]);
1344 }
1345 }
1346