/*
* common functions for reordering audio channels
*
* Copyright (C) 2007 Ulion <ulion A gmail P com>
*
* This file is part of MPlayer.
*
* MPlayer is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* MPlayer is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with MPlayer; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <string.h>
#include "audio/reorder_ch.h"
#ifdef TEST
#define mp_msg(mod,lev, fmt, args... ) printf( fmt, ## args )
#else
#include "core/mp_msg.h"
#endif
#define REORDER_COPY_5(DEST,SRC,SAMPLES,S0,S1,S2,S3,S4) \
for (i = 0; i < SAMPLES; i += 5) {\
DEST[i] = SRC[i+S0];\
DEST[i+1] = SRC[i+S1];\
DEST[i+2] = SRC[i+S2];\
DEST[i+3] = SRC[i+S3];\
DEST[i+4] = SRC[i+S4];\
}
static int reorder_copy_5ch(void *dest, const void *src,
unsigned int samples, unsigned int samplesize,
int s0, int s1, int s2, int s3, int s4)
{
int i;
switch (samplesize) {
case 1:
{
int8_t *dest_8 = dest;
const int8_t *src_8 = src;
REORDER_COPY_5(dest_8,src_8,samples,s0,s1,s2,s3,s4);
break;
}
case 2:
{
int16_t *dest_16 = dest;
const int16_t *src_16 = src;
REORDER_COPY_5(dest_16,src_16,samples,s0,s1,s2,s3,s4);
break;
}
case 3:
{
int8_t *dest_8 = dest;
const int8_t *src_8 = src;
for (i = 0; i < samples * 3; i += 15) {
dest_8[i] = src_8[i+s0*3];
dest_8[i+1] = src_8[i+s0*3+1];
dest_8[i+2] = src_8[i+s0*3+2];
dest_8[i+3] = src_8[i+s1*3];
dest_8[i+4] = src_8[i+s1*3+1];
dest_8[i+5] = src_8[i+s1*3+2];
dest_8[i+6] = src_8[i+s2*3];
dest_8[i+7] = src_8[i+s2*3+1];
dest_8[i+8] = src_8[i+s2*3+2];
dest_8[i+9] = src_8[i+s3*3];
dest_8[i+10] = src_8[i+s3*3+1];
dest_8[i+11] = src_8[i+s3*3+2];
dest_8[i+12] = src_8[i+s4*3];
dest_8[i+13] = src_8[i+s4*3+1];
dest_8[i+14] = src_8[i+s4*3+2];
}
break;
}
case 4:
{
int32_t *dest_32 = dest;
const int32_t *src_32 = src;
REORDER_COPY_5(dest_32,src_32,samples,s0,s1,s2,s3,s4);
break;
}
case 8:
{
int64_t *dest_64 = dest;
const int64_t *src_64 = src;
REORDER_COPY_5(dest_64,src_64,samples,s0,s1,s2,s3,s4);
break;
}
default:
mp_msg(MSGT_GLOBAL, MSGL_WARN,
"[reorder_ch] Unsupported sample size: %d, please "
"report this error on the MPlayer mailing list.\n",samplesize);
return 0;
}
return 1;
}
#define REORDER_COPY_6(DEST,SRC,SAMPLES,S0,S1,S2,S3,S4,S5) \
for (i = 0; i < SAMPLES; i += 6) {\
DEST[i] = SRC[i+S0];\
DEST[i+1] = SRC[i+S1];\
DEST[i+2] = SRC[i+S2];\
DEST[i+3] = SRC[i+S3];\
DEST[i+4] = SRC[i+S4];\
DEST[i+5] = SRC[i+S5];\
}
static int reorder_copy_6ch(void *dest, const void *src,
unsigned int samples, uint8_t samplesize,
int s0, int s1, int s2, int s3, int s4, int s5)
{
int i;
switch (samplesize) {
case 1:
{
int8_t *dest_8 = dest;
const int8_t *src_8 = src;
REORDER_COPY_6(dest_8,src_8,samples,s0,s1,s2,s3,s4,s5);
break;
}
case 2:
{
int16_t *dest_16 = dest;
const int16_t *src_16 = src;
REORDER_COPY_6(dest_16,src_16,samples,s0,s1,s2,s3,s4,s5);
break;
}
case 3:
{
int8_t *dest_8 = dest;
const int8_t *src_8 = src;
for (i = 0; i < samples * 3; i += 18) {
dest_8[i] = src_8[i+s0*3];
dest_8[i+1] = src_8[i+s0*3+1];
dest_8[i+2] = src_8[i+s0*3+2];
dest_8[i+3] = src_8[i+s1*3];
dest_8[i+4] = src_8[i+s1*3+1];
dest_8[i+5] = src_8[i+s1*3+2];
dest_8[i+6] = src_8[i+s2*3];
dest_8[i+7] = src_8[i+s2*3+1];
dest_8[i+8] = src_8[i+s2*3+2];
dest_8[i+9] = src_8[i+s3*3];
dest_8[i+10] = src_8[i+s3*3+1];
dest_8[i+11] = src_8[i+s3*3+2];
dest_8[i+12] = src_8[i+s4*3];
dest_8[i+13] = src_8[i+s4*3+1];
dest_8[i+14] = src_8[i+s4*3+2];
dest_8[i+15] = src_8[i+s5*3];
dest_8[i+16] = src_8[i+s5*3+1];
dest_8[i+17] = src_8[i+s5*3+2];
}
break;
}
case 4:
{
int32_t *dest_32 = dest;
const int32_t *src_32 = src;
REORDER_COPY_6(dest_32,src_32,samples,s0,s1,s2,s3,s4,s5);
break;
}
case 8:
{
int64_t *dest_64 = dest;
const int64_t *src_64 = src;
REORDER_COPY_6(dest_64,src_64,samples,s0,s1,s2,s3,s4,s5);
break;
}
default:
mp_msg(MSGT_GLOBAL, MSGL_WARN,
"[reorder_ch] Unsupported sample size: %d, please "
"report this error on the MPlayer mailing list.\n",samplesize);
return 0;
}
return 1;
}
#define REORDER_COPY_8(DEST,SRC,SAMPLES,S0,S1,S2,S3,S4,S5,S6,S7) \
for (i = 0; i < SAMPLES; i += 8) {\
DEST[i] = SRC[i+S0];\
DEST[i+1] = SRC[i+S1];\
DEST[i+2] = SRC[i+S2];\
DEST[i+3] = SRC[i+S3];\
DEST[i+4] = SRC[i+S4];\
DEST[i+5] = SRC[i+S5];\
DEST[i+6] = SRC[i+S6];\
DEST[i+7] = SRC[i+S7];\
}
static int reorder_copy_8ch(void *dest, const void *src,
unsigned int samples, uint8_t samplesize,
int s0, int s1, int s2, int s3,
int s4, int s5, int s6, int s7)
{
int i;
switch (samplesize) {
case 1:
{
int8_t *dest_8 = dest;
const int8_t *src_8 = src;
REORDER_COPY_8(dest_8,src_8,samples,s0,s1,s2,s3,s4,s5,s6,s7);
break;
}
case 2:
{
int16_t *dest_16 = dest;
const int16_t *src_16 = src;
REORDER_COPY_8(dest_16,src_16,samples,s0,s1,s2,s3,s4,s5,s6,s7);
break;
}
case 3:
{
int8_t *dest_8 = dest;
const int8_t *src_8 = src;
for (i = 0; i < samples * 3; i += 24) {
dest_8[i] = src_8[i+s0*3];
dest_8[i+1] = src_8[i+s0*3+1];
dest_8[i+2] = src_8[i+s0*3+2];
dest_8[i+3] = src_8[i+s1*3];
dest_8[i+4] = src_8[i+s1*3+1];
dest_8[i+5] = src_8[i+s1*3+2];
dest_8[i+6] = src_8[i+s2*3];
dest_8[i+7] = src_8[i+s2*3+1];
dest_8[i+8] = src_8[i+s2*3+2];
dest_8[i+9] = src_8[i+s3*3];
dest_8[i+10] = src_8[i+s3*3+1];
dest_8[i+11] = src_8[i+s3*3+2];
dest_8[i+12] = src_8[i+s4*3];
dest_8[i+13] = src_8[i+s4*3+1];
dest_8[i+14] = src_8[i+s4*3+2];
dest_8[i+15] = src_8[i+s5*3];
dest_8[i+16] = src_8[i+s5*3+1];
dest_8[i+17] = src_8[i+s5*3+2];
dest_8[i+18] = src_8[i+s6*3];
dest_8[i+19] = src_8[i+s6*3+1];
dest_8[i+20] = src_8[i+s6*3+2];
dest_8[i+21] = src_8[i+s7*3];
dest_8[i+22] = src_8[i+s7*3+1];
dest_8[i+23] = src_8[i+s7*3+2];
}
break;
}
case 4:
{
int32_t *dest_32 = dest;
const int32_t *src_32 = src;
REORDER_COPY_8(dest_32,src_32,samples,s0,s1,s2,s3,s4,s5,s6,s7);
break;
}
case 8:
{
int64_t *dest_64 = dest;
const int64_t *src_64 = src;
REORDER_COPY_8(dest_64,src_64,samples,s0,s1,s2,s3,s4,s5,s6,s7);
break;
}
default:
mp_msg(MSGT_GLOBAL, MSGL_WARN,
"[reorder_ch] Unsupported sample size: %d, please "
"report this error on the MPlayer mailing list.\n",samplesize);
return 0;
}
return 1;
}
void reorder_channel_copy(void *src,
int src_layout,
void *dest,
int dest_layout,
int samples,
int samplesize)
{
if (dest_layout==src_layout) {
memcpy(dest, src, samples*samplesize);
return;
}
if (!AF_IS_SAME_CH_NUM(dest_layout,src_layout)) {
mp_msg(MSGT_GLOBAL, MSGL_WARN, "[reorder_ch] different channel count "
"between src and dest: %x, %x\n",
AF_GET_CH_NUM_WITH_LFE(src_layout),
AF_GET_CH_NUM_WITH_LFE(dest_layout));
return;
}
switch ((src_layout<<16)|dest_layout) {
// AF_CHANNEL_LAYOUT_5_0_A L R C Ls Rs
// AF_CHANNEL_LAYOUT_5_0_B L R Ls Rs C
// AF_CHANNEL_LAYOUT_5_0_C L C R Ls Rs
// AF_CHANNEL_LAYOUT_5_0_D C L R Ls Rs
|