diff options
author | Michael Niedermayer | 2012-06-09 13:45:49 -0700 |
---|---|---|
committer | Michael Niedermayer | 2012-09-07 00:41:49 +0200 |
commit | c5278cb84f92e4be14a1372b35f25485a296d10d (patch) | |
tree | 77fb165a18c6f38576d5711e9bd5ddbac63f2cf4 /libswresample/rematrix.c | |
parent | 2dd2e429517d98b3bc97a432a699835ccc62e720 (diff) |
Add Dolby/DPLII downmix support to libswresample
Based on code by John Stebbins <jstebbins.hb@gmail.com>
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libswresample/rematrix.c')
-rw-r--r-- | libswresample/rematrix.c | 48 |
1 files changed, 42 insertions, 6 deletions
diff --git a/libswresample/rematrix.c b/libswresample/rematrix.c index 7652fd8a32..8284e5c692 100644 --- a/libswresample/rematrix.c +++ b/libswresample/rematrix.c @@ -126,6 +126,7 @@ static int auto_matrix(SwrContext *s) int64_t unaccounted= s->in_ch_layout & ~s->out_ch_layout; double maxcoef=0; char buf[128]; + const int matrix_encoding = s->matrix_encoding; memset(s->matrix, 0, sizeof(s->matrix)); for(i=0; i<64; i++){ @@ -178,8 +179,19 @@ static int auto_matrix(SwrContext *s) matrix[ SIDE_LEFT][BACK_CENTER]+= M_SQRT1_2; matrix[SIDE_RIGHT][BACK_CENTER]+= M_SQRT1_2; }else if(s->out_ch_layout & AV_CH_FRONT_LEFT){ - matrix[ FRONT_LEFT][BACK_CENTER]+= s->slev*M_SQRT1_2; - matrix[FRONT_RIGHT][BACK_CENTER]+= s->slev*M_SQRT1_2; + if (matrix_encoding == AV_MATRIX_ENCODING_DOLBY || + matrix_encoding == AV_MATRIX_ENCODING_DPLII) { + if (unaccounted & (AV_CH_BACK_LEFT | AV_CH_SIDE_LEFT)) { + matrix[FRONT_LEFT ][BACK_CENTER] -= s->slev * M_SQRT1_2; + matrix[FRONT_RIGHT][BACK_CENTER] += s->slev * M_SQRT1_2; + } else { + matrix[FRONT_LEFT ][BACK_CENTER] -= s->slev; + matrix[FRONT_RIGHT][BACK_CENTER] += s->slev; + } + } else { + matrix[ FRONT_LEFT][BACK_CENTER]+= s->slev*M_SQRT1_2; + matrix[FRONT_RIGHT][BACK_CENTER]+= s->slev*M_SQRT1_2; + } }else if(s->out_ch_layout & AV_CH_FRONT_CENTER){ matrix[ FRONT_CENTER][BACK_CENTER]+= s->slev*M_SQRT1_2; }else @@ -198,8 +210,20 @@ static int auto_matrix(SwrContext *s) matrix[SIDE_RIGHT][BACK_RIGHT]+= 1.0; } }else if(s->out_ch_layout & AV_CH_FRONT_LEFT){ - matrix[ FRONT_LEFT][ BACK_LEFT]+= s->slev; - matrix[FRONT_RIGHT][BACK_RIGHT]+= s->slev; + if (matrix_encoding == AV_MATRIX_ENCODING_DOLBY) { + matrix[FRONT_LEFT ][BACK_LEFT ] -= s->slev * M_SQRT1_2; + matrix[FRONT_LEFT ][BACK_RIGHT] -= s->slev * M_SQRT1_2; + matrix[FRONT_RIGHT][BACK_LEFT ] += s->slev * M_SQRT1_2; + matrix[FRONT_RIGHT][BACK_RIGHT] += s->slev * M_SQRT1_2; + } else if (matrix_encoding == AV_MATRIX_ENCODING_DPLII) { + matrix[FRONT_LEFT ][BACK_LEFT ] -= s->slev * SQRT3_2; + matrix[FRONT_LEFT ][BACK_RIGHT] -= s->slev * M_SQRT1_2; + matrix[FRONT_RIGHT][BACK_LEFT ] += s->slev * M_SQRT1_2; + matrix[FRONT_RIGHT][BACK_RIGHT] += s->slev * SQRT3_2; + } else { + matrix[ FRONT_LEFT][ BACK_LEFT] += s->slev; + matrix[FRONT_RIGHT][BACK_RIGHT] += s->slev; + } }else if(s->out_ch_layout & AV_CH_FRONT_CENTER){ matrix[ FRONT_CENTER][BACK_LEFT ]+= s->slev*M_SQRT1_2; matrix[ FRONT_CENTER][BACK_RIGHT]+= s->slev*M_SQRT1_2; @@ -222,8 +246,20 @@ static int auto_matrix(SwrContext *s) matrix[BACK_CENTER][ SIDE_LEFT]+= M_SQRT1_2; matrix[BACK_CENTER][SIDE_RIGHT]+= M_SQRT1_2; }else if(s->out_ch_layout & AV_CH_FRONT_LEFT){ - matrix[ FRONT_LEFT][ SIDE_LEFT]+= s->slev; - matrix[FRONT_RIGHT][SIDE_RIGHT]+= s->slev; + if (matrix_encoding == AV_MATRIX_ENCODING_DOLBY) { + matrix[FRONT_LEFT ][SIDE_LEFT ] -= s->slev * M_SQRT1_2; + matrix[FRONT_LEFT ][SIDE_RIGHT] -= s->slev * M_SQRT1_2; + matrix[FRONT_RIGHT][SIDE_LEFT ] += s->slev * M_SQRT1_2; + matrix[FRONT_RIGHT][SIDE_RIGHT] += s->slev * M_SQRT1_2; + } else if (matrix_encoding == AV_MATRIX_ENCODING_DPLII) { + matrix[FRONT_LEFT ][SIDE_LEFT ] -= s->slev * SQRT3_2; + matrix[FRONT_LEFT ][SIDE_RIGHT] -= s->slev * M_SQRT1_2; + matrix[FRONT_RIGHT][SIDE_LEFT ] += s->slev * M_SQRT1_2; + matrix[FRONT_RIGHT][SIDE_RIGHT] += s->slev * SQRT3_2; + } else { + matrix[ FRONT_LEFT][ SIDE_LEFT] += s->slev; + matrix[FRONT_RIGHT][SIDE_RIGHT] += s->slev; + } }else if(s->out_ch_layout & AV_CH_FRONT_CENTER){ matrix[ FRONT_CENTER][SIDE_LEFT ]+= s->slev*M_SQRT1_2; matrix[ FRONT_CENTER][SIDE_RIGHT]+= s->slev*M_SQRT1_2; |