[FFmpeg-soc] [soc]: r3697 - in eac3: ac3dec.c checkout.sh eac3dec.c ffmpeg.patch spectral_extension.patch

jbr subversion at mplayerhq.hu
Mon Sep 1 19:54:25 CEST 2008


Author: jbr
Date: Mon Sep  1 19:54:25 2008
New Revision: 3697

Log:
add decoding support for spectral extension. this can decode the files, but
does not yet apply the band replication.

Removed:
   eac3/spectral_extension.patch
Modified:
   eac3/ac3dec.c
   eac3/checkout.sh
   eac3/eac3dec.c
   eac3/ffmpeg.patch

Modified: eac3/ac3dec.c
==============================================================================
--- eac3/ac3dec.c	(original)
+++ eac3/ac3dec.c	Mon Sep  1 19:54:25 2008
@@ -756,14 +756,70 @@ static int decode_audio_block(AC3DecodeC
 
     /* spectral extension strategy */
     if (s->eac3 && (!blk || get_bits1(gbc))) {
-        if (get_bits1(gbc)) {
-            av_log_missing_feature(s->avctx, "Spectral extension", 1);
-            return -1;
+        s->spx_in_use[blk] = get_bits1(gbc);
+        if (s->spx_in_use[blk]) {
+            static const uint8_t spx_begf_remap_tab[8] = { 2, 3, 4, 5,  6,  7,  9, 11 };
+            static const uint8_t spx_endf_remap_tab[8] = { 5, 6, 7, 8, 11, 13, 15, 17 };
+            int spx_end_band, num_spx_subbands;
+
+            /* determine which channels use spx */
+            if (s->channel_mode == AC3_CHMODE_MONO) {
+                s->channel_in_spx[1] = 1;
+            } else {
+                for (ch = 1; ch <= fbw_channels; ch++)
+                    s->channel_in_spx[ch] = get_bits1(gbc);
+            }
+
+            skip_bits(gbc, 2); // skip spx start copy freq
+            s->spx_begin_band = spx_begf_remap_tab[get_bits(gbc, 3)];
+            spx_end_band      = spx_endf_remap_tab[get_bits(gbc, 3)];
+            num_spx_subbands  = s->num_spx_bands = spx_end_band - s->spx_begin_band;
+            s->spx_start_freq = s->spx_begin_band * 12 + 25;
+
+            /* spectral extension band structure */
+            if (get_bits1(gbc)) {
+                for (bnd = 0; bnd < num_spx_subbands - 1; bnd++) {
+                    s->spx_band_struct[bnd] = get_bits1(gbc);
+                }
+            } else if (!blk) {
+                memcpy(s->spx_band_struct,
+                       &ff_eac3_default_spx_band_struct[s->spx_begin_band+1],
+                       num_spx_subbands-1);
+            }
+            s->spx_band_struct[num_spx_subbands-1] = 0;
+
+            /* calculate number of spx bands based on band structure */
+            for (bnd = 0; bnd < num_spx_subbands-1; bnd++) {
+                s->num_spx_bands -= s->spx_band_struct[bnd];
+            }
+        } else {
+            for (ch = 1; ch <= fbw_channels; ch++) {
+                s->channel_in_spx[ch] = 0;
+                s->first_spx_coords[ch] = 1;
+            }
         }
-        /* TODO: parse spectral extension strategy info */
+    } else {
+        s->spx_in_use[blk] = blk ? s->spx_in_use[blk-1] : 0;
     }
 
-    /* TODO: spectral extension coordinates */
+    /* spectral extension coordinates */
+    if (s->spx_in_use[blk]) {
+        for (ch = 1; ch <= fbw_channels; ch++) {
+            if (s->channel_in_spx[ch]) {
+                if (s->first_spx_coords[ch] || get_bits1(gbc)) {
+                    s->first_spx_coords[ch] = 0;
+                    skip_bits(gbc, 5); // skip spx blend
+                    skip_bits(gbc, 2); // skip master spx coord
+                    for (bnd = 0; bnd < s->num_spx_bands; bnd++) {
+                        skip_bits(gbc, 4); // skip spx coord exponent
+                        skip_bits(gbc, 2); // skip spx coord mantissa
+                    }
+                }
+            } else {
+                s->first_spx_coords[ch] = 1;
+            }
+        }
+    }
 
     /* coupling strategy */
     if (s->eac3 ? s->cpl_strategy_exists[blk] : get_bits1(gbc)) {
@@ -802,14 +858,18 @@ static int decode_audio_block(AC3DecodeC
             /* coupling frequency range */
             /* TODO: modify coupling end freq if spectral extension is used */
             cpl_begin_freq = get_bits(gbc, 4);
-            cpl_end_freq = get_bits(gbc, 4);
-            if (3 + cpl_end_freq - cpl_begin_freq < 0) {
-                av_log(s->avctx, AV_LOG_ERROR, "3+cplendf = %d < cplbegf = %d\n", 3+cpl_end_freq, cpl_begin_freq);
+            if (s->spx_in_use[blk]) {
+                cpl_end_freq = s->spx_begin_band - 1;
+            } else {
+                cpl_end_freq = get_bits(gbc, 4) + 3;
+            }
+            if (cpl_end_freq - cpl_begin_freq < 0) {
+                av_log(s->avctx, AV_LOG_ERROR, "cplendf = %d < cplbegf = %d\n", cpl_end_freq, cpl_begin_freq);
                 return -1;
             }
-            s->num_cpl_bands = s->num_cpl_subbands = 3 + cpl_end_freq - cpl_begin_freq;
+            s->num_cpl_bands = s->num_cpl_subbands = cpl_end_freq - cpl_begin_freq;
             s->start_freq[CPL_CH] = cpl_begin_freq * 12 + 37;
-            s->end_freq[CPL_CH] = cpl_end_freq * 12 + 73;
+            s->end_freq  [CPL_CH] = cpl_end_freq   * 12 + 37;
 
             /* coupling band structure */
             if (!s->eac3 || get_bits1(gbc)) {
@@ -887,8 +947,14 @@ static int decode_audio_block(AC3DecodeC
     if (channel_mode == AC3_CHMODE_STEREO) {
         if ((s->eac3 && !blk) || get_bits1(gbc)) {
             s->num_rematrixing_bands = 4;
-            if(cpl_in_use && s->start_freq[CPL_CH] <= 61)
+            if (cpl_in_use) {
+                if  (s->start_freq[CPL_CH] <= 61)
                 s->num_rematrixing_bands -= 1 + (s->start_freq[CPL_CH] == 37);
+            } else if (s->spx_in_use[blk]) {
+                if (s->spx_start_freq <= 61)
+                    s->num_rematrixing_bands -= 1 + (s->spx_start_freq <= 37) +
+                                                    (s->spx_start_freq <= 25);
+            }
             for(bnd=0; bnd<s->num_rematrixing_bands; bnd++)
                 s->rematrixing_flags[bnd] = get_bits1(gbc);
         } else if (!blk) {
@@ -911,9 +977,11 @@ static int decode_audio_block(AC3DecodeC
         if (s->exp_strategy[blk][ch] != EXP_REUSE) {
             int group_size;
             int prev = s->end_freq[ch];
-            if (s->channel_in_cpl[ch])
+            if (s->channel_in_cpl[ch]) {
                 s->end_freq[ch] = s->start_freq[CPL_CH];
-            else {
+            } else if (s->channel_in_spx[ch]) {
+                s->end_freq[ch] = s->spx_start_freq;
+            } else {
                 int bandwidth_code = get_bits(gbc, 6);
                 if (bandwidth_code > 60) {
                     av_log(s->avctx, AV_LOG_ERROR, "bandwidth code = %d > 60", bandwidth_code);

Modified: eac3/checkout.sh
==============================================================================
--- eac3/checkout.sh	(original)
+++ eac3/checkout.sh	Mon Sep  1 19:54:25 2008
@@ -1,10 +1,10 @@
 FILES="eac3dec.c ac3dec.c"
 
 echo "checking out ffmpeg svn"
-for i in $FILES ; do
+for i in $FILES ac3dec.h ac3dec_data.c ac3dec_data.h; do
     rm -f ffmpeg/libavcodec/$i
 done
-svn checkout svn://svn.mplayerhq.hu/ffmpeg/trunk/ ffmpeg -r 15103
+svn checkout svn://svn.mplayerhq.hu/ffmpeg/trunk/ ffmpeg -r 15141
 echo "patching ffmpeg"
 cd ffmpeg
 patch -p0 <../ffmpeg.patch

Modified: eac3/eac3dec.c
==============================================================================
--- eac3/eac3dec.c	(original)
+++ eac3/eac3dec.c	Mon Sep  1 19:54:25 2008
@@ -460,7 +460,6 @@ int ff_eac3_parse_header(AC3DecodeContex
 
     /* spectral extension attenuation data */
     if (parse_spx_atten_data) {
-        av_log_missing_feature(s->avctx, "Spectral extension attenuation", 1);
         for (ch = 1; ch <= s->fbw_channels; ch++) {
             if (get_bits1(gbc)) { // channel has spx attenuation
                 skip_bits(gbc, 5); // skip spx attenuation code
@@ -480,6 +479,7 @@ int ff_eac3_parse_header(AC3DecodeContex
 
     /* syntax state initialization */
     for (ch = 1; ch <= s->fbw_channels; ch++) {
+        s->first_spx_coords[ch] = 1;
         s->first_cpl_coords[ch] = 1;
     }
     s->first_cpl_leak = 1;

Modified: eac3/ffmpeg.patch
==============================================================================
--- eac3/ffmpeg.patch	(original)
+++ eac3/ffmpeg.patch	Mon Sep  1 19:54:25 2008
@@ -0,0 +1,50 @@
+Index: libavcodec/ac3dec.h
+===================================================================
+--- libavcodec/ac3dec.h	(revision 15141)
++++ libavcodec/ac3dec.h	(working copy)
+@@ -88,6 +88,16 @@
+     int cpl_coords[AC3_MAX_CHANNELS][18];   ///< coupling coordinates                   (cplco)
+ ///@}
+ 
++///@defgroup spx spectral extension
++    int spx_in_use[MAX_BLOCKS];             ///< spectral extension in use              (spxinu)
++    int channel_in_spx[AC3_MAX_CHANNELS];   ///< channel in spectral extension          (chinspx)
++    int spx_begin_band;                     ///< spx beginning frequency band           (spxbegf)
++    int spx_start_freq;                     ///< spx start frequency bin
++    int num_spx_bands;                      ///< number of spectral extension bands     (nspxbnds)
++    uint8_t spx_band_struct[17];            ///< spectral extension band structure      (spxbndstrc)
++    int first_spx_coords[AC3_MAX_CHANNELS]; ///< first spx coordinates states           (firstspxcos)
++///@}
++
+ ///@defgroup aht adaptive hybrid transform
+     int channel_uses_aht[AC3_MAX_CHANNELS];                         ///< channel AHT in use (chahtinu)
+     int pre_mantissa[AC3_MAX_CHANNELS][AC3_MAX_COEFS][MAX_BLOCKS];  ///< pre-IDCT mantissas
+Index: libavcodec/ac3dec_data.c
+===================================================================
+--- libavcodec/ac3dec_data.c	(revision 15141)
++++ libavcodec/ac3dec_data.c	(working copy)
+@@ -1128,6 +1128,12 @@
+ { 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1 };
+ 
+ /**
++ * Table E2.15 Default Spectral Extension Banding Structure
++ */
++const uint8_t ff_eac3_default_spx_band_struct[17] =
++{ 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1 };
++
++/**
+  * Table of bin locations for rematrixing bands
+  * reference: Section 7.5.2 Rematrixing : Frequency Band Definitions
+  */
+Index: libavcodec/ac3dec_data.h
+===================================================================
+--- libavcodec/ac3dec_data.h	(revision 15141)
++++ libavcodec/ac3dec_data.h	(working copy)
+@@ -34,6 +34,7 @@
+ extern const int16_t (*ff_eac3_mantissa_vq[8])[6];
+ extern const uint8_t ff_eac3_frm_expstr[32][6];
+ extern const uint8_t ff_eac3_default_cpl_band_struct[18];
++extern const uint8_t ff_eac3_default_spx_band_struct[17];
+ 
+ extern const uint8_t ff_ac3_rematrix_band_tab[5];
+ 



More information about the FFmpeg-soc mailing list