[FFmpeg-soc] [soc]: r1729 - in eac3: ac3dec.c ac3dec.h eac3dec.c

jbr subversion at mplayerhq.hu
Mon Dec 31 03:26:01 CET 2007


Author: jbr
Date: Mon Dec 31 03:26:01 2007
New Revision: 1729

Log:
move setting of downmix coefficients to a separate function

Modified:
   eac3/ac3dec.c
   eac3/ac3dec.h
   eac3/eac3dec.c

Modified: eac3/ac3dec.c
==============================================================================
--- eac3/ac3dec.c	(original)
+++ eac3/ac3dec.c	Mon Dec 31 03:26:01 2007
@@ -239,7 +239,6 @@ static int ac3_parse_header(AC3DecodeCon
 {
     AC3HeaderInfo hdr;
     GetBitContext *gbc = &s->gbc;
-    float center_mix_level, surround_mix_level;
     int err, i;
 
     err = ff_ac3_parse_header(gbc->buffer, &hdr);
@@ -265,8 +264,8 @@ static int ac3_parse_header(AC3DecodeCon
         s->output_mode |= AC3_OUTPUT_LFEON;
 
     /* set default mix levels */
-    center_mix_level = LEVEL_MINUS_4POINT5DB;
-    surround_mix_level = LEVEL_MINUS_6DB;
+    s->center_mix_level = 5;    // -4.5dB
+    s->surround_mix_level = 6;  // -6.0dB
 
     /* skip over portion of header which has already been read */
     skip_bits(gbc, 16); // skip the sync_word
@@ -277,9 +276,9 @@ static int ac3_parse_header(AC3DecodeCon
         skip_bits(gbc, 2); // skip dsurmod
     } else {
         if((s->channel_mode & 1) && s->channel_mode != AC3_CHMODE_MONO)
-            center_mix_level = ff_ac3_mix_levels[center_levels[get_bits(gbc, 2)]];
+            s->center_mix_level = center_levels[get_bits(gbc, 2)];
         if(s->channel_mode & 4)
-            surround_mix_level = ff_ac3_mix_levels[surround_levels[get_bits(gbc, 2)]];
+            s->surround_mix_level = surround_levels[get_bits(gbc, 2)];
     }
     skip_bits1(gbc); // skip lfeon
 
@@ -312,25 +311,34 @@ static int ac3_parse_header(AC3DecodeCon
         } while(i--);
     }
 
-    /* set stereo downmixing coefficients
-       reference: Section 7.8.2 Downmixing Into Two Channels */
+    return 0;
+}
+
+/**
+ * Set stereo downmixing coefficients based on frame header info.
+ * reference: Section 7.8.2 Downmixing Into Two Channels
+ */
+void ff_ac3_set_downmix_coeffs(AC3DecodeContext *s)
+{
+    int i;
+    float cmix = ff_ac3_mix_levels[s->center_mix_level];
+    float smix = ff_ac3_mix_levels[s->surround_mix_level];
+
     for(i=0; i<s->fbw_channels; i++) {
         s->downmix_coeffs[i][0] = ff_ac3_mix_levels[ff_ac3_default_coeffs[s->channel_mode][i][0]];
         s->downmix_coeffs[i][1] = ff_ac3_mix_levels[ff_ac3_default_coeffs[s->channel_mode][i][1]];
     }
     if(s->channel_mode > 1 && s->channel_mode & 1) {
-        s->downmix_coeffs[1][0] = s->downmix_coeffs[1][1] = center_mix_level;
+        s->downmix_coeffs[1][0] = s->downmix_coeffs[1][1] = cmix;
     }
     if(s->channel_mode == AC3_CHMODE_2F1R || s->channel_mode == AC3_CHMODE_3F1R) {
         int nf = s->channel_mode - 2;
-        s->downmix_coeffs[nf][0] = s->downmix_coeffs[nf][1] = surround_mix_level * LEVEL_MINUS_3DB;
+        s->downmix_coeffs[nf][0] = s->downmix_coeffs[nf][1] = smix * LEVEL_MINUS_3DB;
     }
     if(s->channel_mode == AC3_CHMODE_2F2R || s->channel_mode == AC3_CHMODE_3F2R) {
         int nf = s->channel_mode - 4;
-        s->downmix_coeffs[nf][0] = s->downmix_coeffs[nf+1][1] = surround_mix_level;
+        s->downmix_coeffs[nf][0] = s->downmix_coeffs[nf+1][1] = smix;
     }
-
-    return 0;
 }
 
 /**
@@ -1023,6 +1031,7 @@ static int ac3_decode_frame(AVCodecConte
         /* downmix output if needed */
         if(s->channels != s->out_channels && !((s->output_mode & AC3_OUTPUT_LFEON) &&
                 s->fbw_channels == s->out_channels)) {
+            ff_ac3_set_downmix_coeffs(s);
             ff_ac3_downmix(s);
         }
 

Modified: eac3/ac3dec.h
==============================================================================
--- eac3/ac3dec.h	(original)
+++ eac3/ac3dec.h	Mon Dec 31 03:26:01 2007
@@ -84,6 +84,8 @@ typedef struct AC3DecodeContext {
     int channel_mode;   ///< Channel mode (acmod)
     int lfe_on;         ///< Low frequency effect channel on (lfeon)
     int bitstream_id;   ///< Bit stream identification (bsid)
+    int center_mix_level;   ///< Center mix level index
+    int surround_mix_level; ///< Surround mix level index
 ///@}
 
 ///@defgroup audfrm Frame Syntax Parameters
@@ -256,6 +258,8 @@ void ff_ac3_do_imdct(AC3DecodeContext *s
 
 void ff_ac3_downmix(AC3DecodeContext *s);
 
+void ff_ac3_set_downmix_coeffs(AC3DecodeContext *s);
+
 /** Adjustments in dB gain */
 #define LEVEL_PLUS_3DB          1.4142135623730950
 #define LEVEL_PLUS_1POINT5DB    1.1892071150027209

Modified: eac3/eac3dec.c
==============================================================================
--- eac3/eac3dec.c	(original)
+++ eac3/eac3dec.c	Mon Dec 31 03:26:01 2007
@@ -366,12 +366,9 @@ static int parse_bsi(AC3DecodeContext *s
     }
 #endif
 
-    /* set stereo downmixing coefficients
-       reference: Section 7.8.2 Downmixing Into Two Channels */
-    for (i = 0; i < s->fbw_channels; i++) {
-        s->downmix_coeffs[i][0] = ff_ac3_mix_levels[ff_ac3_default_coeffs[s->channel_mode][i][0]];
-        s->downmix_coeffs[i][1] = ff_ac3_mix_levels[ff_ac3_default_coeffs[s->channel_mode][i][1]];
-    }
+    /* set default mix levels */
+    s->center_mix_level = 5;    // -4.5dB
+    s->surround_mix_level = 6;  // -6.0dB
 
     if (get_bits1(gbc)) {
         /* Mixing metadata */
@@ -382,21 +379,12 @@ static int parse_bsi(AC3DecodeContext *s
             if (s->channel_mode & 1) {
                 /* if three front channels exist */
                 skip_bits(gbc, 3); //skip Lt/Rt center mix level
-                s->downmix_coeffs[1][0] = s->downmix_coeffs[1][1] = ff_ac3_mix_levels[get_bits(gbc, 3)];
+                s->center_mix_level = get_bits(gbc, 3);
             }
             if (s->channel_mode & 4) {
                 /* if a surround channel exists */
-                float surmixlev;
                 skip_bits(gbc, 3); //skip Lt/Rt surround mix level
-                surmixlev = ff_ac3_mix_levels[get_bits(gbc, 3)];
-                if (s->channel_mode & 2) {
-                    //two surround channels
-                    s->downmix_coeffs[s->channel_mode-4][0] = s->downmix_coeffs[s->channel_mode-3][1] =
-                        surmixlev;
-                } else {
-                    s->downmix_coeffs[s->channel_mode-2][0] = s->downmix_coeffs[s->channel_mode-2][1] =
-                        surmixlev * LEVEL_MINUS_3DB;
-                }
+                s->surround_mix_level = get_bits(gbc, 3);
             }
         }
         if (s->lfe_on && get_bits1(gbc)) {
@@ -1232,6 +1220,7 @@ static int eac3_decode_frame(AVCodecCont
 
         if(c->channels != c->out_channels && !((c->output_mode & AC3_OUTPUT_LFEON) &&
                 c->fbw_channels == c->out_channels)) {
+            ff_ac3_set_downmix_coeffs(c);
             ff_ac3_downmix(c);
         }
 



More information about the FFmpeg-soc mailing list