Remove trailing whitespace from most files
[mplayer/glamo.git] / libaf / reorder_ch.c
blob2cbedb8146fa772b7aa854618c633be7ed334e06
1 /*
2 * common functions for reordering audio channels
4 * Copyright (C) 2007 Ulion <ulion A gmail P com>
6 * This file is part of MPlayer.
8 * MPlayer is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * MPlayer is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <inttypes.h>
26 #include <string.h>
27 #include "libvo/fastmemcpy.h"
29 #include "reorder_ch.h"
31 #ifdef TEST
32 #define mp_msg(mod,lev, fmt, args... ) printf( fmt, ## args )
33 #else
34 #include "mp_msg.h"
35 #endif
38 #define REORDER_COPY_5(DEST,SRC,SAMPLES,S0,S1,S2,S3,S4) \
39 for (i = 0; i < SAMPLES; i += 5) {\
40 DEST[i] = SRC[i+S0];\
41 DEST[i+1] = SRC[i+S1];\
42 DEST[i+2] = SRC[i+S2];\
43 DEST[i+3] = SRC[i+S3];\
44 DEST[i+4] = SRC[i+S4];\
47 static int reorder_copy_5ch(void *dest, const void *src,
48 unsigned int samples, unsigned int samplesize,
49 int s0, int s1, int s2, int s3, int s4)
51 int i;
52 switch (samplesize) {
53 case 1:
55 int8_t *dest_8 = dest;
56 const int8_t *src_8 = src;
57 REORDER_COPY_5(dest_8,src_8,samples,s0,s1,s2,s3,s4);
58 break;
60 case 2:
62 int16_t *dest_16 = dest;
63 const int16_t *src_16 = src;
64 REORDER_COPY_5(dest_16,src_16,samples,s0,s1,s2,s3,s4);
65 break;
67 case 3:
69 int8_t *dest_8 = dest;
70 const int8_t *src_8 = src;
71 for (i = 0; i < samples; i += 15) {
72 dest_8[i] = src_8[i+s0*3];
73 dest_8[i+1] = src_8[i+s0*3+1];
74 dest_8[i+2] = src_8[i+s0*3+2];
75 dest_8[i+3] = src_8[i+s1*3];
76 dest_8[i+4] = src_8[i+s1*3+1];
77 dest_8[i+5] = src_8[i+s1*3+2];
78 dest_8[i+6] = src_8[i+s2*3];
79 dest_8[i+7] = src_8[i+s2*3+1];
80 dest_8[i+8] = src_8[i+s2*3+2];
81 dest_8[i+9] = src_8[i+s3*3];
82 dest_8[i+10] = src_8[i+s3*3+1];
83 dest_8[i+11] = src_8[i+s3*3+2];
84 dest_8[i+12] = src_8[i+s4*3];
85 dest_8[i+13] = src_8[i+s4*3+1];
86 dest_8[i+14] = src_8[i+s4*3+2];
89 case 4:
91 int32_t *dest_32 = dest;
92 const int32_t *src_32 = src;
93 REORDER_COPY_5(dest_32,src_32,samples,s0,s1,s2,s3,s4);
94 break;
96 case 8:
98 int64_t *dest_64 = dest;
99 const int64_t *src_64 = src;
100 REORDER_COPY_5(dest_64,src_64,samples,s0,s1,s2,s3,s4);
101 break;
103 default:
104 mp_msg(MSGT_GLOBAL, MSGL_WARN,
105 "[reorder_ch] Unsupported sample size: %d, please "
106 "report this error on the MPlayer mailing list.\n",samplesize);
107 return 0;
109 return 1;
112 #define REORDER_COPY_6(DEST,SRC,SAMPLES,S0,S1,S2,S3,S4,S5) \
113 for (i = 0; i < SAMPLES; i += 6) {\
114 DEST[i] = SRC[i+S0];\
115 DEST[i+1] = SRC[i+S1];\
116 DEST[i+2] = SRC[i+S2];\
117 DEST[i+3] = SRC[i+S3];\
118 DEST[i+4] = SRC[i+S4];\
119 DEST[i+5] = SRC[i+S5];\
122 static int reorder_copy_6ch(void *dest, const void *src,
123 unsigned int samples, uint8_t samplesize,
124 int s0, int s1, int s2, int s3, int s4, int s5)
126 int i;
127 switch (samplesize) {
128 case 1:
130 int8_t *dest_8 = dest;
131 const int8_t *src_8 = src;
132 REORDER_COPY_6(dest_8,src_8,samples,s0,s1,s2,s3,s4,s5);
133 break;
135 case 2:
137 int16_t *dest_16 = dest;
138 const int16_t *src_16 = src;
139 REORDER_COPY_6(dest_16,src_16,samples,s0,s1,s2,s3,s4,s5);
140 break;
142 case 3:
144 int8_t *dest_8 = dest;
145 const int8_t *src_8 = src;
146 for (i = 0; i < samples; i += 18) {
147 dest_8[i] = src_8[i+s0*3];
148 dest_8[i+1] = src_8[i+s0*3+1];
149 dest_8[i+2] = src_8[i+s0*3+2];
150 dest_8[i+3] = src_8[i+s1*3];
151 dest_8[i+4] = src_8[i+s1*3+1];
152 dest_8[i+5] = src_8[i+s1*3+2];
153 dest_8[i+6] = src_8[i+s2*3];
154 dest_8[i+7] = src_8[i+s2*3+1];
155 dest_8[i+8] = src_8[i+s2*3+2];
156 dest_8[i+9] = src_8[i+s3*3];
157 dest_8[i+10] = src_8[i+s3*3+1];
158 dest_8[i+11] = src_8[i+s3*3+2];
159 dest_8[i+12] = src_8[i+s4*3];
160 dest_8[i+13] = src_8[i+s4*3+1];
161 dest_8[i+14] = src_8[i+s4*3+2];
162 dest_8[i+15] = src_8[i+s5*3];
163 dest_8[i+16] = src_8[i+s5*3+1];
164 dest_8[i+17] = src_8[i+s5*3+2];
167 case 4:
169 int32_t *dest_32 = dest;
170 const int32_t *src_32 = src;
171 REORDER_COPY_6(dest_32,src_32,samples,s0,s1,s2,s3,s4,s5);
172 break;
174 case 8:
176 int64_t *dest_64 = dest;
177 const int64_t *src_64 = src;
178 REORDER_COPY_6(dest_64,src_64,samples,s0,s1,s2,s3,s4,s5);
179 break;
181 default:
182 mp_msg(MSGT_GLOBAL, MSGL_WARN,
183 "[reorder_ch] Unsupported sample size: %d, please "
184 "report this error on the MPlayer mailing list.\n",samplesize);
185 return 0;
187 return 1;
190 void reorder_channel_copy(void *src,
191 int src_layout,
192 void *dest,
193 int dest_layout,
194 int samples,
195 int samplesize)
197 if (dest_layout==src_layout) {
198 fast_memcpy(dest, src, samples*samplesize);
199 return;
201 if (!AF_IS_SAME_CH_NUM(dest_layout,src_layout)) {
202 mp_msg(MSGT_GLOBAL, MSGL_WARN, "[reorder_ch] different channel count "
203 "between src and dest: %x, %x\n",
204 AF_GET_CH_NUM_WITH_LFE(src_layout),
205 AF_GET_CH_NUM_WITH_LFE(dest_layout));
206 return;
208 switch ((src_layout<<16)|dest_layout) {
209 // AF_CHANNEL_LAYOUT_5_0_A L R C Ls Rs
210 // AF_CHANNEL_LAYOUT_5_0_B L R Ls Rs C
211 // AF_CHANNEL_LAYOUT_5_0_C L C R Ls Rs
212 // AF_CHANNEL_LAYOUT_5_0_D C L R Ls Rs
213 case AF_CHANNEL_LAYOUT_5_0_A << 16 | AF_CHANNEL_LAYOUT_5_0_B:
214 reorder_copy_5ch(dest, src, samples, samplesize, 0, 1, 3, 4, 2);
215 break;
216 case AF_CHANNEL_LAYOUT_5_0_A << 16 | AF_CHANNEL_LAYOUT_5_0_C:
217 reorder_copy_5ch(dest, src, samples, samplesize, 0, 2, 1, 3, 4);
218 break;
219 case AF_CHANNEL_LAYOUT_5_0_A << 16 | AF_CHANNEL_LAYOUT_5_0_D:
220 reorder_copy_5ch(dest, src, samples, samplesize, 2, 0, 1, 3, 4);
221 break;
222 case AF_CHANNEL_LAYOUT_5_0_B << 16 | AF_CHANNEL_LAYOUT_5_0_A:
223 reorder_copy_5ch(dest, src, samples, samplesize, 0, 1, 4, 2, 3);
224 break;
225 case AF_CHANNEL_LAYOUT_5_0_B << 16 | AF_CHANNEL_LAYOUT_5_0_C:
226 reorder_copy_5ch(dest, src, samples, samplesize, 0, 4, 1, 2, 3);
227 break;
228 case AF_CHANNEL_LAYOUT_5_0_B << 16 | AF_CHANNEL_LAYOUT_5_0_D:
229 reorder_copy_5ch(dest, src, samples, samplesize, 4, 0, 1, 2, 3);
230 break;
231 case AF_CHANNEL_LAYOUT_5_0_C << 16 | AF_CHANNEL_LAYOUT_5_0_A:
232 reorder_copy_5ch(dest, src, samples, samplesize, 0, 2, 1, 3, 4);
233 break;
234 case AF_CHANNEL_LAYOUT_5_0_C << 16 | AF_CHANNEL_LAYOUT_5_0_B:
235 reorder_copy_5ch(dest, src, samples, samplesize, 0, 2, 3, 4, 1);
236 break;
237 case AF_CHANNEL_LAYOUT_5_0_C << 16 | AF_CHANNEL_LAYOUT_5_0_D:
238 reorder_copy_5ch(dest, src, samples, samplesize, 1, 0, 2, 3, 4);
239 break;
240 case AF_CHANNEL_LAYOUT_5_0_D << 16 | AF_CHANNEL_LAYOUT_5_0_A:
241 reorder_copy_5ch(dest, src, samples, samplesize, 1, 2, 0, 3, 4);
242 break;
243 case AF_CHANNEL_LAYOUT_5_0_D << 16 | AF_CHANNEL_LAYOUT_5_0_B:
244 reorder_copy_5ch(dest, src, samples, samplesize, 1, 2, 3, 4, 0);
245 break;
246 case AF_CHANNEL_LAYOUT_5_0_D << 16 | AF_CHANNEL_LAYOUT_5_0_C:
247 reorder_copy_5ch(dest, src, samples, samplesize, 1, 0, 2, 3, 4);
248 break;
249 // AF_CHANNEL_LAYOUT_5_1_A L R C LFE Ls Rs
250 // AF_CHANNEL_LAYOUT_5_1_B L R Ls Rs C LFE
251 // AF_CHANNEL_LAYOUT_5_1_C L C R Ls Rs LFE
252 // AF_CHANNEL_LAYOUT_5_1_D C L R Ls Rs LFE
253 // AF_CHANNEL_LAYOUT_5_1_E LFE L C R Ls Rs
254 case AF_CHANNEL_LAYOUT_5_1_A << 16 | AF_CHANNEL_LAYOUT_5_1_B:
255 reorder_copy_6ch(dest, src, samples, samplesize, 0, 1, 4, 5, 2, 3);
256 break;
257 case AF_CHANNEL_LAYOUT_5_1_A << 16 | AF_CHANNEL_LAYOUT_5_1_C:
258 reorder_copy_6ch(dest, src, samples, samplesize, 0, 2, 1, 4, 5, 3);
259 break;
260 case AF_CHANNEL_LAYOUT_5_1_A << 16 | AF_CHANNEL_LAYOUT_5_1_D:
261 reorder_copy_6ch(dest, src, samples, samplesize, 2, 0, 1, 4, 5, 3);
262 break;
263 case AF_CHANNEL_LAYOUT_5_1_B << 16 | AF_CHANNEL_LAYOUT_5_1_A:
264 reorder_copy_6ch(dest, src, samples, samplesize, 0, 1, 4, 5, 2, 3);
265 break;
266 case AF_CHANNEL_LAYOUT_5_1_B << 16 | AF_CHANNEL_LAYOUT_5_1_C:
267 reorder_copy_6ch(dest, src, samples, samplesize, 0, 4, 1, 2, 3, 5);
268 break;
269 case AF_CHANNEL_LAYOUT_5_1_B << 16 | AF_CHANNEL_LAYOUT_5_1_D:
270 reorder_copy_6ch(dest, src, samples, samplesize, 4, 0, 1, 2, 3, 5);
271 break;
272 case AF_CHANNEL_LAYOUT_5_1_B << 16 | AF_CHANNEL_LAYOUT_5_1_E:
273 reorder_copy_6ch(dest, src, samples, samplesize, 5, 0, 4, 1, 2, 3);
274 break;
275 case AF_CHANNEL_LAYOUT_5_1_C << 16 | AF_CHANNEL_LAYOUT_5_1_A:
276 reorder_copy_6ch(dest, src, samples, samplesize, 0, 2, 1, 5, 3, 4);
277 break;
278 case AF_CHANNEL_LAYOUT_5_1_C << 16 | AF_CHANNEL_LAYOUT_5_1_B:
279 reorder_copy_6ch(dest, src, samples, samplesize, 0, 2, 3, 4, 1, 5);
280 break;
281 case AF_CHANNEL_LAYOUT_5_1_C << 16 | AF_CHANNEL_LAYOUT_5_1_D:
282 reorder_copy_6ch(dest, src, samples, samplesize, 1, 0, 2, 3, 4, 5);
283 break;
284 case AF_CHANNEL_LAYOUT_5_1_D << 16 | AF_CHANNEL_LAYOUT_5_1_A:
285 reorder_copy_6ch(dest, src, samples, samplesize, 1, 2, 0, 5, 3, 4);
286 break;
287 case AF_CHANNEL_LAYOUT_5_1_D << 16 | AF_CHANNEL_LAYOUT_5_1_B:
288 reorder_copy_6ch(dest, src, samples, samplesize, 1, 2, 3, 4, 0, 5);
289 break;
290 case AF_CHANNEL_LAYOUT_5_1_D << 16 | AF_CHANNEL_LAYOUT_5_1_C:
291 reorder_copy_6ch(dest, src, samples, samplesize, 1, 0, 2, 3, 4, 5);
292 break;
293 case AF_CHANNEL_LAYOUT_5_1_E << 16 | AF_CHANNEL_LAYOUT_5_1_B:
294 reorder_copy_6ch(dest, src, samples, samplesize, 1, 3, 4, 5, 2, 0);
295 break;
296 default:
297 mp_msg(MSGT_GLOBAL, MSGL_WARN, "[reorder_channel_copy] unsupport "
298 "from %x to %x, %d * %d\n", src_layout, dest_layout,
299 samples, samplesize);
300 fast_memcpy(dest, src, samples*samplesize);
305 #define REORDER_SELF_SWAP_2(SRC,TMP,SAMPLES,CHNUM,S0,S1) \
306 for (i = 0; i < SAMPLES; i += CHNUM) {\
307 TMP = SRC[i+S0];\
308 SRC[i+S0] = SRC[i+S1];\
309 SRC[i+S1] = TMP;\
312 static int reorder_self_2(void *src, unsigned int samples,
313 unsigned int samplesize, unsigned int chnum,
314 int s0, int s1)
316 int i;
317 switch (samplesize) {
318 case 1:
320 int8_t *src_8 = src;
321 int8_t tmp;
322 if (chnum==6) {
323 REORDER_SELF_SWAP_2(src_8,tmp,samples,6,s0,s1);
325 else {
326 REORDER_SELF_SWAP_2(src_8,tmp,samples,5,s0,s1);
328 break;
330 case 2:
332 int16_t *src_16 = src;
333 int16_t tmp;
334 if (chnum==6) {
335 REORDER_SELF_SWAP_2(src_16,tmp,samples,6,s0,s1);
337 else if (chnum==3) {
338 REORDER_SELF_SWAP_2(src_16,tmp,samples,3,s0,s1);
340 else {
341 REORDER_SELF_SWAP_2(src_16,tmp,samples,5,s0,s1);
343 break;
345 case 3:
347 int8_t *src_8 = src;
348 int8_t tmp0, tmp1, tmp2;
349 for (i = 0; i < samples; i += chnum*3) {
350 tmp0 = src_8[i+s0*3];
351 tmp1 = src_8[i+s0*3+1];
352 tmp2 = src_8[i+s0*3+2];
353 src_8[i+s0*3] = src_8[i+s1*3];
354 src_8[i+s0*3+1] = src_8[i+s1*3+1];
355 src_8[i+s0*3+2] = src_8[i+s1*3+2];
356 src_8[i+s1*3] = tmp0;
357 src_8[i+s1*3+1] = tmp1;
358 src_8[i+s1*3+2] = tmp2;
361 case 4:
363 int32_t *src_32 = src;
364 int32_t tmp;
365 if (chnum==6) {
366 REORDER_SELF_SWAP_2(src_32,tmp,samples,6,s0,s1);
368 else if (chnum==3) {
369 REORDER_SELF_SWAP_2(src_32,tmp,samples,3,s0,s1);
371 else {
372 REORDER_SELF_SWAP_2(src_32,tmp,samples,5,s0,s1);
374 break;
376 case 8:
378 int64_t *src_64 = src;
379 int64_t tmp;
380 if (chnum==6) {
381 REORDER_SELF_SWAP_2(src_64,tmp,samples,6,s0,s1);
383 else if (chnum==3) {
384 REORDER_SELF_SWAP_2(src_64,tmp,samples,3,s0,s1);
386 else {
387 REORDER_SELF_SWAP_2(src_64,tmp,samples,5,s0,s1);
389 break;
391 default:
392 mp_msg(MSGT_GLOBAL, MSGL_WARN,
393 "[reorder_ch] Unsupported sample size: %d, please "
394 "report this error on the MPlayer mailing list.\n",samplesize);
395 return 0;
397 return 1;
400 #define REORDER_SELF_SWAP_3(SRC,TMP,SAMPLES,CHNUM,S0,S1,S2) \
401 for (i = 0; i < SAMPLES; i += CHNUM) {\
402 TMP = SRC[i+S0];\
403 SRC[i+S0] = SRC[i+S1];\
404 SRC[i+S1] = SRC[i+S2];\
405 SRC[i+S2] = TMP;\
408 static int reorder_self_3(void *src, unsigned int samples,
409 unsigned int samplesize, unsigned int chnum,
410 int s0, int s1, int s2)
412 int i;
413 switch (samplesize) {
414 case 1:
416 int8_t *src_8 = src;
417 int8_t tmp;
418 if (chnum==6) {
419 REORDER_SELF_SWAP_3(src_8,tmp,samples,6,s0,s1,s2);
421 else {
422 REORDER_SELF_SWAP_3(src_8,tmp,samples,5,s0,s1,s2);
424 break;
426 case 2:
428 int16_t *src_16 = src;
429 int16_t tmp;
430 if (chnum==6) {
431 REORDER_SELF_SWAP_3(src_16,tmp,samples,6,s0,s1,s2);
433 else {
434 REORDER_SELF_SWAP_3(src_16,tmp,samples,5,s0,s1,s2);
436 break;
438 case 3:
440 int8_t *src_8 = src;
441 int8_t tmp0, tmp1, tmp2;
442 for (i = 0; i < samples; i += chnum*3) {
443 tmp0 = src_8[i+s0*3];
444 tmp1 = src_8[i+s0*3+1];
445 tmp2 = src_8[i+s0*3+2];
446 src_8[i+s0*3] = src_8[i+s1*3];
447 src_8[i+s0*3+1] = src_8[i+s1*3+1];
448 src_8[i+s0*3+2] = src_8[i+s1*3+2];
449 src_8[i+s1*3] = src_8[i+s2*3];
450 src_8[i+s1*3+1] = src_8[i+s2*3+1];
451 src_8[i+s1*3+2] = src_8[i+s2*3+2];
452 src_8[i+s2*3] = tmp0;
453 src_8[i+s2*3+1] = tmp1;
454 src_8[i+s2*3+2] = tmp2;
457 case 4:
459 int32_t *src_32 = src;
460 int32_t tmp;
461 if (chnum==6) {
462 REORDER_SELF_SWAP_3(src_32,tmp,samples,6,s0,s1,s2);
464 else {
465 REORDER_SELF_SWAP_3(src_32,tmp,samples,5,s0,s1,s2);
467 break;
469 case 8:
471 int64_t *src_64 = src;
472 int64_t tmp;
473 if (chnum==6) {
474 REORDER_SELF_SWAP_3(src_64,tmp,samples,6,s0,s1,s2);
476 else {
477 REORDER_SELF_SWAP_3(src_64,tmp,samples,5,s0,s1,s2);
479 break;
481 default:
482 mp_msg(MSGT_GLOBAL, MSGL_WARN,
483 "[reorder_ch] Unsupported sample size: %d, please "
484 "report this error on the MPlayer mailing list.\n",samplesize);
485 return 0;
487 return 1;
490 #define REORDER_SELF_SWAP_4_STEP_1(SRC,TMP,SAMPLES,CHNUM,S0,S1,S2,S3) \
491 for (i = 0; i < SAMPLES; i += CHNUM) {\
492 TMP = SRC[i+S0];\
493 SRC[i+S0] = SRC[i+S1];\
494 SRC[i+S1] = SRC[i+S2];\
495 SRC[i+S2] = SRC[i+S3];\
496 SRC[i+S3] = TMP;\
499 static int reorder_self_4_step_1(void *src, unsigned int samples,
500 unsigned int samplesize, unsigned int chnum,
501 int s0, int s1, int s2, int s3)
503 int i;
504 switch (samplesize) {
505 case 1:
507 int8_t *src_8 = src;
508 int8_t tmp;
509 if (chnum==6) {
510 REORDER_SELF_SWAP_4_STEP_1(src_8,tmp,samples,6,s0,s1,s2,s3);
512 else {
513 REORDER_SELF_SWAP_4_STEP_1(src_8,tmp,samples,5,s0,s1,s2,s3);
515 break;
517 case 2:
519 int16_t *src_16 = src;
520 int16_t tmp;
521 if (chnum==6) {
522 REORDER_SELF_SWAP_4_STEP_1(src_16,tmp,samples,6,s0,s1,s2,s3);
524 else {
525 REORDER_SELF_SWAP_4_STEP_1(src_16,tmp,samples,5,s0,s1,s2,s3);
527 break;
529 case 3:
531 int8_t *src_8 = src;
532 int8_t tmp0, tmp1, tmp2;
533 for (i = 0; i < samples; i += chnum*3) {
534 tmp0 = src_8[i+s0*3];
535 tmp1 = src_8[i+s0*3+1];
536 tmp2 = src_8[i+s0*3+2];
537 src_8[i+s0*3] = src_8[i+s1*3];
538 src_8[i+s0*3+1] = src_8[i+s1*3+1];
539 src_8[i+s0*3+2] = src_8[i+s1*3+2];
540 src_8[i+s1*3] = src_8[i+s2*3];
541 src_8[i+s1*3+1] = src_8[i+s2*3+1];
542 src_8[i+s1*3+2] = src_8[i+s2*3+2];
543 src_8[i+s2*3] = src_8[i+s3*3];
544 src_8[i+s2*3+1] = src_8[i+s3*3+1];
545 src_8[i+s2*3+2] = src_8[i+s3*3+2];
546 src_8[i+s3*3] = tmp0;
547 src_8[i+s3*3+1] = tmp1;
548 src_8[i+s3*3+2] = tmp2;
551 case 4:
553 int32_t *src_32 = src;
554 int32_t tmp;
555 if (chnum==6) {
556 REORDER_SELF_SWAP_4_STEP_1(src_32,tmp,samples,6,s0,s1,s2,s3);
558 else {
559 REORDER_SELF_SWAP_4_STEP_1(src_32,tmp,samples,5,s0,s1,s2,s3);
561 break;
563 case 8:
565 int64_t *src_64 = src;
566 int64_t tmp;
567 if (chnum==6) {
568 REORDER_SELF_SWAP_4_STEP_1(src_64,tmp,samples,6,s0,s1,s2,s3);
570 else {
571 REORDER_SELF_SWAP_4_STEP_1(src_64,tmp,samples,5,s0,s1,s2,s3);
573 break;
575 default:
576 mp_msg(MSGT_GLOBAL, MSGL_WARN,
577 "[reorder_ch] Unsupported sample size: %d, please "
578 "report this error on the MPlayer mailing list.\n",samplesize);
579 return 0;
581 return 1;
584 #define REORDER_SELF_SWAP_4_STEP_2(SRC,TMP,SAMPLES,CHNUM,S0,S1,S2,S3) \
585 for (i = 0; i < SAMPLES; i += CHNUM) {\
586 TMP = SRC[i+S0];\
587 SRC[i+S0] = SRC[i+S2];\
588 SRC[i+S2] = TMP;\
589 TMP = SRC[i+S1];\
590 SRC[i+S1] = SRC[i+S3];\
591 SRC[i+S3] = TMP;\
594 static int reorder_self_4_step_2(void *src, unsigned int samples,
595 unsigned int samplesize, unsigned int chnum,
596 int s0, int s1, int s2, int s3)
598 int i;
599 switch (samplesize) {
600 case 3:
602 int8_t *src_8 = src;
603 int8_t tmp0, tmp1, tmp2;
604 for (i = 0; i < samples; i += chnum*3) {
605 tmp0 = src_8[i+s0*3];
606 tmp1 = src_8[i+s0*3+1];
607 tmp2 = src_8[i+s0*3+2];
608 src_8[i+s0*3] = src_8[i+s2*3];
609 src_8[i+s0*3+1] = src_8[i+s2*3+1];
610 src_8[i+s0*3+2] = src_8[i+s2*3+2];
611 src_8[i+s2*3] = tmp0;
612 src_8[i+s2*3+1] = tmp1;
613 src_8[i+s2*3+2] = tmp2;
614 tmp0 = src_8[i+s1*3];
615 tmp1 = src_8[i+s1*3+1];
616 tmp2 = src_8[i+s1*3+2];
617 src_8[i+s1*3] = src_8[i+s3*3];
618 src_8[i+s1*3+1] = src_8[i+s3*3+1];
619 src_8[i+s1*3+2] = src_8[i+s3*3+2];
620 src_8[i+s3*3] = tmp0;
621 src_8[i+s3*3+1] = tmp1;
622 src_8[i+s3*3+2] = tmp2;
625 default:
626 mp_msg(MSGT_GLOBAL, MSGL_WARN,
627 "[reorder_ch] Unsupported sample size: %d, please "
628 "report this error on the MPlayer mailing list.\n",samplesize);
629 return 0;
631 return 1;
634 #define REORDER_SELF_SWAP_5_STEP_1(SRC,TMP,SAMPLES,CHNUM,S0,S1,S2,S3,S4) \
635 for (i = 0; i < SAMPLES; i += CHNUM) {\
636 TMP = SRC[i+S0];\
637 SRC[i+S0] = SRC[i+S1];\
638 SRC[i+S1] = SRC[i+S2];\
639 SRC[i+S2] = SRC[i+S3];\
640 SRC[i+S3] = SRC[i+S4];\
641 SRC[i+S4] = TMP;\
644 static int reorder_self_5_step_1(void *src, unsigned int samples,
645 unsigned int samplesize, unsigned int chnum,
646 int s0, int s1, int s2, int s3, int s4)
648 int i;
649 switch (samplesize) {
650 case 1:
652 int8_t *src_8 = src;
653 int8_t tmp;
654 if (chnum==6) {
655 REORDER_SELF_SWAP_5_STEP_1(src_8,tmp,samples,6,s0,s1,s2,s3,s4);
657 else {
658 REORDER_SELF_SWAP_5_STEP_1(src_8,tmp,samples,5,s0,s1,s2,s3,s4);
660 break;
662 case 2:
664 int16_t *src_16 = src;
665 int16_t tmp;
666 if (chnum==6) {
667 REORDER_SELF_SWAP_5_STEP_1(src_16,tmp,samples,6,s0,s1,s2,s3,s4);
669 else {
670 REORDER_SELF_SWAP_5_STEP_1(src_16,tmp,samples,5,s0,s1,s2,s3,s4);
672 break;
674 case 3:
676 int8_t *src_8 = src;
677 int8_t tmp0, tmp1, tmp2;
678 for (i = 0; i < samples; i += chnum*3) {
679 tmp0 = src_8[i+s0*3];
680 tmp1 = src_8[i+s0*3+1];
681 tmp2 = src_8[i+s0*3+2];
682 src_8[i+s0*3] = src_8[i+s1*3];
683 src_8[i+s0*3+1] = src_8[i+s1*3+1];
684 src_8[i+s0*3+2] = src_8[i+s1*3+2];
685 src_8[i+s1*3] = src_8[i+s2*3];
686 src_8[i+s1*3+1] = src_8[i+s2*3+1];
687 src_8[i+s1*3+2] = src_8[i+s2*3+2];
688 src_8[i+s2*3] = src_8[i+s3*3];
689 src_8[i+s2*3+1] = src_8[i+s3*3+1];
690 src_8[i+s2*3+2] = src_8[i+s3*3+2];
691 src_8[i+s3*3] = src_8[i+s4*3];
692 src_8[i+s3*3+1] = src_8[i+s4*3+1];
693 src_8[i+s3*3+2] = src_8[i+s4*3+2];
694 src_8[i+s4*3] = tmp0;
695 src_8[i+s4*3+1] = tmp1;
696 src_8[i+s4*3+2] = tmp2;
699 case 4:
701 int32_t *src_32 = src;
702 int32_t tmp;
703 if (chnum==6) {
704 REORDER_SELF_SWAP_5_STEP_1(src_32,tmp,samples,6,s0,s1,s2,s3,s4);
706 else {
707 REORDER_SELF_SWAP_5_STEP_1(src_32,tmp,samples,5,s0,s1,s2,s3,s4);
709 break;
711 case 8:
713 int64_t *src_64 = src;
714 int64_t tmp;
715 if (chnum==6) {
716 REORDER_SELF_SWAP_5_STEP_1(src_64,tmp,samples,6,s0,s1,s2,s3,s4);
718 else {
719 REORDER_SELF_SWAP_5_STEP_1(src_64,tmp,samples,5,s0,s1,s2,s3,s4);
721 break;
723 default:
724 mp_msg(MSGT_GLOBAL, MSGL_WARN,
725 "[reorder_ch] Unsupported sample size: %d, please "
726 "report this error on the MPlayer mailing list.\n",samplesize);
727 return 0;
729 return 1;
732 #define REORDER_SELF_SWAP_2_3(SRC,TMP,SAMPLES,CHNUM,S0,S1,S2,S3,S4) \
733 for (i = 0; i < SAMPLES; i += CHNUM) {\
734 TMP = SRC[i+S0];\
735 SRC[i+S0] = SRC[i+S1];\
736 SRC[i+S1] = TMP;\
737 TMP = SRC[i+S2];\
738 SRC[i+S2] = SRC[i+S3];\
739 SRC[i+S3] = SRC[i+S4];\
740 SRC[i+S4] = TMP;\
743 static int reorder_self_2_3(void *src, unsigned int samples,
744 unsigned int samplesize,
745 int s0, int s1, int s2, int s3, int s4)
747 int i;
748 switch (samplesize) {
749 case 1:
751 int8_t *src_8 = src;
752 int8_t tmp;
753 REORDER_SELF_SWAP_2_3(src_8,tmp,samples,6,s0,s1,s2,s3,s4);
754 break;
756 case 2:
758 int16_t *src_16 = src;
759 int16_t tmp;
760 REORDER_SELF_SWAP_2_3(src_16,tmp,samples,6,s0,s1,s2,s3,s4);
761 break;
763 case 3:
765 int8_t *src_8 = src;
766 int8_t tmp0, tmp1, tmp2;
767 for (i = 0; i < samples; i += 18) {
768 tmp0 = src_8[i+s0*3];
769 tmp1 = src_8[i+s0*3+1];
770 tmp2 = src_8[i+s0*3+2];
771 src_8[i+s0*3] = src_8[i+s1*3];
772 src_8[i+s0*3+1] = src_8[i+s1*3+1];
773 src_8[i+s0*3+2] = src_8[i+s1*3+2];
774 src_8[i+s1*3] = tmp0;
775 src_8[i+s1*3+1] = tmp1;
776 src_8[i+s1*3+2] = tmp2;
777 tmp0 = src_8[i+s2*3];
778 tmp1 = src_8[i+s2*3+1];
779 tmp2 = src_8[i+s2*3+2];
780 src_8[i+s2*3] = src_8[i+s3*3];
781 src_8[i+s2*3+1] = src_8[i+s3*3+1];
782 src_8[i+s2*3+2] = src_8[i+s3*3+2];
783 src_8[i+s3*3] = src_8[i+s4*3];
784 src_8[i+s3*3+1] = src_8[i+s4*3+1];
785 src_8[i+s3*3+2] = src_8[i+s4*3+2];
786 src_8[i+s4*3] = tmp0;
787 src_8[i+s4*3+1] = tmp1;
788 src_8[i+s4*3+2] = tmp2;
791 case 4:
793 int32_t *src_32 = src;
794 int32_t tmp;
795 REORDER_SELF_SWAP_2_3(src_32,tmp,samples,6,s0,s1,s2,s3,s4);
796 break;
798 case 8:
800 int64_t *src_64 = src;
801 int64_t tmp;
802 REORDER_SELF_SWAP_2_3(src_64,tmp,samples,6,s0,s1,s2,s3,s4);
803 break;
805 default:
806 mp_msg(MSGT_GLOBAL, MSGL_WARN,
807 "[reorder_ch] Unsupported sample size: %d, please "
808 "report this error on the MPlayer mailing list.\n",samplesize);
809 return 0;
811 return 1;
814 #define REORDER_SELF_SWAP_3_3(SRC,TMP,SAMPLES,CHNUM,S0,S1,S2,S3,S4,S5) \
815 for (i = 0; i < SAMPLES; i += CHNUM) {\
816 TMP = SRC[i+S0];\
817 SRC[i+S0] = SRC[i+S1];\
818 SRC[i+S1] = SRC[i+S2];\
819 SRC[i+S2] = TMP;\
820 TMP = SRC[i+S3];\
821 SRC[i+S3] = SRC[i+S4];\
822 SRC[i+S4] = SRC[i+S5];\
823 SRC[i+S5] = TMP;\
826 static int reorder_self_3_3(void *src, unsigned int samples,
827 unsigned int samplesize,
828 int s0, int s1, int s2, int s3, int s4, int s5)
830 int i;
831 switch (samplesize) {
832 case 1:
834 int8_t *src_8 = src;
835 int8_t tmp;
836 REORDER_SELF_SWAP_3_3(src_8,tmp,samples,6,s0,s1,s2,s3,s4,s5);
837 break;
839 case 2:
841 int16_t *src_16 = src;
842 int16_t tmp;
843 REORDER_SELF_SWAP_3_3(src_16,tmp,samples,6,s0,s1,s2,s3,s4,s5);
844 break;
846 case 3:
848 int8_t *src_8 = src;
849 int8_t tmp0, tmp1, tmp2;
850 for (i = 0; i < samples; i += 18) {
851 tmp0 = src_8[i+s0*3];
852 tmp1 = src_8[i+s0*3+1];
853 tmp2 = src_8[i+s0*3+2];
854 src_8[i+s0*3] = src_8[i+s1*3];
855 src_8[i+s0*3+1] = src_8[i+s1*3+1];
856 src_8[i+s0*3+2] = src_8[i+s1*3+2];
857 src_8[i+s1*3] = src_8[i+s2*3];
858 src_8[i+s1*3+1] = src_8[i+s2*3+1];
859 src_8[i+s1*3+2] = src_8[i+s2*3+2];
860 src_8[i+s2*3] = tmp0;
861 src_8[i+s2*3+1] = tmp1;
862 src_8[i+s2*3+2] = tmp2;
863 tmp0 = src_8[i+s3*3];
864 tmp1 = src_8[i+s3*3+1];
865 tmp2 = src_8[i+s3*3+2];
866 src_8[i+s3*3] = src_8[i+s4*3];
867 src_8[i+s3*3+1] = src_8[i+s4*3+1];
868 src_8[i+s3*3+2] = src_8[i+s4*3+2];
869 src_8[i+s4*3] = src_8[i+s5*3];
870 src_8[i+s4*3+1] = src_8[i+s5*3+1];
871 src_8[i+s4*3+2] = src_8[i+s5*3+2];
872 src_8[i+s5*3] = tmp0;
873 src_8[i+s5*3+1] = tmp1;
874 src_8[i+s5*3+2] = tmp2;
877 case 4:
879 int32_t *src_32 = src;
880 int32_t tmp;
881 REORDER_SELF_SWAP_3_3(src_32,tmp,samples,6,s0,s1,s2,s3,s4,s5);
882 break;
884 case 8:
886 int64_t *src_64 = src;
887 int64_t tmp;
888 REORDER_SELF_SWAP_3_3(src_64,tmp,samples,6,s0,s1,s2,s3,s4,s5);
889 break;
891 default:
892 mp_msg(MSGT_GLOBAL, MSGL_WARN,
893 "[reorder_ch] Unsupported sample size: %d, please "
894 "report this error on the MPlayer mailing list.\n",samplesize);
895 return 0;
897 return 1;
900 #define REORDER_SELF_SWAP_2_4(SRC,TMP,SAMPLES,CHNUM,S0,S1,S2,S3,S4,S5) \
901 for (i = 0; i < SAMPLES; i += CHNUM) {\
902 TMP = SRC[i+S0];\
903 SRC[i+S0] = SRC[i+S1];\
904 SRC[i+S1] = TMP;\
905 TMP = SRC[i+S2];\
906 SRC[i+S2] = SRC[i+S3];\
907 SRC[i+S3] = SRC[i+S4];\
908 SRC[i+S4] = SRC[i+S5];\
909 SRC[i+S5] = TMP;\
912 static int reorder_self_2_4(void *src, unsigned int samples,
913 unsigned int samplesize,
914 int s0, int s1, int s2, int s3, int s4, int s5)
916 int i;
917 switch (samplesize) {
918 case 1:
920 int8_t *src_8 = src;
921 int8_t tmp;
922 REORDER_SELF_SWAP_2_4(src_8,tmp,samples,6,s0,s1,s2,s3,s4,s5);
923 break;
925 case 2:
927 int16_t *src_16 = src;
928 int16_t tmp;
929 REORDER_SELF_SWAP_2_4(src_16,tmp,samples,6,s0,s1,s2,s3,s4,s5);
930 break;
932 case 3:
934 int8_t *src_8 = src;
935 int8_t tmp0, tmp1, tmp2;
936 for (i = 0; i < samples; i += 18) {
937 tmp0 = src_8[i+s0*3];
938 tmp1 = src_8[i+s0*3+1];
939 tmp2 = src_8[i+s0*3+2];
940 src_8[i+s0*3] = src_8[i+s1*3];
941 src_8[i+s0*3+1] = src_8[i+s1*3+1];
942 src_8[i+s0*3+2] = src_8[i+s1*3+2];
943 src_8[i+s1*3] = tmp0;
944 src_8[i+s1*3+1] = tmp1;
945 src_8[i+s1*3+2] = tmp2;
946 tmp0 = src_8[i+s2*3];
947 tmp1 = src_8[i+s2*3+1];
948 tmp2 = src_8[i+s2*3+2];
949 src_8[i+s2*3] = src_8[i+s3*3];
950 src_8[i+s2*3+1] = src_8[i+s3*3+1];
951 src_8[i+s2*3+2] = src_8[i+s3*3+2];
952 src_8[i+s3*3] = src_8[i+s4*3];
953 src_8[i+s3*3+1] = src_8[i+s4*3+1];
954 src_8[i+s3*3+2] = src_8[i+s4*3+2];
955 src_8[i+s4*3] = src_8[i+s5*3];
956 src_8[i+s4*3+1] = src_8[i+s5*3+1];
957 src_8[i+s4*3+2] = src_8[i+s5*3+2];
958 src_8[i+s5*3] = tmp0;
959 src_8[i+s5*3+1] = tmp1;
960 src_8[i+s5*3+2] = tmp2;
963 case 4:
965 int32_t *src_32 = src;
966 int32_t tmp;
967 REORDER_SELF_SWAP_2_4(src_32,tmp,samples,6,s0,s1,s2,s3,s4,s5);
968 break;
970 case 8:
972 int64_t *src_64 = src;
973 int64_t tmp;
974 REORDER_SELF_SWAP_2_4(src_64,tmp,samples,6,s0,s1,s2,s3,s4,s5);
975 break;
977 default:
978 mp_msg(MSGT_GLOBAL, MSGL_WARN,
979 "[reorder_ch] Unsupported sample size: %d, please "
980 "report this error on the MPlayer mailing list.\n",samplesize);
981 return 0;
983 return 1;
986 void reorder_channel(void *src,
987 int src_layout,
988 int dest_layout,
989 int samples,
990 int samplesize)
992 if (dest_layout==src_layout)
993 return;
994 if (!AF_IS_SAME_CH_NUM(dest_layout,src_layout)) {
995 mp_msg(MSGT_GLOBAL, MSGL_WARN,
996 "[reorder_channel] different channel count "
997 "between current and target: %x, %x\n",
998 AF_GET_CH_NUM_WITH_LFE(src_layout),
999 AF_GET_CH_NUM_WITH_LFE(dest_layout));
1000 return;
1002 switch ((src_layout<<16)|dest_layout) {
1003 // AF_CHANNEL_LAYOUT_5_0_A L R C Ls Rs
1004 // AF_CHANNEL_LAYOUT_5_0_B L R Ls Rs C
1005 // AF_CHANNEL_LAYOUT_5_0_C L C R Ls Rs
1006 // AF_CHANNEL_LAYOUT_5_0_D C L R Ls Rs
1007 case AF_CHANNEL_LAYOUT_5_0_A << 16 | AF_CHANNEL_LAYOUT_5_0_B:
1008 reorder_self_3(src, samples, samplesize, 5, 2, 3, 4);
1009 break;
1010 case AF_CHANNEL_LAYOUT_5_0_A << 16 | AF_CHANNEL_LAYOUT_5_0_C:
1011 reorder_self_2(src, samples, samplesize, 5, 1, 2);
1012 break;
1013 case AF_CHANNEL_LAYOUT_5_0_A << 16 | AF_CHANNEL_LAYOUT_5_0_D:
1014 reorder_self_3(src, samples, samplesize, 5, 2, 1, 0);
1015 break;
1016 case AF_CHANNEL_LAYOUT_5_0_B << 16 | AF_CHANNEL_LAYOUT_5_0_A:
1017 reorder_self_3(src, samples, samplesize, 5, 4, 3, 2);
1018 break;
1019 case AF_CHANNEL_LAYOUT_5_0_B << 16 | AF_CHANNEL_LAYOUT_5_0_C:
1020 reorder_self_4_step_1(src, samples, samplesize, 5, 4, 3, 2, 1);
1021 break;
1022 case AF_CHANNEL_LAYOUT_5_0_B << 16 | AF_CHANNEL_LAYOUT_5_0_D:
1023 reorder_self_5_step_1(src, samples, samplesize, 5, 4, 3, 2, 1, 0);
1024 break;
1025 case AF_CHANNEL_LAYOUT_5_0_C << 16 | AF_CHANNEL_LAYOUT_5_0_A:
1026 reorder_self_2(src, samples, samplesize, 5, 1, 2);
1027 break;
1028 case AF_CHANNEL_LAYOUT_5_0_C << 16 | AF_CHANNEL_LAYOUT_5_0_B:
1029 reorder_self_4_step_1(src, samples, samplesize, 5, 1, 2, 3, 4);
1030 break;
1031 case AF_CHANNEL_LAYOUT_5_0_C << 16 | AF_CHANNEL_LAYOUT_5_0_D:
1032 reorder_self_2(src, samples, samplesize, 5, 0, 1);
1033 break;
1034 case AF_CHANNEL_LAYOUT_5_0_D << 16 | AF_CHANNEL_LAYOUT_5_0_A:
1035 reorder_self_3(src, samples, samplesize, 5, 0, 1, 2);
1036 break;
1037 case AF_CHANNEL_LAYOUT_5_0_D << 16 | AF_CHANNEL_LAYOUT_5_0_B:
1038 reorder_self_5_step_1(src, samples, samplesize, 5, 0, 1, 2, 3, 4);
1039 break;
1040 case AF_CHANNEL_LAYOUT_5_0_D << 16 | AF_CHANNEL_LAYOUT_5_0_C:
1041 reorder_self_2(src, samples, samplesize, 5, 0, 1);
1042 break;
1043 // AF_CHANNEL_LAYOUT_5_1_A L R C LFE Ls Rs
1044 // AF_CHANNEL_LAYOUT_5_1_B L R Ls Rs C LFE
1045 // AF_CHANNEL_LAYOUT_5_1_C L C R Ls Rs LFE
1046 // AF_CHANNEL_LAYOUT_5_1_D C L R Ls Rs LFE
1047 // AF_CHANNEL_LAYOUT_5_1_E LFE L C R Ls Rs
1048 case AF_CHANNEL_LAYOUT_5_1_A << 16 | AF_CHANNEL_LAYOUT_5_1_B:
1049 if (samplesize != 3)
1050 reorder_self_2(src, samples/2, samplesize*2, 3, 1, 2);
1051 else
1052 reorder_self_4_step_2(src, samples, samplesize, 6, 2, 3, 4, 5);
1053 break;
1054 case AF_CHANNEL_LAYOUT_5_1_A << 16 | AF_CHANNEL_LAYOUT_5_1_C:
1055 reorder_self_2_3(src, samples, samplesize, 1, 2, 3, 4, 5);
1056 break;
1057 case AF_CHANNEL_LAYOUT_5_1_A << 16 | AF_CHANNEL_LAYOUT_5_1_D:
1058 reorder_self_3_3(src, samples, samplesize, 2, 1, 0, 3, 4, 5);
1059 break;
1060 case AF_CHANNEL_LAYOUT_5_1_B << 16 | AF_CHANNEL_LAYOUT_5_1_A:
1061 if (samplesize != 3)
1062 reorder_self_2(src, samples/2, samplesize*2, 3, 1, 2);
1063 else
1064 reorder_self_4_step_2(src, samples, samplesize, 6, 2, 3, 4, 5);
1065 break;
1066 case AF_CHANNEL_LAYOUT_5_1_B << 16 | AF_CHANNEL_LAYOUT_5_1_C:
1067 reorder_self_4_step_1(src, samples, samplesize, 6, 4, 3, 2, 1);
1068 break;
1069 case AF_CHANNEL_LAYOUT_5_1_B << 16 | AF_CHANNEL_LAYOUT_5_1_D:
1070 reorder_self_5_step_1(src, samples, samplesize, 6, 4, 3, 2, 1, 0);
1071 break;
1072 case AF_CHANNEL_LAYOUT_5_1_B << 16 | AF_CHANNEL_LAYOUT_5_1_E:
1073 reorder_self_2_4(src, samples, samplesize, 2, 4, 5, 3, 1, 0);
1074 break;
1075 case AF_CHANNEL_LAYOUT_5_1_C << 16 | AF_CHANNEL_LAYOUT_5_1_A:
1076 reorder_self_2_3(src, samples, samplesize, 1, 2, 5, 4, 3);
1077 break;
1078 case AF_CHANNEL_LAYOUT_5_1_C << 16 | AF_CHANNEL_LAYOUT_5_1_B:
1079 reorder_self_4_step_1(src, samples, samplesize, 6, 1, 2, 3, 4);
1080 break;
1081 case AF_CHANNEL_LAYOUT_5_1_C << 16 | AF_CHANNEL_LAYOUT_5_1_D:
1082 reorder_self_2(src, samples, samplesize, 6, 0, 1);
1083 break;
1084 case AF_CHANNEL_LAYOUT_5_1_D << 16 | AF_CHANNEL_LAYOUT_5_1_A:
1085 reorder_self_3_3(src, samples, samplesize, 0, 1, 2, 5, 4, 3);
1086 break;
1087 case AF_CHANNEL_LAYOUT_5_1_D << 16 | AF_CHANNEL_LAYOUT_5_1_B:
1088 reorder_self_5_step_1(src, samples, samplesize, 6, 0, 1, 2, 3, 4);
1089 break;
1090 case AF_CHANNEL_LAYOUT_5_1_D << 16 | AF_CHANNEL_LAYOUT_5_1_C:
1091 reorder_self_2(src, samples, samplesize, 6, 0, 1);
1092 break;
1093 case AF_CHANNEL_LAYOUT_5_1_E << 16 | AF_CHANNEL_LAYOUT_5_1_B:
1094 reorder_self_2_4(src, samples, samplesize, 2, 4, 0, 1, 3, 5);
1095 break;
1096 default:
1097 mp_msg(MSGT_GLOBAL, MSGL_WARN,
1098 "[reorder_channel] unsupported from %x to %x, %d * %d\n",
1099 src_layout, dest_layout, samples, samplesize);
1104 static int channel_layout_mapping_5ch[AF_CHANNEL_LAYOUT_SOURCE_NUM] = {
1105 AF_CHANNEL_LAYOUT_ALSA_5CH_DEFAULT,
1106 AF_CHANNEL_LAYOUT_AAC_5CH_DEFAULT,
1107 AF_CHANNEL_LAYOUT_WAVEEX_5CH_DEFAULT,
1108 AF_CHANNEL_LAYOUT_LAVC_AC3_5CH_DEFAULT,
1109 AF_CHANNEL_LAYOUT_LAVC_LIBA52_5CH_DEFAULT,
1110 AF_CHANNEL_LAYOUT_LAVC_DCA_5CH_DEFAULT,
1111 AF_CHANNEL_LAYOUT_VORBIS_5CH_DEFAULT,
1112 AF_CHANNEL_LAYOUT_FLAC_5CH_DEFAULT,
1115 static int channel_layout_mapping_6ch[AF_CHANNEL_LAYOUT_SOURCE_NUM] = {
1116 AF_CHANNEL_LAYOUT_ALSA_6CH_DEFAULT,
1117 AF_CHANNEL_LAYOUT_AAC_6CH_DEFAULT,
1118 AF_CHANNEL_LAYOUT_WAVEEX_6CH_DEFAULT,
1119 AF_CHANNEL_LAYOUT_LAVC_AC3_6CH_DEFAULT,
1120 AF_CHANNEL_LAYOUT_LAVC_LIBA52_6CH_DEFAULT,
1121 AF_CHANNEL_LAYOUT_LAVC_DCA_6CH_DEFAULT,
1122 AF_CHANNEL_LAYOUT_VORBIS_6CH_DEFAULT,
1123 AF_CHANNEL_LAYOUT_FLAC_6CH_DEFAULT,
1126 void reorder_channel_copy_nch(void *src,
1127 int src_layout,
1128 void *dest,
1129 int dest_layout,
1130 int chnum,
1131 int samples,
1132 int samplesize)
1134 if (chnum < 5 || chnum > 6 || src_layout < 0 || dest_layout < 0 ||
1135 src_layout >= AF_CHANNEL_LAYOUT_SOURCE_NUM ||
1136 dest_layout >= AF_CHANNEL_LAYOUT_SOURCE_NUM)
1137 fast_memcpy(dest, src, samples*samplesize);
1138 else if (chnum == 6)
1139 reorder_channel_copy(src, channel_layout_mapping_6ch[src_layout],
1140 dest, channel_layout_mapping_6ch[dest_layout],
1141 samples, samplesize);
1142 else
1143 reorder_channel_copy(src, channel_layout_mapping_5ch[src_layout],
1144 dest, channel_layout_mapping_5ch[dest_layout],
1145 samples, samplesize);
1148 void reorder_channel_nch(void *buf,
1149 int src_layout,
1150 int dest_layout,
1151 int chnum,
1152 int samples,
1153 int samplesize)
1155 if (src_layout == dest_layout || chnum < 5 || chnum > 6 ||
1156 src_layout < 0 || dest_layout < 0 ||
1157 src_layout >= AF_CHANNEL_LAYOUT_SOURCE_NUM ||
1158 dest_layout >= AF_CHANNEL_LAYOUT_SOURCE_NUM ||
1159 src_layout == dest_layout)
1160 return;
1161 if (chnum == 6)
1162 reorder_channel(buf, channel_layout_mapping_6ch[src_layout],
1163 channel_layout_mapping_6ch[dest_layout],
1164 samples, samplesize);
1165 else
1166 reorder_channel(buf, channel_layout_mapping_5ch[src_layout],
1167 channel_layout_mapping_5ch[dest_layout],
1168 samples, samplesize);
1172 #ifdef TEST
1174 static void test_copy(int channels) {
1175 int samples = 12*1024*1024;
1176 int samplesize = 2;
1177 int i;
1178 unsigned char *bufin = malloc((samples+100)*samplesize);
1179 unsigned char *bufout = malloc((samples+100)*samplesize);
1180 memset(bufin, 0xFF, samples*samplesize);
1181 for (i = 0;i < 100; ++i)
1182 reorder_channel_copy(bufin, AF_CHANNEL_LAYOUT_5_1_A,
1183 bufout, AF_CHANNEL_LAYOUT_5_1_B,
1184 samples, samplesize);
1185 // reorder_channel(bufin, AF_CHANNEL_LAYOUT_5_1_B,
1186 // AF_CHANNEL_LAYOUT_5_1_D,
1187 // samples, samplesize);
1188 free(bufin);
1189 free(bufout);
1192 int main(int argc, char *argv[]) {
1193 int channels = 6;
1194 if (argc > 1)
1195 channels = atoi(argv[1]);
1196 test_copy(channels);
1197 return 0;
1200 #endif