[FFmpeg-cvslog] swr/auto_matrix: move layouts to local variables

Michael Niedermayer git at videolan.org
Sat Sep 8 21:35:47 CEST 2012


ffmpeg | branch: master | Michael Niedermayer <michaelni at gmx.at> | Sat Sep  8 20:55:15 2012 +0200| [ebc854e4e90c3b960d2776e52e251effcdea4243] | committer: Michael Niedermayer

swr/auto_matrix: move layouts to local variables

Signed-off-by: Michael Niedermayer <michaelni at gmx.at>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=ebc854e4e90c3b960d2776e52e251effcdea4243
---

 libswresample/rematrix.c |   72 ++++++++++++++++++++++++----------------------
 1 file changed, 37 insertions(+), 35 deletions(-)

diff --git a/libswresample/rematrix.c b/libswresample/rematrix.c
index 8284e5c..9fa4f52 100644
--- a/libswresample/rematrix.c
+++ b/libswresample/rematrix.c
@@ -123,35 +123,37 @@ static int auto_matrix(SwrContext *s)
 {
     int i, j, out_i;
     double matrix[64][64]={{0}};
-    int64_t unaccounted= s->in_ch_layout & ~s->out_ch_layout;
+    int64_t unaccounted, in_ch_layout = s->in_ch_layout, out_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++){
-        if(s->in_ch_layout & s->out_ch_layout & (1LL<<i))
-            matrix[i][i]= 1.0;
-    }
-
-    if(!sane_layout(s->in_ch_layout)){
+    if(!sane_layout(in_ch_layout)){
         av_get_channel_layout_string(buf, sizeof(buf), -1, s->in_ch_layout);
         av_log(s, AV_LOG_ERROR, "Input channel layout '%s' is not supported\n", buf);
         return AVERROR(EINVAL);
     }
-    if(!sane_layout(s->out_ch_layout)){
+    if(!sane_layout(out_ch_layout)){
         av_get_channel_layout_string(buf, sizeof(buf), -1, s->out_ch_layout);
         av_log(s, AV_LOG_ERROR, "Output channel layout '%s' is not supported\n", buf);
         return AVERROR(EINVAL);
     }
 
+    memset(s->matrix, 0, sizeof(s->matrix));
+    for(i=0; i<64; i++){
+        if(in_ch_layout & out_ch_layout & (1LL<<i))
+            matrix[i][i]= 1.0;
+    }
+
+    unaccounted= in_ch_layout & ~out_ch_layout;
+
 //FIXME implement dolby surround
 //FIXME implement full ac3
 
 
     if(unaccounted & AV_CH_FRONT_CENTER){
-        if((s->out_ch_layout & AV_CH_LAYOUT_STEREO) == AV_CH_LAYOUT_STEREO){
-            if(s->in_ch_layout & AV_CH_LAYOUT_STEREO) {
+        if((out_ch_layout & AV_CH_LAYOUT_STEREO) == AV_CH_LAYOUT_STEREO){
+            if(in_ch_layout & AV_CH_LAYOUT_STEREO) {
                 matrix[ FRONT_LEFT][FRONT_CENTER]+= s->clev;
                 matrix[FRONT_RIGHT][FRONT_CENTER]+= s->clev;
             } else {
@@ -162,23 +164,23 @@ static int auto_matrix(SwrContext *s)
             av_assert0(0);
     }
     if(unaccounted & AV_CH_LAYOUT_STEREO){
-        if(s->out_ch_layout & AV_CH_FRONT_CENTER){
+        if(out_ch_layout & AV_CH_FRONT_CENTER){
             matrix[FRONT_CENTER][ FRONT_LEFT]+= M_SQRT1_2;
             matrix[FRONT_CENTER][FRONT_RIGHT]+= M_SQRT1_2;
-            if(s->in_ch_layout & AV_CH_FRONT_CENTER)
+            if(in_ch_layout & AV_CH_FRONT_CENTER)
                 matrix[FRONT_CENTER][ FRONT_CENTER] = s->clev*sqrt(2);
         }else
             av_assert0(0);
     }
 
     if(unaccounted & AV_CH_BACK_CENTER){
-        if(s->out_ch_layout & AV_CH_BACK_LEFT){
+        if(out_ch_layout & AV_CH_BACK_LEFT){
             matrix[ BACK_LEFT][BACK_CENTER]+= M_SQRT1_2;
             matrix[BACK_RIGHT][BACK_CENTER]+= M_SQRT1_2;
-        }else if(s->out_ch_layout & AV_CH_SIDE_LEFT){
+        }else if(out_ch_layout & AV_CH_SIDE_LEFT){
             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){
+        }else if(out_ch_layout & AV_CH_FRONT_LEFT){
             if (matrix_encoding == AV_MATRIX_ENCODING_DOLBY ||
                 matrix_encoding == AV_MATRIX_ENCODING_DPLII) {
                 if (unaccounted & (AV_CH_BACK_LEFT | AV_CH_SIDE_LEFT)) {
@@ -192,24 +194,24 @@ static int auto_matrix(SwrContext *s)
                 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){
+        }else if(out_ch_layout & AV_CH_FRONT_CENTER){
             matrix[ FRONT_CENTER][BACK_CENTER]+= s->slev*M_SQRT1_2;
         }else
             av_assert0(0);
     }
     if(unaccounted & AV_CH_BACK_LEFT){
-        if(s->out_ch_layout & AV_CH_BACK_CENTER){
+        if(out_ch_layout & AV_CH_BACK_CENTER){
             matrix[BACK_CENTER][ BACK_LEFT]+= M_SQRT1_2;
             matrix[BACK_CENTER][BACK_RIGHT]+= M_SQRT1_2;
-        }else if(s->out_ch_layout & AV_CH_SIDE_LEFT){
-            if(s->in_ch_layout & AV_CH_SIDE_LEFT){
+        }else if(out_ch_layout & AV_CH_SIDE_LEFT){
+            if(in_ch_layout & AV_CH_SIDE_LEFT){
                 matrix[ SIDE_LEFT][ BACK_LEFT]+= M_SQRT1_2;
                 matrix[SIDE_RIGHT][BACK_RIGHT]+= M_SQRT1_2;
             }else{
             matrix[ SIDE_LEFT][ BACK_LEFT]+= 1.0;
             matrix[SIDE_RIGHT][BACK_RIGHT]+= 1.0;
             }
-        }else if(s->out_ch_layout & AV_CH_FRONT_LEFT){
+        }else if(out_ch_layout & AV_CH_FRONT_LEFT){
             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;
@@ -224,7 +226,7 @@ static int auto_matrix(SwrContext *s)
                 matrix[ FRONT_LEFT][ BACK_LEFT] += s->slev;
                 matrix[FRONT_RIGHT][BACK_RIGHT] += s->slev;
             }
-        }else if(s->out_ch_layout & AV_CH_FRONT_CENTER){
+        }else if(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;
         }else
@@ -232,20 +234,20 @@ static int auto_matrix(SwrContext *s)
     }
 
     if(unaccounted & AV_CH_SIDE_LEFT){
-        if(s->out_ch_layout & AV_CH_BACK_LEFT){
+        if(out_ch_layout & AV_CH_BACK_LEFT){
             /* if back channels do not exist in the input, just copy side
                channels to back channels, otherwise mix side into back */
-            if (s->in_ch_layout & AV_CH_BACK_LEFT) {
+            if (in_ch_layout & AV_CH_BACK_LEFT) {
                 matrix[BACK_LEFT ][SIDE_LEFT ] += M_SQRT1_2;
                 matrix[BACK_RIGHT][SIDE_RIGHT] += M_SQRT1_2;
             } else {
                 matrix[BACK_LEFT ][SIDE_LEFT ] += 1.0;
                 matrix[BACK_RIGHT][SIDE_RIGHT] += 1.0;
             }
-        }else if(s->out_ch_layout & AV_CH_BACK_CENTER){
+        }else if(out_ch_layout & AV_CH_BACK_CENTER){
             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){
+        }else if(out_ch_layout & AV_CH_FRONT_LEFT){
             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;
@@ -260,7 +262,7 @@ static int auto_matrix(SwrContext *s)
                 matrix[ FRONT_LEFT][ SIDE_LEFT] += s->slev;
                 matrix[FRONT_RIGHT][SIDE_RIGHT] += s->slev;
             }
-        }else if(s->out_ch_layout & AV_CH_FRONT_CENTER){
+        }else if(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;
         }else
@@ -268,10 +270,10 @@ static int auto_matrix(SwrContext *s)
     }
 
     if(unaccounted & AV_CH_FRONT_LEFT_OF_CENTER){
-        if(s->out_ch_layout & AV_CH_FRONT_LEFT){
+        if(out_ch_layout & AV_CH_FRONT_LEFT){
             matrix[ FRONT_LEFT][ FRONT_LEFT_OF_CENTER]+= 1.0;
             matrix[FRONT_RIGHT][FRONT_RIGHT_OF_CENTER]+= 1.0;
-        }else if(s->out_ch_layout & AV_CH_FRONT_CENTER){
+        }else if(out_ch_layout & AV_CH_FRONT_CENTER){
             matrix[ FRONT_CENTER][ FRONT_LEFT_OF_CENTER]+= M_SQRT1_2;
             matrix[ FRONT_CENTER][FRONT_RIGHT_OF_CENTER]+= M_SQRT1_2;
         }else
@@ -279,9 +281,9 @@ static int auto_matrix(SwrContext *s)
     }
     /* mix LFE into front left/right or center */
     if (unaccounted & AV_CH_LOW_FREQUENCY) {
-        if (s->out_ch_layout & AV_CH_FRONT_CENTER) {
+        if (out_ch_layout & AV_CH_FRONT_CENTER) {
             matrix[FRONT_CENTER][LOW_FREQUENCY] += s->lfe_mix_level;
-        } else if (s->out_ch_layout & AV_CH_FRONT_LEFT) {
+        } else if (out_ch_layout & AV_CH_FRONT_LEFT) {
             matrix[FRONT_LEFT ][LOW_FREQUENCY] += s->lfe_mix_level * M_SQRT1_2;
             matrix[FRONT_RIGHT][LOW_FREQUENCY] += s->lfe_mix_level * M_SQRT1_2;
         } else
@@ -296,11 +298,11 @@ static int auto_matrix(SwrContext *s)
             if(matrix[i][j]){
                 sum += fabs(matrix[i][j]);
             }
-            if(s->in_ch_layout & (1ULL<<j))
+            if(in_ch_layout & (1ULL<<j))
                 in_i++;
         }
         maxcoef= FFMAX(maxcoef, sum);
-        if(s->out_ch_layout & (1ULL<<i))
+        if(out_ch_layout & (1ULL<<i))
             out_i++;
     }
     if(s->rematrix_volume  < 0)
@@ -321,8 +323,8 @@ static int auto_matrix(SwrContext *s)
             }
     }
 
-    for(i=0; i<av_get_channel_layout_nb_channels(s->out_ch_layout); i++){
-        for(j=0; j<av_get_channel_layout_nb_channels(s->in_ch_layout); j++){
+    for(i=0; i<av_get_channel_layout_nb_channels(out_ch_layout); i++){
+        for(j=0; j<av_get_channel_layout_nb_channels(in_ch_layout); j++){
             av_log(NULL, AV_LOG_DEBUG, "%f ", s->matrix[i][j]);
         }
         av_log(NULL, AV_LOG_DEBUG, "\n");



More information about the ffmpeg-cvslog mailing list