[FFmpeg-soc] [soc]: r3665 - eac3/spectral_extension.patch

jbr subversion at mplayerhq.hu
Fri Aug 29 04:22:43 CEST 2008


Author: jbr
Date: Fri Aug 29 04:22:43 2008
New Revision: 3665

Log:
add a patch for spectral extension decoding. will apply it after the
remainder of the decoder is in FFmpeg SVN.

Added:
   eac3/spectral_extension.patch

Added: eac3/spectral_extension.patch
==============================================================================
--- (empty file)
+++ eac3/spectral_extension.patch	Fri Aug 29 04:22:43 2008
@@ -0,0 +1,238 @@
+Index: ffmpeg.patch
+===================================================================
+--- ffmpeg.patch	(revision 3635)
++++ ffmpeg.patch	(working copy)
+@@ -1,6 +1,27 @@
++Index: libavcodec/ac3dec.h
++===================================================================
++--- libavcodec/ac3dec.h	(revision 15015)
+++++ 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;
+++    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/Makefile
+ ===================================================================
+---- libavcodec/Makefile	(revision 14991)
++--- libavcodec/Makefile	(revision 15015)
+ +++ libavcodec/Makefile	(working copy)
+ @@ -27,7 +27,7 @@
+  
+@@ -11,3 +32,32 @@
+  OBJS-$(CONFIG_AC3_ENCODER)             += ac3enc.o ac3tab.o ac3.o
+  OBJS-$(CONFIG_ALAC_DECODER)            += alac.o
+  OBJS-$(CONFIG_ALAC_ENCODER)            += alacenc.o lpc.o
++Index: libavcodec/ac3dec_data.c
++===================================================================
++--- libavcodec/ac3dec_data.c	(revision 15015)
+++++ 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 15015)
+++++ 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];
++ 
+Index: ac3dec.c
+===================================================================
+--- ac3dec.c	(revision 3664)
++++ ac3dec.c	(working copy)
+@@ -755,15 +755,70 @@
+     } while(i--);
+ 
+     /* spectral extension strategy */
++    s->spx_in_use[blk] = blk ? s->spx_in_use[blk-1] : 0;
+     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 */
+     }
+ 
+-    /* 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 +857,18 @@
+             /* 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 +946,14 @@
+     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 +976,11 @@
+         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);
+Index: eac3dec.c
+===================================================================
+--- eac3dec.c	(revision 3663)
++++ eac3dec.c	(working copy)
+@@ -463,7 +463,7 @@
+ 
+     /* spectral extension attenuation data */
+     if (parse_spx_atten_data) {
+-        av_log_missing_feature(s->avctx, "Spectral extension attenuation", 1);
++        //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
+@@ -483,6 +483,7 @@
+ 
+     /* 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;
+Index: checkout.sh
+===================================================================
+--- checkout.sh	(revision 3635)
++++ checkout.sh	(working copy)
+@@ -1,10 +1,10 @@
+ FILES="eac3dec.c ac3dec.c"
+ 
+ echo "checking out ffmpeg svn"
+-for i in $FILES Makefile; do
++for i in $FILES Makefile 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 14991
++svn checkout svn://svn.mplayerhq.hu/ffmpeg/trunk/ ffmpeg -r 15015
+ echo "patching ffmpeg"
+ cd ffmpeg
+ patch -p0 <../ffmpeg.patch



More information about the FFmpeg-soc mailing list