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.
27 #include "libvo/fastmemcpy.h"
29 #include "reorder_ch.h"
32 #define mp_msg(mod,lev, fmt, args... ) printf( fmt, ## args )
38 #define REORDER_COPY_5(DEST,SRC,SAMPLES,S0,S1,S2,S3,S4) \
39 for (i = 0; i < SAMPLES; i += 5) {\
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
)
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
);
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
);
69 int8_t *dest_8
= dest
;
70 const int8_t *src_8
= src
;
71 for (i
= 0; i
< samples
* 3; 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];
92 int32_t *dest_32
= dest
;
93 const int32_t *src_32
= src
;
94 REORDER_COPY_5(dest_32
,src_32
,samples
,s0
,s1
,s2
,s3
,s4
);
99 int64_t *dest_64
= dest
;
100 const int64_t *src_64
= src
;
101 REORDER_COPY_5(dest_64
,src_64
,samples
,s0
,s1
,s2
,s3
,s4
);
105 mp_msg(MSGT_GLOBAL
, MSGL_WARN
,
106 "[reorder_ch] Unsupported sample size: %d, please "
107 "report this error on the MPlayer mailing list.\n",samplesize
);
113 #define REORDER_COPY_6(DEST,SRC,SAMPLES,S0,S1,S2,S3,S4,S5) \
114 for (i = 0; i < SAMPLES; i += 6) {\
115 DEST[i] = SRC[i+S0];\
116 DEST[i+1] = SRC[i+S1];\
117 DEST[i+2] = SRC[i+S2];\
118 DEST[i+3] = SRC[i+S3];\
119 DEST[i+4] = SRC[i+S4];\
120 DEST[i+5] = SRC[i+S5];\
123 static int reorder_copy_6ch(void *dest
, const void *src
,
124 unsigned int samples
, uint8_t samplesize
,
125 int s0
, int s1
, int s2
, int s3
, int s4
, int s5
)
128 switch (samplesize
) {
131 int8_t *dest_8
= dest
;
132 const int8_t *src_8
= src
;
133 REORDER_COPY_6(dest_8
,src_8
,samples
,s0
,s1
,s2
,s3
,s4
,s5
);
138 int16_t *dest_16
= dest
;
139 const int16_t *src_16
= src
;
140 REORDER_COPY_6(dest_16
,src_16
,samples
,s0
,s1
,s2
,s3
,s4
,s5
);
145 int8_t *dest_8
= dest
;
146 const int8_t *src_8
= src
;
147 for (i
= 0; i
< samples
* 3; i
+= 18) {
148 dest_8
[i
] = src_8
[i
+s0
*3];
149 dest_8
[i
+1] = src_8
[i
+s0
*3+1];
150 dest_8
[i
+2] = src_8
[i
+s0
*3+2];
151 dest_8
[i
+3] = src_8
[i
+s1
*3];
152 dest_8
[i
+4] = src_8
[i
+s1
*3+1];
153 dest_8
[i
+5] = src_8
[i
+s1
*3+2];
154 dest_8
[i
+6] = src_8
[i
+s2
*3];
155 dest_8
[i
+7] = src_8
[i
+s2
*3+1];
156 dest_8
[i
+8] = src_8
[i
+s2
*3+2];
157 dest_8
[i
+9] = src_8
[i
+s3
*3];
158 dest_8
[i
+10] = src_8
[i
+s3
*3+1];
159 dest_8
[i
+11] = src_8
[i
+s3
*3+2];
160 dest_8
[i
+12] = src_8
[i
+s4
*3];
161 dest_8
[i
+13] = src_8
[i
+s4
*3+1];
162 dest_8
[i
+14] = src_8
[i
+s4
*3+2];
163 dest_8
[i
+15] = src_8
[i
+s5
*3];
164 dest_8
[i
+16] = src_8
[i
+s5
*3+1];
165 dest_8
[i
+17] = src_8
[i
+s5
*3+2];
171 int32_t *dest_32
= dest
;
172 const int32_t *src_32
= src
;
173 REORDER_COPY_6(dest_32
,src_32
,samples
,s0
,s1
,s2
,s3
,s4
,s5
);
178 int64_t *dest_64
= dest
;
179 const int64_t *src_64
= src
;
180 REORDER_COPY_6(dest_64
,src_64
,samples
,s0
,s1
,s2
,s3
,s4
,s5
);
184 mp_msg(MSGT_GLOBAL
, MSGL_WARN
,
185 "[reorder_ch] Unsupported sample size: %d, please "
186 "report this error on the MPlayer mailing list.\n",samplesize
);
192 #define REORDER_COPY_8(DEST,SRC,SAMPLES,S0,S1,S2,S3,S4,S5,S6,S7) \
193 for (i = 0; i < SAMPLES; i += 8) {\
194 DEST[i] = SRC[i+S0];\
195 DEST[i+1] = SRC[i+S1];\
196 DEST[i+2] = SRC[i+S2];\
197 DEST[i+3] = SRC[i+S3];\
198 DEST[i+4] = SRC[i+S4];\
199 DEST[i+5] = SRC[i+S5];\
200 DEST[i+6] = SRC[i+S6];\
201 DEST[i+7] = SRC[i+S7];\
204 static int reorder_copy_8ch(void *dest
, const void *src
,
205 unsigned int samples
, uint8_t samplesize
,
206 int s0
, int s1
, int s2
, int s3
,
207 int s4
, int s5
, int s6
, int s7
)
210 switch (samplesize
) {
213 int8_t *dest_8
= dest
;
214 const int8_t *src_8
= src
;
215 REORDER_COPY_8(dest_8
,src_8
,samples
,s0
,s1
,s2
,s3
,s4
,s5
,s6
,s7
);
220 int16_t *dest_16
= dest
;
221 const int16_t *src_16
= src
;
222 REORDER_COPY_8(dest_16
,src_16
,samples
,s0
,s1
,s2
,s3
,s4
,s5
,s6
,s7
);
227 int8_t *dest_8
= dest
;
228 const int8_t *src_8
= src
;
229 for (i
= 0; i
< samples
* 3; i
+= 24) {
230 dest_8
[i
] = src_8
[i
+s0
*3];
231 dest_8
[i
+1] = src_8
[i
+s0
*3+1];
232 dest_8
[i
+2] = src_8
[i
+s0
*3+2];
233 dest_8
[i
+3] = src_8
[i
+s1
*3];
234 dest_8
[i
+4] = src_8
[i
+s1
*3+1];
235 dest_8
[i
+5] = src_8
[i
+s1
*3+2];
236 dest_8
[i
+6] = src_8
[i
+s2
*3];
237 dest_8
[i
+7] = src_8
[i
+s2
*3+1];
238 dest_8
[i
+8] = src_8
[i
+s2
*3+2];
239 dest_8
[i
+9] = src_8
[i
+s3
*3];
240 dest_8
[i
+10] = src_8
[i
+s3
*3+1];
241 dest_8
[i
+11] = src_8
[i
+s3
*3+2];
242 dest_8
[i
+12] = src_8
[i
+s4
*3];
243 dest_8
[i
+13] = src_8
[i
+s4
*3+1];
244 dest_8
[i
+14] = src_8
[i
+s4
*3+2];
245 dest_8
[i
+15] = src_8
[i
+s5
*3];
246 dest_8
[i
+16] = src_8
[i
+s5
*3+1];
247 dest_8
[i
+17] = src_8
[i
+s5
*3+2];
248 dest_8
[i
+18] = src_8
[i
+s6
*3];
249 dest_8
[i
+19] = src_8
[i
+s6
*3+1];
250 dest_8
[i
+20] = src_8
[i
+s6
*3+2];
251 dest_8
[i
+21] = src_8
[i
+s7
*3];
252 dest_8
[i
+22] = src_8
[i
+s7
*3+1];
253 dest_8
[i
+23] = src_8
[i
+s7
*3+2];
259 int32_t *dest_32
= dest
;
260 const int32_t *src_32
= src
;
261 REORDER_COPY_8(dest_32
,src_32
,samples
,s0
,s1
,s2
,s3
,s4
,s5
,s6
,s7
);
266 int64_t *dest_64
= dest
;
267 const int64_t *src_64
= src
;
268 REORDER_COPY_8(dest_64
,src_64
,samples
,s0
,s1
,s2
,s3
,s4
,s5
,s6
,s7
);
272 mp_msg(MSGT_GLOBAL
, MSGL_WARN
,
273 "[reorder_ch] Unsupported sample size: %d, please "
274 "report this error on the MPlayer mailing list.\n",samplesize
);
280 void reorder_channel_copy(void *src
,
287 if (dest_layout
==src_layout
) {
288 fast_memcpy(dest
, src
, samples
*samplesize
);
291 if (!AF_IS_SAME_CH_NUM(dest_layout
,src_layout
)) {
292 mp_msg(MSGT_GLOBAL
, MSGL_WARN
, "[reorder_ch] different channel count "
293 "between src and dest: %x, %x\n",
294 AF_GET_CH_NUM_WITH_LFE(src_layout
),
295 AF_GET_CH_NUM_WITH_LFE(dest_layout
));
298 switch ((src_layout
<<16)|dest_layout
) {
299 // AF_CHANNEL_LAYOUT_5_0_A L R C Ls Rs
300 // AF_CHANNEL_LAYOUT_5_0_B L R Ls Rs C
301 // AF_CHANNEL_LAYOUT_5_0_C L C R Ls Rs
302 // AF_CHANNEL_LAYOUT_5_0_D C L R Ls Rs
303 case AF_CHANNEL_LAYOUT_5_0_A
<< 16 | AF_CHANNEL_LAYOUT_5_0_B
:
304 reorder_copy_5ch(dest
, src
, samples
, samplesize
, 0, 1, 3, 4, 2);
306 case AF_CHANNEL_LAYOUT_5_0_A
<< 16 | AF_CHANNEL_LAYOUT_5_0_C
:
307 reorder_copy_5ch(dest
, src
, samples
, samplesize
, 0, 2, 1, 3, 4);
309 case AF_CHANNEL_LAYOUT_5_0_A
<< 16 | AF_CHANNEL_LAYOUT_5_0_D
:
310 reorder_copy_5ch(dest
, src
, samples
, samplesize
, 2, 0, 1, 3, 4);
312 case AF_CHANNEL_LAYOUT_5_0_B
<< 16 | AF_CHANNEL_LAYOUT_5_0_A
:
313 reorder_copy_5ch(dest
, src
, samples
, samplesize
, 0, 1, 4, 2, 3);
315 case AF_CHANNEL_LAYOUT_5_0_B
<< 16 | AF_CHANNEL_LAYOUT_5_0_C
:
316 reorder_copy_5ch(dest
, src
, samples
, samplesize
, 0, 4, 1, 2, 3);
318 case AF_CHANNEL_LAYOUT_5_0_B
<< 16 | AF_CHANNEL_LAYOUT_5_0_D
:
319 reorder_copy_5ch(dest
, src
, samples
, samplesize
, 4, 0, 1, 2, 3);
321 case AF_CHANNEL_LAYOUT_5_0_C
<< 16 | AF_CHANNEL_LAYOUT_5_0_A
:
322 reorder_copy_5ch(dest
, src
, samples
, samplesize
, 0, 2, 1, 3, 4);
324 case AF_CHANNEL_LAYOUT_5_0_C
<< 16 | AF_CHANNEL_LAYOUT_5_0_B
:
325 reorder_copy_5ch(dest
, src
, samples
, samplesize
, 0, 2, 3, 4, 1);
327 case AF_CHANNEL_LAYOUT_5_0_C
<< 16 | AF_CHANNEL_LAYOUT_5_0_D
:
328 reorder_copy_5ch(dest
, src
, samples
, samplesize
, 1, 0, 2, 3, 4);
330 case AF_CHANNEL_LAYOUT_5_0_D
<< 16 | AF_CHANNEL_LAYOUT_5_0_A
:
331 reorder_copy_5ch(dest
, src
, samples
, samplesize
, 1, 2, 0, 3, 4);
333 case AF_CHANNEL_LAYOUT_5_0_D
<< 16 | AF_CHANNEL_LAYOUT_5_0_B
:
334 reorder_copy_5ch(dest
, src
, samples
, samplesize
, 1, 2, 3, 4, 0);
336 case AF_CHANNEL_LAYOUT_5_0_D
<< 16 | AF_CHANNEL_LAYOUT_5_0_C
:
337 reorder_copy_5ch(dest
, src
, samples
, samplesize
, 1, 0, 2, 3, 4);
339 // AF_CHANNEL_LAYOUT_5_1_A L R C LFE Ls Rs
340 // AF_CHANNEL_LAYOUT_5_1_B L R Ls Rs C LFE
341 // AF_CHANNEL_LAYOUT_5_1_C L C R Ls Rs LFE
342 // AF_CHANNEL_LAYOUT_5_1_D C L R Ls Rs LFE
343 // AF_CHANNEL_LAYOUT_5_1_E LFE L C R Ls Rs
344 case AF_CHANNEL_LAYOUT_5_1_A
<< 16 | AF_CHANNEL_LAYOUT_5_1_B
:
345 reorder_copy_6ch(dest
, src
, samples
, samplesize
, 0, 1, 4, 5, 2, 3);
347 case AF_CHANNEL_LAYOUT_5_1_A
<< 16 | AF_CHANNEL_LAYOUT_5_1_C
:
348 reorder_copy_6ch(dest
, src
, samples
, samplesize
, 0, 2, 1, 4, 5, 3);
350 case AF_CHANNEL_LAYOUT_5_1_A
<< 16 | AF_CHANNEL_LAYOUT_5_1_D
:
351 reorder_copy_6ch(dest
, src
, samples
, samplesize
, 2, 0, 1, 4, 5, 3);
353 case AF_CHANNEL_LAYOUT_5_1_B
<< 16 | AF_CHANNEL_LAYOUT_5_1_A
:
354 reorder_copy_6ch(dest
, src
, samples
, samplesize
, 0, 1, 4, 5, 2, 3);
356 case AF_CHANNEL_LAYOUT_5_1_B
<< 16 | AF_CHANNEL_LAYOUT_5_1_C
:
357 reorder_copy_6ch(dest
, src
, samples
, samplesize
, 0, 4, 1, 2, 3, 5);
359 case AF_CHANNEL_LAYOUT_5_1_B
<< 16 | AF_CHANNEL_LAYOUT_5_1_D
:
360 reorder_copy_6ch(dest
, src
, samples
, samplesize
, 4, 0, 1, 2, 3, 5);
362 case AF_CHANNEL_LAYOUT_5_1_B
<< 16 | AF_CHANNEL_LAYOUT_5_1_E
:
363 reorder_copy_6ch(dest
, src
, samples
, samplesize
, 5, 0, 4, 1, 2, 3);
365 case AF_CHANNEL_LAYOUT_5_1_C
<< 16 | AF_CHANNEL_LAYOUT_5_1_A
:
366 reorder_copy_6ch(dest
, src
, samples
, samplesize
, 0, 2, 1, 5, 3, 4);
368 case AF_CHANNEL_LAYOUT_5_1_C
<< 16 | AF_CHANNEL_LAYOUT_5_1_B
:
369 reorder_copy_6ch(dest
, src
, samples
, samplesize
, 0, 2, 3, 4, 1, 5);
371 case AF_CHANNEL_LAYOUT_5_1_C
<< 16 | AF_CHANNEL_LAYOUT_5_1_D
:
372 reorder_copy_6ch(dest
, src
, samples
, samplesize
, 1, 0, 2, 3, 4, 5);
374 case AF_CHANNEL_LAYOUT_5_1_D
<< 16 | AF_CHANNEL_LAYOUT_5_1_A
:
375 reorder_copy_6ch(dest
, src
, samples
, samplesize
, 1, 2, 0, 5, 3, 4);
377 case AF_CHANNEL_LAYOUT_5_1_D
<< 16 | AF_CHANNEL_LAYOUT_5_1_B
:
378 reorder_copy_6ch(dest
, src
, samples
, samplesize
, 1, 2, 3, 4, 0, 5);
380 case AF_CHANNEL_LAYOUT_5_1_D
<< 16 | AF_CHANNEL_LAYOUT_5_1_C
:
381 reorder_copy_6ch(dest
, src
, samples
, samplesize
, 1, 0, 2, 3, 4, 5);
383 case AF_CHANNEL_LAYOUT_5_1_E
<< 16 | AF_CHANNEL_LAYOUT_5_1_B
:
384 reorder_copy_6ch(dest
, src
, samples
, samplesize
, 1, 3, 4, 5, 2, 0);
386 case AF_CHANNEL_LAYOUT_5_1_F
<< 16 | AF_CHANNEL_LAYOUT_5_1_B
:
387 reorder_copy_6ch(dest
, src
, samples
, samplesize
, 1, 2, 4, 5, 0, 3);
389 // AF_CHANNEL_LAYOUT_7_1_A L R C LFE Ls Rs Rls Rrs
390 // AF_CHANNEL_LAYOUT_7_1_B L R Ls Rs C LFE Rls Rrs
391 // AF_CHANNEL_LAYOUT_7_1_D C L R Ls Rs Rls Rrs LFE
392 case AF_CHANNEL_LAYOUT_7_1_A
<< 16 | AF_CHANNEL_LAYOUT_7_1_B
:
393 case AF_CHANNEL_LAYOUT_7_1_B
<< 16 | AF_CHANNEL_LAYOUT_7_1_A
:
394 reorder_copy_8ch(dest
, src
, samples
, samplesize
, 0, 1, 4, 5, 2, 3, 6, 7);
396 case AF_CHANNEL_LAYOUT_7_1_D
<< 16 | AF_CHANNEL_LAYOUT_7_1_B
:
397 reorder_copy_8ch(dest
, src
, samples
, samplesize
, 1, 2, 3, 4, 0, 7, 5, 6);
400 mp_msg(MSGT_GLOBAL
, MSGL_WARN
, "[reorder_channel_copy] unsupport "
401 "from %x to %x, %d * %d\n", src_layout
, dest_layout
,
402 samples
, samplesize
);
403 fast_memcpy(dest
, src
, samples
*samplesize
);
408 #define REORDER_SELF_SWAP_2(SRC,TMP,SAMPLES,CHNUM,S0,S1) \
409 for (i = 0; i < SAMPLES; i += CHNUM) {\
411 SRC[i+S0] = SRC[i+S1];\
415 static int reorder_self_2(void *src
, unsigned int samples
,
416 unsigned int samplesize
, unsigned int chnum
,
420 switch (samplesize
) {
426 REORDER_SELF_SWAP_2(src_8
,tmp
,samples
,6,s0
,s1
);
429 REORDER_SELF_SWAP_2(src_8
,tmp
,samples
,8,s0
,s1
);
432 REORDER_SELF_SWAP_2(src_8
,tmp
,samples
,5,s0
,s1
);
438 int16_t *src_16
= src
;
441 REORDER_SELF_SWAP_2(src_16
,tmp
,samples
,6,s0
,s1
);
444 REORDER_SELF_SWAP_2(src_16
,tmp
,samples
,3,s0
,s1
);
447 REORDER_SELF_SWAP_2(src_16
,tmp
,samples
,3,s0
,s1
);
450 REORDER_SELF_SWAP_2(src_16
,tmp
,samples
,5,s0
,s1
);
457 int8_t tmp0
, tmp1
, tmp2
;
458 for (i
= 0; i
< samples
* 3; i
+= chnum
* 3) {
459 tmp0
= src_8
[i
+s0
*3];
460 tmp1
= src_8
[i
+s0
*3+1];
461 tmp2
= src_8
[i
+s0
*3+2];
462 src_8
[i
+s0
*3] = src_8
[i
+s1
*3];
463 src_8
[i
+s0
*3+1] = src_8
[i
+s1
*3+1];
464 src_8
[i
+s0
*3+2] = src_8
[i
+s1
*3+2];
465 src_8
[i
+s1
*3] = tmp0
;
466 src_8
[i
+s1
*3+1] = tmp1
;
467 src_8
[i
+s1
*3+2] = tmp2
;
473 int32_t *src_32
= src
;
476 REORDER_SELF_SWAP_2(src_32
,tmp
,samples
,6,s0
,s1
);
479 REORDER_SELF_SWAP_2(src_32
,tmp
,samples
,3,s0
,s1
);
482 REORDER_SELF_SWAP_2(src_32
,tmp
,samples
,4,s0
,s1
);
485 REORDER_SELF_SWAP_2(src_32
,tmp
,samples
,5,s0
,s1
);
491 int64_t *src_64
= src
;
494 REORDER_SELF_SWAP_2(src_64
,tmp
,samples
,6,s0
,s1
);
497 REORDER_SELF_SWAP_2(src_64
,tmp
,samples
,3,s0
,s1
);
500 REORDER_SELF_SWAP_2(src_64
,tmp
,samples
,4,s0
,s1
);
503 REORDER_SELF_SWAP_2(src_64
,tmp
,samples
,5,s0
,s1
);
508 mp_msg(MSGT_GLOBAL
, MSGL_WARN
,
509 "[reorder_ch] Unsupported sample size: %d, please "
510 "report this error on the MPlayer mailing list.\n",samplesize
);
516 #define REORDER_SELF_SWAP_3(SRC,TMP,SAMPLES,CHNUM,S0,S1,S2) \
517 for (i = 0; i < SAMPLES; i += CHNUM) {\
519 SRC[i+S0] = SRC[i+S1];\
520 SRC[i+S1] = SRC[i+S2];\
524 static int reorder_self_3(void *src
, unsigned int samples
,
525 unsigned int samplesize
, unsigned int chnum
,
526 int s0
, int s1
, int s2
)
529 switch (samplesize
) {
535 REORDER_SELF_SWAP_3(src_8
,tmp
,samples
,6,s0
,s1
,s2
);
538 REORDER_SELF_SWAP_3(src_8
,tmp
,samples
,5,s0
,s1
,s2
);
544 int16_t *src_16
= src
;
547 REORDER_SELF_SWAP_3(src_16
,tmp
,samples
,6,s0
,s1
,s2
);
550 REORDER_SELF_SWAP_3(src_16
,tmp
,samples
,5,s0
,s1
,s2
);
557 int8_t tmp0
, tmp1
, tmp2
;
558 for (i
= 0; i
< samples
* 3; i
+= chnum
* 3) {
559 tmp0
= src_8
[i
+s0
*3];
560 tmp1
= src_8
[i
+s0
*3+1];
561 tmp2
= src_8
[i
+s0
*3+2];
562 src_8
[i
+s0
*3] = src_8
[i
+s1
*3];
563 src_8
[i
+s0
*3+1] = src_8
[i
+s1
*3+1];
564 src_8
[i
+s0
*3+2] = src_8
[i
+s1
*3+2];
565 src_8
[i
+s1
*3] = src_8
[i
+s2
*3];
566 src_8
[i
+s1
*3+1] = src_8
[i
+s2
*3+1];
567 src_8
[i
+s1
*3+2] = src_8
[i
+s2
*3+2];
568 src_8
[i
+s2
*3] = tmp0
;
569 src_8
[i
+s2
*3+1] = tmp1
;
570 src_8
[i
+s2
*3+2] = tmp2
;
576 int32_t *src_32
= src
;
579 REORDER_SELF_SWAP_3(src_32
,tmp
,samples
,6,s0
,s1
,s2
);
582 REORDER_SELF_SWAP_3(src_32
,tmp
,samples
,5,s0
,s1
,s2
);
588 int64_t *src_64
= src
;
591 REORDER_SELF_SWAP_3(src_64
,tmp
,samples
,6,s0
,s1
,s2
);
594 REORDER_SELF_SWAP_3(src_64
,tmp
,samples
,5,s0
,s1
,s2
);
599 mp_msg(MSGT_GLOBAL
, MSGL_WARN
,
600 "[reorder_ch] Unsupported sample size: %d, please "
601 "report this error on the MPlayer mailing list.\n",samplesize
);
607 #define REORDER_SELF_SWAP_4_STEP_1(SRC,TMP,SAMPLES,CHNUM,S0,S1,S2,S3) \
608 for (i = 0; i < SAMPLES; i += CHNUM) {\
610 SRC[i+S0] = SRC[i+S1];\
611 SRC[i+S1] = SRC[i+S2];\
612 SRC[i+S2] = SRC[i+S3];\
616 static int reorder_self_4_step_1(void *src
, unsigned int samples
,
617 unsigned int samplesize
, unsigned int chnum
,
618 int s0
, int s1
, int s2
, int s3
)
621 switch (samplesize
) {
627 REORDER_SELF_SWAP_4_STEP_1(src_8
,tmp
,samples
,6,s0
,s1
,s2
,s3
);
630 REORDER_SELF_SWAP_4_STEP_1(src_8
,tmp
,samples
,8,s0
,s1
,s2
,s3
);
633 REORDER_SELF_SWAP_4_STEP_1(src_8
,tmp
,samples
,5,s0
,s1
,s2
,s3
);
639 int16_t *src_16
= src
;
642 REORDER_SELF_SWAP_4_STEP_1(src_16
,tmp
,samples
,6,s0
,s1
,s2
,s3
);
645 REORDER_SELF_SWAP_4_STEP_1(src_16
,tmp
,samples
,8,s0
,s1
,s2
,s3
);
648 REORDER_SELF_SWAP_4_STEP_1(src_16
,tmp
,samples
,5,s0
,s1
,s2
,s3
);
655 int8_t tmp0
, tmp1
, tmp2
;
656 for (i
= 0; i
< samples
* 3; i
+= chnum
* 3) {
657 tmp0
= src_8
[i
+s0
*3];
658 tmp1
= src_8
[i
+s0
*3+1];
659 tmp2
= src_8
[i
+s0
*3+2];
660 src_8
[i
+s0
*3] = src_8
[i
+s1
*3];
661 src_8
[i
+s0
*3+1] = src_8
[i
+s1
*3+1];
662 src_8
[i
+s0
*3+2] = src_8
[i
+s1
*3+2];
663 src_8
[i
+s1
*3] = src_8
[i
+s2
*3];
664 src_8
[i
+s1
*3+1] = src_8
[i
+s2
*3+1];
665 src_8
[i
+s1
*3+2] = src_8
[i
+s2
*3+2];
666 src_8
[i
+s2
*3] = src_8
[i
+s3
*3];
667 src_8
[i
+s2
*3+1] = src_8
[i
+s3
*3+1];
668 src_8
[i
+s2
*3+2] = src_8
[i
+s3
*3+2];
669 src_8
[i
+s3
*3] = tmp0
;
670 src_8
[i
+s3
*3+1] = tmp1
;
671 src_8
[i
+s3
*3+2] = tmp2
;
677 int32_t *src_32
= src
;
680 REORDER_SELF_SWAP_4_STEP_1(src_32
,tmp
,samples
,6,s0
,s1
,s2
,s3
);
683 REORDER_SELF_SWAP_4_STEP_1(src_32
,tmp
,samples
,8,s0
,s1
,s2
,s3
);
686 REORDER_SELF_SWAP_4_STEP_1(src_32
,tmp
,samples
,5,s0
,s1
,s2
,s3
);
692 int64_t *src_64
= src
;
695 REORDER_SELF_SWAP_4_STEP_1(src_64
,tmp
,samples
,6,s0
,s1
,s2
,s3
);
698 REORDER_SELF_SWAP_4_STEP_1(src_64
,tmp
,samples
,8,s0
,s1
,s2
,s3
);
701 REORDER_SELF_SWAP_4_STEP_1(src_64
,tmp
,samples
,5,s0
,s1
,s2
,s3
);
706 mp_msg(MSGT_GLOBAL
, MSGL_WARN
,
707 "[reorder_ch] Unsupported sample size: %d, please "
708 "report this error on the MPlayer mailing list.\n",samplesize
);
714 #define REORDER_SELF_SWAP_4_STEP_2(SRC,TMP,SAMPLES,CHNUM,S0,S1,S2,S3) \
715 for (i = 0; i < SAMPLES; i += CHNUM) {\
717 SRC[i+S0] = SRC[i+S2];\
720 SRC[i+S1] = SRC[i+S3];\
724 static int reorder_self_4_step_2(void *src
, unsigned int samples
,
725 unsigned int samplesize
, unsigned int chnum
,
726 int s0
, int s1
, int s2
, int s3
)
729 switch (samplesize
) {
733 int8_t tmp0
, tmp1
, tmp2
;
734 for (i
= 0; i
< samples
* 3; i
+= chnum
* 3) {
735 tmp0
= src_8
[i
+s0
*3];
736 tmp1
= src_8
[i
+s0
*3+1];
737 tmp2
= src_8
[i
+s0
*3+2];
738 src_8
[i
+s0
*3] = src_8
[i
+s2
*3];
739 src_8
[i
+s0
*3+1] = src_8
[i
+s2
*3+1];
740 src_8
[i
+s0
*3+2] = src_8
[i
+s2
*3+2];
741 src_8
[i
+s2
*3] = tmp0
;
742 src_8
[i
+s2
*3+1] = tmp1
;
743 src_8
[i
+s2
*3+2] = tmp2
;
744 tmp0
= src_8
[i
+s1
*3];
745 tmp1
= src_8
[i
+s1
*3+1];
746 tmp2
= src_8
[i
+s1
*3+2];
747 src_8
[i
+s1
*3] = src_8
[i
+s3
*3];
748 src_8
[i
+s1
*3+1] = src_8
[i
+s3
*3+1];
749 src_8
[i
+s1
*3+2] = src_8
[i
+s3
*3+2];
750 src_8
[i
+s3
*3] = tmp0
;
751 src_8
[i
+s3
*3+1] = tmp1
;
752 src_8
[i
+s3
*3+2] = tmp2
;
757 mp_msg(MSGT_GLOBAL
, MSGL_WARN
,
758 "[reorder_ch] Unsupported sample size: %d, please "
759 "report this error on the MPlayer mailing list.\n",samplesize
);
765 #define REORDER_SELF_SWAP_5_STEP_1(SRC,TMP,SAMPLES,CHNUM,S0,S1,S2,S3,S4) \
766 for (i = 0; i < SAMPLES; i += CHNUM) {\
768 SRC[i+S0] = SRC[i+S1];\
769 SRC[i+S1] = SRC[i+S2];\
770 SRC[i+S2] = SRC[i+S3];\
771 SRC[i+S3] = SRC[i+S4];\
775 static int reorder_self_5_step_1(void *src
, unsigned int samples
,
776 unsigned int samplesize
, unsigned int chnum
,
777 int s0
, int s1
, int s2
, int s3
, int s4
)
780 switch (samplesize
) {
786 REORDER_SELF_SWAP_5_STEP_1(src_8
,tmp
,samples
,6,s0
,s1
,s2
,s3
,s4
);
789 REORDER_SELF_SWAP_5_STEP_1(src_8
,tmp
,samples
,5,s0
,s1
,s2
,s3
,s4
);
795 int16_t *src_16
= src
;
798 REORDER_SELF_SWAP_5_STEP_1(src_16
,tmp
,samples
,6,s0
,s1
,s2
,s3
,s4
);
801 REORDER_SELF_SWAP_5_STEP_1(src_16
,tmp
,samples
,5,s0
,s1
,s2
,s3
,s4
);
808 int8_t tmp0
, tmp1
, tmp2
;
809 for (i
= 0; i
< samples
* 3; i
+= chnum
* 3) {
810 tmp0
= src_8
[i
+s0
*3];
811 tmp1
= src_8
[i
+s0
*3+1];
812 tmp2
= src_8
[i
+s0
*3+2];
813 src_8
[i
+s0
*3] = src_8
[i
+s1
*3];
814 src_8
[i
+s0
*3+1] = src_8
[i
+s1
*3+1];
815 src_8
[i
+s0
*3+2] = src_8
[i
+s1
*3+2];
816 src_8
[i
+s1
*3] = src_8
[i
+s2
*3];
817 src_8
[i
+s1
*3+1] = src_8
[i
+s2
*3+1];
818 src_8
[i
+s1
*3+2] = src_8
[i
+s2
*3+2];
819 src_8
[i
+s2
*3] = src_8
[i
+s3
*3];
820 src_8
[i
+s2
*3+1] = src_8
[i
+s3
*3+1];
821 src_8
[i
+s2
*3+2] = src_8
[i
+s3
*3+2];
822 src_8
[i
+s3
*3] = src_8
[i
+s4
*3];
823 src_8
[i
+s3
*3+1] = src_8
[i
+s4
*3+1];
824 src_8
[i
+s3
*3+2] = src_8
[i
+s4
*3+2];
825 src_8
[i
+s4
*3] = tmp0
;
826 src_8
[i
+s4
*3+1] = tmp1
;
827 src_8
[i
+s4
*3+2] = tmp2
;
833 int32_t *src_32
= src
;
836 REORDER_SELF_SWAP_5_STEP_1(src_32
,tmp
,samples
,6,s0
,s1
,s2
,s3
,s4
);
839 REORDER_SELF_SWAP_5_STEP_1(src_32
,tmp
,samples
,5,s0
,s1
,s2
,s3
,s4
);
845 int64_t *src_64
= src
;
848 REORDER_SELF_SWAP_5_STEP_1(src_64
,tmp
,samples
,6,s0
,s1
,s2
,s3
,s4
);
851 REORDER_SELF_SWAP_5_STEP_1(src_64
,tmp
,samples
,5,s0
,s1
,s2
,s3
,s4
);
856 mp_msg(MSGT_GLOBAL
, MSGL_WARN
,
857 "[reorder_ch] Unsupported sample size: %d, please "
858 "report this error on the MPlayer mailing list.\n",samplesize
);
864 #define REORDER_SELF_SWAP_2_3(SRC,TMP,SAMPLES,CHNUM,S0,S1,S2,S3,S4) \
865 for (i = 0; i < SAMPLES; i += CHNUM) {\
867 SRC[i+S0] = SRC[i+S1];\
870 SRC[i+S2] = SRC[i+S3];\
871 SRC[i+S3] = SRC[i+S4];\
875 static int reorder_self_2_3(void *src
, unsigned int samples
,
876 unsigned int samplesize
,
877 int s0
, int s1
, int s2
, int s3
, int s4
)
880 switch (samplesize
) {
885 REORDER_SELF_SWAP_2_3(src_8
,tmp
,samples
,6,s0
,s1
,s2
,s3
,s4
);
890 int16_t *src_16
= src
;
892 REORDER_SELF_SWAP_2_3(src_16
,tmp
,samples
,6,s0
,s1
,s2
,s3
,s4
);
898 int8_t tmp0
, tmp1
, tmp2
;
899 for (i
= 0; i
< samples
* 3; i
+= 18) {
900 tmp0
= src_8
[i
+s0
*3];
901 tmp1
= src_8
[i
+s0
*3+1];
902 tmp2
= src_8
[i
+s0
*3+2];
903 src_8
[i
+s0
*3] = src_8
[i
+s1
*3];
904 src_8
[i
+s0
*3+1] = src_8
[i
+s1
*3+1];
905 src_8
[i
+s0
*3+2] = src_8
[i
+s1
*3+2];
906 src_8
[i
+s1
*3] = tmp0
;
907 src_8
[i
+s1
*3+1] = tmp1
;
908 src_8
[i
+s1
*3+2] = tmp2
;
909 tmp0
= src_8
[i
+s2
*3];
910 tmp1
= src_8
[i
+s2
*3+1];
911 tmp2
= src_8
[i
+s2
*3+2];
912 src_8
[i
+s2
*3] = src_8
[i
+s3
*3];
913 src_8
[i
+s2
*3+1] = src_8
[i
+s3
*3+1];
914 src_8
[i
+s2
*3+2] = src_8
[i
+s3
*3+2];
915 src_8
[i
+s3
*3] = src_8
[i
+s4
*3];
916 src_8
[i
+s3
*3+1] = src_8
[i
+s4
*3+1];
917 src_8
[i
+s3
*3+2] = src_8
[i
+s4
*3+2];
918 src_8
[i
+s4
*3] = tmp0
;
919 src_8
[i
+s4
*3+1] = tmp1
;
920 src_8
[i
+s4
*3+2] = tmp2
;
926 int32_t *src_32
= src
;
928 REORDER_SELF_SWAP_2_3(src_32
,tmp
,samples
,6,s0
,s1
,s2
,s3
,s4
);
933 int64_t *src_64
= src
;
935 REORDER_SELF_SWAP_2_3(src_64
,tmp
,samples
,6,s0
,s1
,s2
,s3
,s4
);
939 mp_msg(MSGT_GLOBAL
, MSGL_WARN
,
940 "[reorder_ch] Unsupported sample size: %d, please "
941 "report this error on the MPlayer mailing list.\n",samplesize
);
947 #define REORDER_SELF_SWAP_3_3(SRC,TMP,SAMPLES,CHNUM,S0,S1,S2,S3,S4,S5) \
948 for (i = 0; i < SAMPLES; i += CHNUM) {\
950 SRC[i+S0] = SRC[i+S1];\
951 SRC[i+S1] = SRC[i+S2];\
954 SRC[i+S3] = SRC[i+S4];\
955 SRC[i+S4] = SRC[i+S5];\
959 static int reorder_self_3_3(void *src
, unsigned int samples
,
960 unsigned int samplesize
,
961 int s0
, int s1
, int s2
, int s3
, int s4
, int s5
)
964 switch (samplesize
) {
969 REORDER_SELF_SWAP_3_3(src_8
,tmp
,samples
,6,s0
,s1
,s2
,s3
,s4
,s5
);
974 int16_t *src_16
= src
;
976 REORDER_SELF_SWAP_3_3(src_16
,tmp
,samples
,6,s0
,s1
,s2
,s3
,s4
,s5
);
982 int8_t tmp0
, tmp1
, tmp2
;
983 for (i
= 0; i
< samples
* 3; i
+= 18) {
984 tmp0
= src_8
[i
+s0
*3];
985 tmp1
= src_8
[i
+s0
*3+1];
986 tmp2
= src_8
[i
+s0
*3+2];
987 src_8
[i
+s0
*3] = src_8
[i
+s1
*3];
988 src_8
[i
+s0
*3+1] = src_8
[i
+s1
*3+1];
989 src_8
[i
+s0
*3+2] = src_8
[i
+s1
*3+2];
990 src_8
[i
+s1
*3] = src_8
[i
+s2
*3];
991 src_8
[i
+s1
*3+1] = src_8
[i
+s2
*3+1];
992 src_8
[i
+s1
*3+2] = src_8
[i
+s2
*3+2];
993 src_8
[i
+s2
*3] = tmp0
;
994 src_8
[i
+s2
*3+1] = tmp1
;
995 src_8
[i
+s2
*3+2] = tmp2
;
996 tmp0
= src_8
[i
+s3
*3];
997 tmp1
= src_8
[i
+s3
*3+1];
998 tmp2
= src_8
[i
+s3
*3+2];
999 src_8
[i
+s3
*3] = src_8
[i
+s4
*3];
1000 src_8
[i
+s3
*3+1] = src_8
[i
+s4
*3+1];
1001 src_8
[i
+s3
*3+2] = src_8
[i
+s4
*3+2];
1002 src_8
[i
+s4
*3] = src_8
[i
+s5
*3];
1003 src_8
[i
+s4
*3+1] = src_8
[i
+s5
*3+1];
1004 src_8
[i
+s4
*3+2] = src_8
[i
+s5
*3+2];
1005 src_8
[i
+s5
*3] = tmp0
;
1006 src_8
[i
+s5
*3+1] = tmp1
;
1007 src_8
[i
+s5
*3+2] = tmp2
;
1013 int32_t *src_32
= src
;
1015 REORDER_SELF_SWAP_3_3(src_32
,tmp
,samples
,6,s0
,s1
,s2
,s3
,s4
,s5
);
1020 int64_t *src_64
= src
;
1022 REORDER_SELF_SWAP_3_3(src_64
,tmp
,samples
,6,s0
,s1
,s2
,s3
,s4
,s5
);
1026 mp_msg(MSGT_GLOBAL
, MSGL_WARN
,
1027 "[reorder_ch] Unsupported sample size: %d, please "
1028 "report this error on the MPlayer mailing list.\n",samplesize
);
1034 #define REORDER_SELF_SWAP_2_4(SRC,TMP,SAMPLES,CHNUM,S0,S1,S2,S3,S4,S5) \
1035 for (i = 0; i < SAMPLES; i += CHNUM) {\
1037 SRC[i+S0] = SRC[i+S1];\
1040 SRC[i+S2] = SRC[i+S3];\
1041 SRC[i+S3] = SRC[i+S4];\
1042 SRC[i+S4] = SRC[i+S5];\
1046 static int reorder_self_2_4(void *src
, unsigned int samples
,
1047 unsigned int samplesize
, int chnum
,
1048 int s0
, int s1
, int s2
, int s3
, int s4
, int s5
)
1051 switch (samplesize
) {
1054 int8_t *src_8
= src
;
1057 REORDER_SELF_SWAP_2_4(src_8
,tmp
,samples
,6,s0
,s1
,s2
,s3
,s4
,s5
);
1059 REORDER_SELF_SWAP_2_4(src_8
,tmp
,samples
,8,s0
,s1
,s2
,s3
,s4
,s5
);
1065 int16_t *src_16
= src
;
1068 REORDER_SELF_SWAP_2_4(src_16
,tmp
,samples
,6,s0
,s1
,s2
,s3
,s4
,s5
);
1070 REORDER_SELF_SWAP_2_4(src_16
,tmp
,samples
,8,s0
,s1
,s2
,s3
,s4
,s5
);
1076 int8_t *src_8
= src
;
1077 int8_t tmp0
, tmp1
, tmp2
;
1078 for (i
= 0; i
< samples
* 3; i
+= chnum
* 3) {
1079 tmp0
= src_8
[i
+s0
*3];
1080 tmp1
= src_8
[i
+s0
*3+1];
1081 tmp2
= src_8
[i
+s0
*3+2];
1082 src_8
[i
+s0
*3] = src_8
[i
+s1
*3];
1083 src_8
[i
+s0
*3+1] = src_8
[i
+s1
*3+1];
1084 src_8
[i
+s0
*3+2] = src_8
[i
+s1
*3+2];
1085 src_8
[i
+s1
*3] = tmp0
;
1086 src_8
[i
+s1
*3+1] = tmp1
;
1087 src_8
[i
+s1
*3+2] = tmp2
;
1088 tmp0
= src_8
[i
+s2
*3];
1089 tmp1
= src_8
[i
+s2
*3+1];
1090 tmp2
= src_8
[i
+s2
*3+2];
1091 src_8
[i
+s2
*3] = src_8
[i
+s3
*3];
1092 src_8
[i
+s2
*3+1] = src_8
[i
+s3
*3+1];
1093 src_8
[i
+s2
*3+2] = src_8
[i
+s3
*3+2];
1094 src_8
[i
+s3
*3] = src_8
[i
+s4
*3];
1095 src_8
[i
+s3
*3+1] = src_8
[i
+s4
*3+1];
1096 src_8
[i
+s3
*3+2] = src_8
[i
+s4
*3+2];
1097 src_8
[i
+s4
*3] = src_8
[i
+s5
*3];
1098 src_8
[i
+s4
*3+1] = src_8
[i
+s5
*3+1];
1099 src_8
[i
+s4
*3+2] = src_8
[i
+s5
*3+2];
1100 src_8
[i
+s5
*3] = tmp0
;
1101 src_8
[i
+s5
*3+1] = tmp1
;
1102 src_8
[i
+s5
*3+2] = tmp2
;
1108 int32_t *src_32
= src
;
1111 REORDER_SELF_SWAP_2_4(src_32
,tmp
,samples
,6,s0
,s1
,s2
,s3
,s4
,s5
);
1113 REORDER_SELF_SWAP_2_4(src_32
,tmp
,samples
,8,s0
,s1
,s2
,s3
,s4
,s5
);
1119 int64_t *src_64
= src
;
1122 REORDER_SELF_SWAP_2_4(src_64
,tmp
,samples
,6,s0
,s1
,s2
,s3
,s4
,s5
);
1124 REORDER_SELF_SWAP_2_4(src_64
,tmp
,samples
,8,s0
,s1
,s2
,s3
,s4
,s5
);
1129 mp_msg(MSGT_GLOBAL
, MSGL_WARN
,
1130 "[reorder_ch] Unsupported sample size: %d, please "
1131 "report this error on the MPlayer mailing list.\n",samplesize
);
1137 void reorder_channel(void *src
,
1143 if (dest_layout
==src_layout
)
1145 if (!AF_IS_SAME_CH_NUM(dest_layout
,src_layout
)) {
1146 mp_msg(MSGT_GLOBAL
, MSGL_WARN
,
1147 "[reorder_channel] different channel count "
1148 "between current and target: %x, %x\n",
1149 AF_GET_CH_NUM_WITH_LFE(src_layout
),
1150 AF_GET_CH_NUM_WITH_LFE(dest_layout
));
1153 switch ((src_layout
<<16)|dest_layout
) {
1154 // AF_CHANNEL_LAYOUT_5_0_A L R C Ls Rs
1155 // AF_CHANNEL_LAYOUT_5_0_B L R Ls Rs C
1156 // AF_CHANNEL_LAYOUT_5_0_C L C R Ls Rs
1157 // AF_CHANNEL_LAYOUT_5_0_D C L R Ls Rs
1158 case AF_CHANNEL_LAYOUT_5_0_A
<< 16 | AF_CHANNEL_LAYOUT_5_0_B
:
1159 reorder_self_3(src
, samples
, samplesize
, 5, 2, 3, 4);
1161 case AF_CHANNEL_LAYOUT_5_0_A
<< 16 | AF_CHANNEL_LAYOUT_5_0_C
:
1162 reorder_self_2(src
, samples
, samplesize
, 5, 1, 2);
1164 case AF_CHANNEL_LAYOUT_5_0_A
<< 16 | AF_CHANNEL_LAYOUT_5_0_D
:
1165 reorder_self_3(src
, samples
, samplesize
, 5, 2, 1, 0);
1167 case AF_CHANNEL_LAYOUT_5_0_B
<< 16 | AF_CHANNEL_LAYOUT_5_0_A
:
1168 reorder_self_3(src
, samples
, samplesize
, 5, 4, 3, 2);
1170 case AF_CHANNEL_LAYOUT_5_0_B
<< 16 | AF_CHANNEL_LAYOUT_5_0_C
:
1171 reorder_self_4_step_1(src
, samples
, samplesize
, 5, 4, 3, 2, 1);
1173 case AF_CHANNEL_LAYOUT_5_0_B
<< 16 | AF_CHANNEL_LAYOUT_5_0_D
:
1174 reorder_self_5_step_1(src
, samples
, samplesize
, 5, 4, 3, 2, 1, 0);
1176 case AF_CHANNEL_LAYOUT_5_0_C
<< 16 | AF_CHANNEL_LAYOUT_5_0_A
:
1177 reorder_self_2(src
, samples
, samplesize
, 5, 1, 2);
1179 case AF_CHANNEL_LAYOUT_5_0_C
<< 16 | AF_CHANNEL_LAYOUT_5_0_B
:
1180 reorder_self_4_step_1(src
, samples
, samplesize
, 5, 1, 2, 3, 4);
1182 case AF_CHANNEL_LAYOUT_5_0_C
<< 16 | AF_CHANNEL_LAYOUT_5_0_D
:
1183 reorder_self_2(src
, samples
, samplesize
, 5, 0, 1);
1185 case AF_CHANNEL_LAYOUT_5_0_D
<< 16 | AF_CHANNEL_LAYOUT_5_0_A
:
1186 reorder_self_3(src
, samples
, samplesize
, 5, 0, 1, 2);
1188 case AF_CHANNEL_LAYOUT_5_0_D
<< 16 | AF_CHANNEL_LAYOUT_5_0_B
:
1189 reorder_self_5_step_1(src
, samples
, samplesize
, 5, 0, 1, 2, 3, 4);
1191 case AF_CHANNEL_LAYOUT_5_0_D
<< 16 | AF_CHANNEL_LAYOUT_5_0_C
:
1192 reorder_self_2(src
, samples
, samplesize
, 5, 0, 1);
1194 // AF_CHANNEL_LAYOUT_5_1_A L R C LFE Ls Rs
1195 // AF_CHANNEL_LAYOUT_5_1_B L R Ls Rs C LFE
1196 // AF_CHANNEL_LAYOUT_5_1_C L C R Ls Rs LFE
1197 // AF_CHANNEL_LAYOUT_5_1_D C L R Ls Rs LFE
1198 // AF_CHANNEL_LAYOUT_5_1_E LFE L C R Ls Rs
1199 case AF_CHANNEL_LAYOUT_5_1_A
<< 16 | AF_CHANNEL_LAYOUT_5_1_B
:
1200 if (samplesize
!= 3)
1201 reorder_self_2(src
, samples
/2, samplesize
*2, 3, 1, 2);
1203 reorder_self_4_step_2(src
, samples
, samplesize
, 6, 2, 3, 4, 5);
1205 case AF_CHANNEL_LAYOUT_5_1_A
<< 16 | AF_CHANNEL_LAYOUT_5_1_C
:
1206 reorder_self_2_3(src
, samples
, samplesize
, 1, 2, 3, 4, 5);
1208 case AF_CHANNEL_LAYOUT_5_1_A
<< 16 | AF_CHANNEL_LAYOUT_5_1_D
:
1209 reorder_self_3_3(src
, samples
, samplesize
, 2, 1, 0, 3, 4, 5);
1211 case AF_CHANNEL_LAYOUT_5_1_B
<< 16 | AF_CHANNEL_LAYOUT_5_1_A
:
1212 if (samplesize
!= 3)
1213 reorder_self_2(src
, samples
/2, samplesize
*2, 3, 1, 2);
1215 reorder_self_4_step_2(src
, samples
, samplesize
, 6, 2, 3, 4, 5);
1217 case AF_CHANNEL_LAYOUT_5_1_B
<< 16 | AF_CHANNEL_LAYOUT_5_1_C
:
1218 reorder_self_4_step_1(src
, samples
, samplesize
, 6, 4, 3, 2, 1);
1220 case AF_CHANNEL_LAYOUT_5_1_B
<< 16 | AF_CHANNEL_LAYOUT_5_1_D
:
1221 reorder_self_5_step_1(src
, samples
, samplesize
, 6, 4, 3, 2, 1, 0);
1223 case AF_CHANNEL_LAYOUT_5_1_B
<< 16 | AF_CHANNEL_LAYOUT_5_1_E
:
1224 reorder_self_2_4(src
, samples
, samplesize
, 6, 2, 4, 5, 3, 1, 0);
1226 case AF_CHANNEL_LAYOUT_5_1_C
<< 16 | AF_CHANNEL_LAYOUT_5_1_A
:
1227 reorder_self_2_3(src
, samples
, samplesize
, 1, 2, 5, 4, 3);
1229 case AF_CHANNEL_LAYOUT_5_1_C
<< 16 | AF_CHANNEL_LAYOUT_5_1_B
:
1230 reorder_self_4_step_1(src
, samples
, samplesize
, 6, 1, 2, 3, 4);
1232 case AF_CHANNEL_LAYOUT_5_1_C
<< 16 | AF_CHANNEL_LAYOUT_5_1_D
:
1233 reorder_self_2(src
, samples
, samplesize
, 6, 0, 1);
1235 case AF_CHANNEL_LAYOUT_5_1_D
<< 16 | AF_CHANNEL_LAYOUT_5_1_A
:
1236 reorder_self_3_3(src
, samples
, samplesize
, 0, 1, 2, 5, 4, 3);
1238 case AF_CHANNEL_LAYOUT_5_1_D
<< 16 | AF_CHANNEL_LAYOUT_5_1_B
:
1239 reorder_self_5_step_1(src
, samples
, samplesize
, 6, 0, 1, 2, 3, 4);
1241 case AF_CHANNEL_LAYOUT_5_1_D
<< 16 | AF_CHANNEL_LAYOUT_5_1_C
:
1242 reorder_self_2(src
, samples
, samplesize
, 6, 0, 1);
1244 case AF_CHANNEL_LAYOUT_5_1_E
<< 16 | AF_CHANNEL_LAYOUT_5_1_B
:
1245 reorder_self_2_4(src
, samples
, samplesize
, 6, 2, 4, 0, 1, 3, 5);
1247 case AF_CHANNEL_LAYOUT_5_1_F
<< 16 | AF_CHANNEL_LAYOUT_5_1_B
:
1248 reorder_self_2_4(src
, samples
, samplesize
, 6, 3, 5, 0, 1, 2, 4);
1250 // AF_CHANNEL_LAYOUT_7_1_A L R C LFE Ls Rs Rls Rrs
1251 // AF_CHANNEL_LAYOUT_7_1_B L R Ls Rs C LFE Rls Rrs
1252 // AF_CHANNEL_LAYOUT_7_1_C L C R Ls Rs LFE Rls Rrs
1253 // AF_CHANNEL_LAYOUT_7_1_F C L R LFE Ls Rs Rls Rrs
1254 case AF_CHANNEL_LAYOUT_7_1_A
<< 16 | AF_CHANNEL_LAYOUT_7_1_B
:
1255 case AF_CHANNEL_LAYOUT_7_1_B
<< 16 | AF_CHANNEL_LAYOUT_7_1_A
:
1256 if (samplesize
!= 3)
1257 reorder_self_2(src
, samples
/2, samplesize
*2, 4, 1, 2);
1259 reorder_self_4_step_2(src
, samples
, samplesize
, 8, 2, 3, 4, 5);
1261 case AF_CHANNEL_LAYOUT_7_1_C
<< 16 | AF_CHANNEL_LAYOUT_7_1_B
:
1262 reorder_self_4_step_1(src
, samples
, samplesize
, 8, 1, 2, 3, 4);
1264 case AF_CHANNEL_LAYOUT_7_1_F
<< 16 | AF_CHANNEL_LAYOUT_7_1_B
:
1265 reorder_self_2_4(src
, samples
, samplesize
, 8, 3, 5, 0, 1, 2, 4);
1268 mp_msg(MSGT_GLOBAL
, MSGL_WARN
,
1269 "[reorder_channel] unsupported from %x to %x, %d * %d\n",
1270 src_layout
, dest_layout
, samples
, samplesize
);
1275 static int channel_layout_mapping_5ch
[AF_CHANNEL_LAYOUT_SOURCE_NUM
] = {
1276 AF_CHANNEL_LAYOUT_ALSA_5CH_DEFAULT
,
1277 AF_CHANNEL_LAYOUT_AAC_5CH_DEFAULT
,
1278 AF_CHANNEL_LAYOUT_WAVEEX_5CH_DEFAULT
,
1279 AF_CHANNEL_LAYOUT_LAVC_5CH_DEFAULT
,
1280 AF_CHANNEL_LAYOUT_VORBIS_5CH_DEFAULT
,
1283 static int channel_layout_mapping_6ch
[AF_CHANNEL_LAYOUT_SOURCE_NUM
] = {
1284 AF_CHANNEL_LAYOUT_ALSA_6CH_DEFAULT
,
1285 AF_CHANNEL_LAYOUT_AAC_6CH_DEFAULT
,
1286 AF_CHANNEL_LAYOUT_WAVEEX_6CH_DEFAULT
,
1287 AF_CHANNEL_LAYOUT_LAVC_6CH_DEFAULT
,
1288 AF_CHANNEL_LAYOUT_VORBIS_6CH_DEFAULT
,
1291 static int channel_layout_mapping_8ch
[AF_CHANNEL_LAYOUT_SOURCE_NUM
] = {
1292 AF_CHANNEL_LAYOUT_ALSA_8CH_DEFAULT
,
1293 AF_CHANNEL_LAYOUT_AAC_8CH_DEFAULT
,
1294 AF_CHANNEL_LAYOUT_WAVEEX_8CH_DEFAULT
,
1295 AF_CHANNEL_LAYOUT_LAVC_8CH_DEFAULT
,
1296 AF_CHANNEL_LAYOUT_VORBIS_8CH_DEFAULT
,
1299 void reorder_channel_copy_nch(void *src
,
1307 if (chnum
< 5 || chnum
== 7 || chnum
> 8 ||
1308 src_layout
< 0 || dest_layout
< 0 ||
1309 src_layout
>= AF_CHANNEL_LAYOUT_SOURCE_NUM
||
1310 dest_layout
>= AF_CHANNEL_LAYOUT_SOURCE_NUM
)
1311 fast_memcpy(dest
, src
, samples
*samplesize
);
1312 else if (chnum
== 6)
1313 reorder_channel_copy(src
, channel_layout_mapping_6ch
[src_layout
],
1314 dest
, channel_layout_mapping_6ch
[dest_layout
],
1315 samples
, samplesize
);
1316 else if (chnum
== 8)
1317 reorder_channel_copy(src
, channel_layout_mapping_8ch
[src_layout
],
1318 dest
, channel_layout_mapping_8ch
[dest_layout
],
1319 samples
, samplesize
);
1321 reorder_channel_copy(src
, channel_layout_mapping_5ch
[src_layout
],
1322 dest
, channel_layout_mapping_5ch
[dest_layout
],
1323 samples
, samplesize
);
1326 void reorder_channel_nch(void *buf
,
1333 if (src_layout
== dest_layout
|| chnum
< 5 || chnum
== 7 || chnum
> 8 ||
1334 src_layout
< 0 || dest_layout
< 0 ||
1335 src_layout
>= AF_CHANNEL_LAYOUT_SOURCE_NUM
||
1336 dest_layout
>= AF_CHANNEL_LAYOUT_SOURCE_NUM
||
1337 src_layout
== dest_layout
)
1340 reorder_channel(buf
, channel_layout_mapping_6ch
[src_layout
],
1341 channel_layout_mapping_6ch
[dest_layout
],
1342 samples
, samplesize
);
1343 else if (chnum
== 8)
1344 reorder_channel(buf
, channel_layout_mapping_8ch
[src_layout
],
1345 channel_layout_mapping_8ch
[dest_layout
],
1346 samples
, samplesize
);
1348 reorder_channel(buf
, channel_layout_mapping_5ch
[src_layout
],
1349 channel_layout_mapping_5ch
[dest_layout
],
1350 samples
, samplesize
);
1356 static void test_copy(int channels
) {
1357 int samples
= 12*1024*1024;
1360 unsigned char *bufin
= malloc((samples
+100)*samplesize
);
1361 unsigned char *bufout
= malloc((samples
+100)*samplesize
);
1362 memset(bufin
, 0xFF, samples
*samplesize
);
1363 for (i
= 0;i
< 100; ++i
)
1364 reorder_channel_copy(bufin
, AF_CHANNEL_LAYOUT_5_1_A
,
1365 bufout
, AF_CHANNEL_LAYOUT_5_1_B
,
1366 samples
, samplesize
);
1367 // reorder_channel(bufin, AF_CHANNEL_LAYOUT_5_1_B,
1368 // AF_CHANNEL_LAYOUT_5_1_D,
1369 // samples, samplesize);
1374 int main(int argc
, char *argv
[]) {
1377 channels
= atoi(argv
[1]);
1378 test_copy(channels
);