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

jbr subversion at mplayerhq.hu
Sun Dec 30 07:46:00 CET 2007


Author: jbr
Date: Sun Dec 30 07:45:59 2007
New Revision: 1706

Log:
use same context for ac3 and eac3 decoders

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

Modified: eac3/ac3.h
==============================================================================
--- eac3/ac3.h	(original)
+++ eac3/ac3.h	Sun Dec 30 07:45:59 2007
@@ -43,8 +43,6 @@
 #define EXP_D25   2
 #define EXP_D45   3
 
-#define AC3_OUTPUT_LFEON  8
-
 /** Delta bit allocation strategy */
 typedef enum {
     DBA_REUSE = 0,

Modified: eac3/ac3dec.c
==============================================================================
--- eac3/ac3dec.c	(original)
+++ eac3/ac3dec.c	Sun Dec 30 07:45:59 2007
@@ -106,79 +106,6 @@ const uint8_t ff_ac3_default_coeffs[8][5
     { { 2, 7 }, { 5, 5 }, { 7, 2 }, { 6, 7 }, { 7, 6 }, },
 };
 
-/* override ac3.h to include coupling channel */
-#undef AC3_MAX_CHANNELS
-#define AC3_MAX_CHANNELS 7
-
-typedef struct {
-    int channel_mode;                       ///< channel mode (acmod)
-    int block_switch[AC3_MAX_CHANNELS];     ///< block switch flags
-    int dither_flag[AC3_MAX_CHANNELS];      ///< dither flags
-    int dither_all;                         ///< true if all channels are dithered
-    int cpl_in_use;                         ///< coupling in use
-    int channel_in_cpl[AC3_MAX_CHANNELS];   ///< channel in coupling
-    int phase_flags_in_use;                 ///< phase flags in use
-    int cpl_band_struct[18];                ///< coupling band structure
-    int rematrixing_strategy;               ///< rematrixing strategy
-    int num_rematrixing_bands;              ///< number of rematrixing bands
-    int rematrixing_flags[4];               ///< rematrixing flags
-    int exp_strategy[AC3_MAX_CHANNELS];     ///< exponent strategies
-    int snr_offset[AC3_MAX_CHANNELS];       ///< signal-to-noise ratio offsets
-    int fast_gain[AC3_MAX_CHANNELS];        ///< fast gain values (signal-to-mask ratio)
-    int dba_mode[AC3_MAX_CHANNELS];         ///< delta bit allocation mode
-    int dba_nsegs[AC3_MAX_CHANNELS];        ///< number of delta segments
-    uint8_t dba_offsets[AC3_MAX_CHANNELS][8]; ///< delta segment offsets
-    uint8_t dba_lengths[AC3_MAX_CHANNELS][8]; ///< delta segment lengths
-    uint8_t dba_values[AC3_MAX_CHANNELS][8];  ///< delta values for each segment
-
-    int sample_rate;                        ///< sample frequency, in Hz
-    int bit_rate;                           ///< stream bit rate, in bits-per-second
-    int frame_size;                         ///< current frame size, in bytes
-
-    int channels;                           ///< number of total channels
-    int fbw_channels;                       ///< number of full-bandwidth channels
-    int lfe_on;                             ///< lfe channel in use
-    int lfe_ch;                             ///< index of LFE channel
-    int output_mode;                        ///< output channel configuration
-    int out_channels;                       ///< number of output channels
-
-    float downmix_coeffs[AC3_MAX_CHANNELS][2];  ///< stereo downmix coefficients
-    float dynamic_range[2];                 ///< dynamic range
-    float cpl_coords[AC3_MAX_CHANNELS][18]; ///< coupling coordinates
-    int   num_cpl_bands;                    ///< number of coupling bands
-    int   num_cpl_subbands;                 ///< number of coupling sub bands
-    int   start_freq[AC3_MAX_CHANNELS];     ///< start frequency bin
-    int   end_freq[AC3_MAX_CHANNELS];       ///< end frequency bin
-    AC3BitAllocParameters bit_alloc_params; ///< bit allocation parameters
-
-    int8_t  dexps[AC3_MAX_CHANNELS][256];   ///< decoded exponents
-    uint8_t bap[AC3_MAX_CHANNELS][256];     ///< bit allocation pointers
-    int16_t psd[AC3_MAX_CHANNELS][256];     ///< scaled exponents
-    int16_t band_psd[AC3_MAX_CHANNELS][50]; ///< interpolated exponents
-    int16_t mask[AC3_MAX_CHANNELS][50];     ///< masking curve values
-
-    DECLARE_ALIGNED_16(float, transform_coeffs[AC3_MAX_CHANNELS][256]);  ///< transform coefficients
-
-    /* For IMDCT. */
-    MDCTContext imdct_512;                  ///< for 512 sample IMDCT
-    MDCTContext imdct_256;                  ///< for 256 sample IMDCT
-    DSPContext  dsp;                        ///< for optimization
-    float       add_bias;                   ///< offset for float_to_int16 conversion
-    float       mul_bias;                   ///< scaling for float_to_int16 conversion
-
-    DECLARE_ALIGNED_16(float, output[AC3_MAX_CHANNELS-1][256]);     ///< output after imdct transform and windowing
-    DECLARE_ALIGNED_16(short, int_output[AC3_MAX_CHANNELS-1][256]); ///< final 16-bit integer output
-    DECLARE_ALIGNED_16(float, delay[AC3_MAX_CHANNELS-1][256]);      ///< delay - added to the next block
-    DECLARE_ALIGNED_16(float, tmp_imdct[256]);                      ///< temporary storage for imdct transform
-    DECLARE_ALIGNED_16(float, tmp_output[512]);                     ///< temporary storage for output before windowing
-    DECLARE_ALIGNED_16(float, window[256]);                         ///< window coefficients
-
-    /* Miscellaneous. */
-    GetBitContext gbc;                      ///< bitstream reader
-    AVRandomState dith_state;               ///< for dither generation
-    AVCodecContext *avctx;                  ///< parent context
-} AC3DecodeContext;
-
 /**
  * Generate a Kaiser-Bessel Derived Window.
  */
@@ -779,10 +706,12 @@ static int ac3_parse_audio_block(AC3Deco
     } while(i--);
 
     /* coupling strategy */
+    if(blk)
+        ctx->cpl_in_use[blk] = ctx->cpl_in_use[blk-1];
     if (get_bits1(gbc)) {
         memset(bit_alloc_stages, 3, AC3_MAX_CHANNELS);
-        ctx->cpl_in_use = get_bits1(gbc);
-        if (ctx->cpl_in_use) {
+        ctx->cpl_in_use[blk] = get_bits1(gbc);
+        if (ctx->cpl_in_use[blk]) {
             /* coupling in use */
             int cpl_begin_freq, cpl_end_freq;
 
@@ -818,7 +747,7 @@ static int ac3_parse_audio_block(AC3Deco
     }
 
     /* coupling coordinates */
-    if (ctx->cpl_in_use) {
+    if (ctx->cpl_in_use[blk]) {
         int cpl_coords_exist = 0;
 
         for (ch = 1; ch <= fbw_channels; ch++) {
@@ -850,10 +779,9 @@ static int ac3_parse_audio_block(AC3Deco
 
     /* stereo rematrixing strategy and band structure */
     if (channel_mode == AC3_CHMODE_STEREO) {
-        ctx->rematrixing_strategy = get_bits1(gbc);
-        if (ctx->rematrixing_strategy) {
+        if (get_bits1(gbc)) {
             ctx->num_rematrixing_bands = 4;
-            if(ctx->cpl_in_use && ctx->start_freq[CPL_CH] <= 61)
+            if(ctx->cpl_in_use[blk] && ctx->start_freq[CPL_CH] <= 61)
                 ctx->num_rematrixing_bands -= 1 + (ctx->start_freq[CPL_CH] == 37);
             for(bnd=0; bnd<ctx->num_rematrixing_bands; bnd++)
                 ctx->rematrixing_flags[bnd] = get_bits1(gbc);
@@ -861,21 +789,21 @@ static int ac3_parse_audio_block(AC3Deco
     }
 
     /* exponent strategies for each channel */
-    ctx->exp_strategy[CPL_CH] = EXP_REUSE;
-    ctx->exp_strategy[ctx->lfe_ch] = EXP_REUSE;
-    for (ch = !ctx->cpl_in_use; ch <= ctx->channels; ch++) {
+    ctx->exp_strategy[blk][CPL_CH] = EXP_REUSE;
+    ctx->exp_strategy[blk][ctx->lfe_ch] = EXP_REUSE;
+    for (ch = !ctx->cpl_in_use[blk]; ch <= ctx->channels; ch++) {
         if(ch == ctx->lfe_ch)
-            ctx->exp_strategy[ch] = get_bits(gbc, 1);
+            ctx->exp_strategy[blk][ch] = get_bits(gbc, 1);
         else
-            ctx->exp_strategy[ch] = get_bits(gbc, 2);
-        if(ctx->exp_strategy[ch] != EXP_REUSE)
+            ctx->exp_strategy[blk][ch] = get_bits(gbc, 2);
+        if(ctx->exp_strategy[blk][ch] != EXP_REUSE)
             bit_alloc_stages[ch] = 3;
     }
 
     /* channel bandwidth */
     for (ch = 1; ch <= fbw_channels; ch++) {
         ctx->start_freq[ch] = 0;
-        if (ctx->exp_strategy[ch] != EXP_REUSE) {
+        if (ctx->exp_strategy[blk][ch] != EXP_REUSE) {
             int prev = ctx->end_freq[ch];
             if (ctx->channel_in_cpl[ch])
                 ctx->end_freq[ch] = ctx->start_freq[CPL_CH];
@@ -895,10 +823,10 @@ static int ac3_parse_audio_block(AC3Deco
     ctx->end_freq[ctx->lfe_ch] = 7;
 
     /* decode exponents for each channel */
-    for (ch = !ctx->cpl_in_use; ch <= ctx->channels; ch++) {
-        if (ctx->exp_strategy[ch] != EXP_REUSE) {
+    for (ch = !ctx->cpl_in_use[blk]; ch <= ctx->channels; ch++) {
+        if (ctx->exp_strategy[blk][ch] != EXP_REUSE) {
             int group_size, num_groups;
-            group_size = 3 << (ctx->exp_strategy[ch] - 1);
+            group_size = 3 << (ctx->exp_strategy[blk][ch] - 1);
             if(ch == CPL_CH)
                 num_groups = (ctx->end_freq[ch] - ctx->start_freq[ch]) / group_size;
             else if(ch == ctx->lfe_ch)
@@ -906,7 +834,7 @@ static int ac3_parse_audio_block(AC3Deco
             else
                 num_groups = (ctx->end_freq[ch] + group_size - 4) / group_size;
             ctx->dexps[ch][0] = get_bits(gbc, 4) << !ch;
-            ff_ac3_decode_exponents(gbc, ctx->exp_strategy[ch], num_groups, ctx->dexps[ch][0],
+            ff_ac3_decode_exponents(gbc, ctx->exp_strategy[blk][ch], num_groups, ctx->dexps[ch][0],
                              &ctx->dexps[ch][ctx->start_freq[ch]+!!ch]);
             if(ch != CPL_CH && ch != ctx->lfe_ch)
                 skip_bits(gbc, 2); /* skip gainrng */
@@ -920,7 +848,7 @@ static int ac3_parse_audio_block(AC3Deco
         ctx->bit_alloc_params.slow_gain  = ff_ac3_slow_gain_tab[get_bits(gbc, 2)];
         ctx->bit_alloc_params.db_per_bit = ff_ac3_db_per_bit_tab[get_bits(gbc, 2)];
         ctx->bit_alloc_params.floor  = ff_ac3_floor_tab[get_bits(gbc, 3)];
-        for(ch=!ctx->cpl_in_use; ch<=ctx->channels; ch++) {
+        for(ch=!ctx->cpl_in_use[blk]; ch<=ctx->channels; ch++) {
             bit_alloc_stages[ch] = FFMAX(bit_alloc_stages[ch], 2);
         }
     }
@@ -929,7 +857,7 @@ static int ac3_parse_audio_block(AC3Deco
     if (get_bits1(gbc)) {
         int csnr;
         csnr = (get_bits(gbc, 6) - 15) << 4;
-        for (ch = !ctx->cpl_in_use; ch <= ctx->channels; ch++) { /* snr offset and fast gain */
+        for (ch = !ctx->cpl_in_use[blk]; ch <= ctx->channels; ch++) { /* snr offset and fast gain */
             ctx->snr_offset[ch] = (csnr + get_bits(gbc, 4)) << 2;
             ctx->fast_gain[ch] = ff_ac3_fast_gain_tab[get_bits(gbc, 3)];
         }
@@ -937,7 +865,7 @@ static int ac3_parse_audio_block(AC3Deco
     }
 
     /* coupling leak information */
-    if (ctx->cpl_in_use && get_bits1(gbc)) {
+    if (ctx->cpl_in_use[blk] && get_bits1(gbc)) {
         ctx->bit_alloc_params.cpl_fast_leak = get_bits(gbc, 3);
         ctx->bit_alloc_params.cpl_slow_leak = get_bits(gbc, 3);
         bit_alloc_stages[CPL_CH] = FFMAX(bit_alloc_stages[CPL_CH], 2);
@@ -946,7 +874,7 @@ static int ac3_parse_audio_block(AC3Deco
     /* delta bit allocation information */
     if (get_bits1(gbc)) {
         /* delta bit allocation exists (strategy) */
-        for (ch = !ctx->cpl_in_use; ch <= fbw_channels; ch++) {
+        for (ch = !ctx->cpl_in_use[blk]; ch <= fbw_channels; ch++) {
             ctx->dba_mode[ch] = get_bits(gbc, 2);
             if (ctx->dba_mode[ch] == DBA_RESERVED) {
                 av_log(ctx->avctx, AV_LOG_ERROR, "delta bit allocation strategy reserved\n");
@@ -955,7 +883,7 @@ static int ac3_parse_audio_block(AC3Deco
             bit_alloc_stages[ch] = FFMAX(bit_alloc_stages[ch], 2);
         }
         /* channel delta offset, len and bit allocation */
-        for (ch = !ctx->cpl_in_use; ch <= fbw_channels; ch++) {
+        for (ch = !ctx->cpl_in_use[blk]; ch <= fbw_channels; ch++) {
             if (ctx->dba_mode[ch] == DBA_NEW) {
                 ctx->dba_nsegs[ch] = get_bits(gbc, 3);
                 for (seg = 0; seg <= ctx->dba_nsegs[ch]; seg++) {
@@ -972,7 +900,7 @@ static int ac3_parse_audio_block(AC3Deco
     }
 
     /* Bit allocation */
-    for(ch=!ctx->cpl_in_use; ch<=ctx->channels; ch++) {
+    for(ch=!ctx->cpl_in_use[blk]; ch<=ctx->channels; ch++) {
         if(bit_alloc_stages[ch] > 2) {
             /* Exponent mapping into PSD and PSD integration */
             ff_ac3_bit_alloc_calc_psd(ctx->dexps[ch],

Modified: eac3/ac3dec.h
==============================================================================
--- eac3/ac3dec.h	(original)
+++ eac3/ac3dec.h	Sun Dec 30 07:45:59 2007
@@ -29,10 +29,22 @@
 
 #include "ac3tab.h"
 #include "bitstream.h"
+#include "dsputil.h"
 #include "random.h"
 
+/* override ac3.h to include coupling channel */
+#undef AC3_MAX_CHANNELS
+#define AC3_MAX_CHANNELS 7
+
 #define CPL_CH 0
 
+#define AC3_OUTPUT_LFEON  8
+
+#define AC3_MAX_COEFS   256
+#define AC3_BLOCK_SIZE  256
+#define MAX_BLOCKS 6
+#define MAX_SPX_CODES 18
+
 void ff_ac3_window_init(float *window);
 void ff_ac3_tables_init(void);
 
@@ -54,6 +66,165 @@ extern const float ff_ac3_mix_levels[9];
 /** default stereo downmixing coefficients */
 extern const uint8_t ff_ac3_default_coeffs[8][5][2];
 
+typedef struct AC3DecodeContext {
+    AVCodecContext *avctx;  ///< Parent context
+    GetBitContext gbc;      ///< Bitstream reader
+
+///@defgroup bsi Bit Stream Information
+///@{
+    int syncword;       ///< AC3 frame sync word
+    int stream_type;    ///< Stream type (strmtyp)
+    int substreamid;    ///< Substream identification
+    int frame_size;     ///< Frame size, in bytes
+    int bit_rate;       ///< Bitrate, in bits-per-second
+    int sr_code;        ///< Sample rate code (fscod)
+    int sr_code2;       ///< Sample rate code 2 (fscod2)
+    int sample_rate;    ///< Sample rate, in Hz
+    int num_blocks;     ///< Number of audio blocks
+    int channel_mode;   ///< Channel mode (acmod)
+    int lfe_on;         ///< Low frequency effect channel on (lfeon)
+    int bitstream_id;   ///< Bit stream identification (bsid)
+///@}
+
+///@defgroup audfrm Frame Syntax Parameters
+    int snr_offset_strategy;    ///< SNR offset strategy (snroffststr)
+    int block_switch_syntax;    ///< Block switch syntax enabled (blkswe)
+    int dither_flag_syntax;     ///< Dither flag syntax enabled (dithflage)
+    int bit_allocation_syntax;  ///< Bit allocation model syntax enabled (bamode)
+    int fast_gain_syntax;       ///< Fast gain codes enabled (frmfgaincode)
+    int dba_syntax;             ///< Delta bit allocation syntax enabled (dbaflde)
+    int skip_syntax;            ///< Skip Filed syntax enabled (skipflde)
+///@}
+
+///@defgroup cpl Standard Coupling
+    int cpl_in_use[MAX_BLOCKS];                 ///< Coupling in use (cplinu)
+    int cpl_strategy_exists[MAX_BLOCKS];        ///< Coupling strategy exists (cplstre)
+    int channel_in_cpl[AC3_MAX_CHANNELS];       ///< Channel in coupling (chincpl)
+    int phase_flags_in_use;                     ///< Phase flag in use (phsflginu)
+    int phase_flags[18];                        ///< Phase flag
+    int num_cpl_subbands;                       ///< Number of coupling sub bands (ncplsubnd)
+    int num_cpl_bands;                          ///< Number of coupling bands (ncplbnd)
+    int cpl_band_struct[18];                    ///< Coupling band structure (cplbndstrc)
+    int firstchincpl;                           ///< First channel in coupling
+    int first_cpl_coords[AC3_MAX_CHANNELS];     ///< First coupling coordinates states (firstcplcos)
+    float cpl_coords[AC3_MAX_CHANNELS][18];     ///< coupling coordinates (cplco)
+///@}
+
+///@defgroup aht Adaptive Hybrid Transform
+    int channel_uses_aht[AC3_MAX_CHANNELS];     ///< Channel AHT in use (chahtinu)
+    int gaq_gain[256];                              ///< Gain adaptive quantization gain
+    float pre_mantissa[6][AC3_MAX_CHANNELS][256];   ///< Pre-IDCT mantissas
+///@}
+
+///@defgroup spx Spectral Extension
+    int channel_uses_spx[AC3_MAX_CHANNELS]; ///< Channel in spectral extension attenuation process (chinspxatten)
+    int spx_atten_code[AC3_MAX_CHANNELS];   ///< spectral extension attenuation code (spxattencod)
+    int spxinu;                             ///< spectral extension in use
+    int chinspx[AC3_MAX_CHANNELS];          ///< Channel in spectral extension
+    int spxstrtf;                           ///< Spectral extension start copy frequency code
+    int spxbegf;                            ///< Spectral extension begin frequency code
+    int spxendf;                            ///< Spectral extension end frequency code
+    int nspxbnds;                           ///< Number of structured spectral extension bands
+    int spxbndsztab[MAX_SPX_CODES];         ///< Sizes of spectral extension bands
+    int spxbndstrc[MAX_SPX_CODES];          ///< Spectral extension band structure
+    int spxcoe[AC3_MAX_CHANNELS];           ///< Spectral extension coordinates exists
+    int spxblnd[AC3_MAX_CHANNELS];          ///< Spectral extension blend
+    int firstspxcos[AC3_MAX_CHANNELS];      ///< First spectral extension coordinates states
+    float spxco[AC3_MAX_CHANNELS][18];      ///< Spectral extension coordinates
+///@}
+
+///@defgroup ecpl Enhanced Coupling
+    int ecpl_in_use;                        ///< Enhanced coupling in use
+    int ecplbegf;                           ///< Enhanced coupling begin frequency code
+    int ecplendf;                           ///< Enhanced coupling end frequency code
+    int ecpl_start_subbnd;                  ///< Enhanced coupling begin frequency
+    int ecpl_end_subbnd;                    ///< Enhanced coupling end frequency
+    int necplbnd;                           ///< Number of structured enhanced coupling bands
+    int ecplbndstrc[23];                    ///< Enhanced coupling band structure
+    int ecplangleintrp;                     ///< Enhanced coupling angle interpolation flag
+    int ecplparam1e[AC3_MAX_CHANNELS];      ///< Enhanced coupling parameters 1 exists
+    int ecplparam2e[AC3_MAX_CHANNELS];      ///< Enhanced coupling parameters 2 exists
+    int ecplamp[AC3_MAX_CHANNELS][23];      ///< Enhanced coupling amplitude scaling
+    int ecplangle[AC3_MAX_CHANNELS][23];    ///< Enhanced coupling angle
+    int ecplchaos[AC3_MAX_CHANNELS][23];    ///< Enhanced coupling chaos
+    int ecpltrans[AC3_MAX_CHANNELS];        ///< Enhanced coupling transient present
+///@}
+
+///@defgroup channel Channel
+    int fbw_channels;                           ///< Number of fbw channels
+    int channels;                               ///< Total of all channels
+    int lfe_ch;                                 ///< Index of LFE channel
+    float downmix_coeffs[AC3_MAX_CHANNELS][2];  ///< stereo downmix coefficients
+    int output_mode;                            ///< output channel configuration
+    int out_channels;                           ///< number of output channels
+///@}
+
+///@defgroup dynrng Dynamic Range
+    float dynamic_range[2]; ///< Dynamic range gain (dynrng)
+///@}
+
+///@defgroup bandwidth Bandwidth
+    int start_freq[AC3_MAX_CHANNELS];   ///< Start frequency bin (strtmant)
+    int end_freq[AC3_MAX_CHANNELS];     ///< End frequency bin (endmant)
+///@}
+
+///@defgroup rematrixing Rematrixing
+    int num_rematrixing_bands;  ///< Number of rematrixing bands (nrematbnds)
+    int rematrixing_flags[4];   ///< Rematrixing flags (rematflg)
+///@}
+
+///@defgroup exponents Exponents
+    int nchgrps[AC3_MAX_CHANNELS];                  ///< Number of fbw channel exponent groups
+    uint8_t dexps[AC3_MAX_CHANNELS][AC3_MAX_COEFS]; ///< Differential exponents
+    int exp_strategy[MAX_BLOCKS][AC3_MAX_CHANNELS]; ///< Channel exponent strategy (chexpstr)
+///@}
+
+///@defgroup bitalloc Bit Allocation
+    AC3BitAllocParameters bit_alloc_params;         ///< Bit allocation parameters
+    int first_cpl_leak;                             ///< First coupling leak state (firstcplleak)
+    int snr_offset[AC3_MAX_CHANNELS];               ///< SNR offset (snroffst)
+    int fast_gain[AC3_MAX_CHANNELS];                ///< Channel fast gain (fgain)
+    uint8_t bap[AC3_MAX_CHANNELS][AC3_MAX_COEFS];   ///< bit allocation pointers
+    uint8_t hebap[AC3_MAX_CHANNELS][AC3_MAX_COEFS]; ///< high-efficiency bit allocation pointers for AHT
+    int16_t psd[AC3_MAX_CHANNELS][AC3_MAX_COEFS];   ///< scaled exponents
+    int16_t band_psd[AC3_MAX_CHANNELS][50];         ///< interpolated exponents (bndpsd)
+    int16_t mask[AC3_MAX_CHANNELS][50];             ///< masking values
+    uint8_t dba_mode[AC3_MAX_CHANNELS];             ///< Delta bit allocation mode (deltbae)
+    uint8_t dba_nsegs[AC3_MAX_CHANNELS];            ///< Number of delta segments (deltnseg)
+    uint8_t dba_offsets[AC3_MAX_CHANNELS][9];       ///< Delta segment offsets (deltoffst)
+    uint8_t dba_lengths[AC3_MAX_CHANNELS][9];       ///< Delta segment lengths (deltlen)
+    uint8_t dba_values[AC3_MAX_CHANNELS][9];        ///< Delta values for each segment (deltba)
+///@}
+
+///@defgroup dithering Zero-Mantissa Dithering
+    int dither_all;                     ///< Indicates whether all channels use dithering
+    int dither_flag[AC3_MAX_CHANNELS];  ///< Dither flag (dithflag)
+    AVRandomState dith_state;           ///< for dither generation
+///@}
+
+///@defgroup imdct IMDCT
+    int block_switch[AC3_MAX_CHANNELS]; ///< Block switch flag (blksw)
+    MDCTContext imdct_512;              ///< for 512 sample imdct transform
+    MDCTContext imdct_256;              ///< for 256 sample imdct transform
+///@}
+
+///@defgroup opt Optimization
+    DSPContext  dsp;    ///< for optimization
+    float add_bias;     ///< offset for float_to_int16 conversion
+    float mul_bias;     ///< scaling for float_to_int16 conversion
+///@}
+
+///@defgroup arrays Aligned Arrays
+    DECLARE_ALIGNED_16(float, transform_coeffs[AC3_MAX_CHANNELS][AC3_MAX_COEFS]);   ///< Frequency Coefficients
+    DECLARE_ALIGNED_16(float, delay[AC3_MAX_CHANNELS][AC3_BLOCK_SIZE]);             ///< delay - added to the next block
+    DECLARE_ALIGNED_16(float, window[AC3_BLOCK_SIZE]);                              ///< window coefficients
+    DECLARE_ALIGNED_16(float, tmp_output[AC3_BLOCK_SIZE * 24]);                     ///< temp storage for output before windowing
+    DECLARE_ALIGNED_16(float, tmp_imdct[AC3_BLOCK_SIZE * 24]);                      ///< temp storage for imdct transform
+    DECLARE_ALIGNED_16(float, output[AC3_MAX_CHANNELS][AC3_BLOCK_SIZE]);            ///< output after imdct transform and windowing
+    DECLARE_ALIGNED_16(int16_t, int_output[AC3_MAX_CHANNELS][AC3_BLOCK_SIZE]);      ///< final 16-bit integer output
+///@}
+} AC3DecodeContext;
+
 /**
  * Decode the grouped exponents according to exponent strategy.
  * reference: Section 7.1.3 Exponent Decoding

Modified: eac3/eac3dec.c
==============================================================================
--- eac3/eac3dec.c	(original)
+++ eac3/eac3dec.c	Sun Dec 30 07:45:59 2007
@@ -20,11 +20,28 @@
  */
 
 #include "avcodec.h"
-#include "eac3.h"
-#include "ac3dec.h"
 #include "ac3.h"
+#include "ac3dec.h"
 #include "random.h"
 
+/** Channel gain adaptive quantization mode */
+typedef enum {
+    EAC3_GAQ_NO =0,
+    EAC3_GAQ_12,
+    EAC3_GAQ_14,
+    EAC3_GAQ_124
+} EAC3GaqMode;
+
+/** Stream Type */
+typedef enum {
+    EAC3_STREAM_TYPE_INDEPENDENT = 0,
+    EAC3_STREAM_TYPE_DEPENDENT,
+    EAC3_STREAM_TYPE_AC3_CONVERT,
+    EAC3_STREAM_TYPE_RESERVED
+} EAC3StreamType;
+
+#define EAC3_SR_CODE_REDUCED  3
+
 static float idct_cos_tab[6][5];
 
 static int gaq_ungroup_tab[32][3];
@@ -40,7 +57,7 @@ static void log_missing_feature(AVCodecC
 }
 
 #if 0
-static void spectral_extension(EAC3Context *s){
+static void spectral_extension(AC3DecodeContext *s){
     //Now turned off, because there are no samples for testing it.
     int copystartmant, copyendmant, copyindex, insertindex;
     int wrapflag[18];
@@ -152,7 +169,7 @@ static void spectral_extension(EAC3Conte
 }
 #endif
 
-static void get_transform_coeffs_aht_ch(EAC3Context *s, int ch){
+static void get_transform_coeffs_aht_ch(AC3DecodeContext *s, int ch){
     int bin, blk, gs;
     int hebap, end_bap, gaq_mode, bits, pre_mantissa, remap, log_gain;
     float mant;
@@ -244,7 +261,7 @@ static void get_transform_coeffs_aht_ch(
     }
 }
 
-static void idct_transform_coeffs_ch(EAC3Context *s, int ch, int blk){
+static void idct_transform_coeffs_ch(AC3DecodeContext *s, int ch, int blk){
     // TODO fast IDCT
     int bin, i;
     float tmp;
@@ -257,7 +274,7 @@ static void idct_transform_coeffs_ch(EAC
     }
 }
 
-static void get_eac3_transform_coeffs_ch(EAC3Context *s, int blk,
+static void get_eac3_transform_coeffs_ch(AC3DecodeContext *s, int blk,
         int ch, mant_groups *m){
     if (!s->channel_uses_aht[ch]) {
         ff_ac3_get_transform_coeffs_ch(m, &s->gbc, s->dexps[ch], s->bap[ch],
@@ -276,7 +293,7 @@ static void get_eac3_transform_coeffs_ch
            s->end_freq[ch] * sizeof(*s->transform_coeffs[ch]));
 }
 
-static void remove_dithering(EAC3Context *s) {
+static void remove_dithering(AC3DecodeContext *s) {
     /* TODO: merge with same function in ac3dec.c */
     int ch, i;
     int end=0;
@@ -312,7 +329,7 @@ static void remove_dithering(EAC3Context
     }
 }
 
-static int parse_bsi(EAC3Context *s){
+static int parse_bsi(AC3DecodeContext *s){
     int i, blk;
     GetBitContext *gbc = &s->gbc;
 
@@ -507,7 +524,7 @@ static int parse_bsi(EAC3Context *s){
     return 0;
 } /* end of bsi */
 
-static int parse_audfrm(EAC3Context *s){
+static int parse_audfrm(AC3DecodeContext *s){
     int blk, ch;
     int ac3_exponent_strategy, parse_aht_info, parse_spx_atten_data;
     int parse_transient_proc_info;
@@ -668,7 +685,7 @@ static int parse_audfrm(EAC3Context *s){
     return 0;
 } /* end of audfrm */
 
-static int parse_audblk(EAC3Context *s, const int blk){
+static int parse_audblk(AC3DecodeContext *s, const int blk){
     //int grp, sbnd, n, bin;
     int seg, bnd, ch, i, chbwcod, grpsize;
     int got_cplchan;
@@ -1194,7 +1211,7 @@ static int parse_audblk(EAC3Context *s, 
 /**
  * Performs Inverse MDCT transform
  */
-static void do_imdct(EAC3Context *ctx){
+static void do_imdct(AC3DecodeContext *ctx){
     int ch;
 
     for (ch = 1; ch <= ctx->fbw_channels + ctx->lfe_on; ch++) {
@@ -1220,7 +1237,7 @@ static void do_imdct(EAC3Context *ctx){
 static int eac3_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
         uint8_t *buf, int buf_size){
     int16_t *out_samples = (int16_t *)data;
-    EAC3Context *c = (EAC3Context *)avctx->priv_data;
+    AC3DecodeContext *c = (AC3DecodeContext *)avctx->priv_data;
     int k, i, blk, ch;
 
     *data_size = 0;
@@ -1327,7 +1344,7 @@ static void eac3_tables_init(void) {
 }
 
 static int eac3_decode_init(AVCodecContext *avctx){
-    EAC3Context *ctx = avctx->priv_data;
+    AC3DecodeContext *ctx = avctx->priv_data;
 
     ctx->avctx = avctx;
     ac3_common_init();
@@ -1349,7 +1366,7 @@ static int eac3_decode_init(AVCodecConte
 }
 
 static int eac3_decode_end(AVCodecContext *avctx){
-    EAC3Context *ctx = avctx->priv_data;
+    AC3DecodeContext *ctx = avctx->priv_data;
     ff_mdct_end(&ctx->imdct_512);
     ff_mdct_end(&ctx->imdct_256);
 
@@ -1360,7 +1377,7 @@ AVCodec eac3_decoder = {
     .name = "E-AC3",
     .type = CODEC_TYPE_AUDIO,
     .id = CODEC_ID_EAC3,
-    .priv_data_size = sizeof (EAC3Context),
+    .priv_data_size = sizeof (AC3DecodeContext),
     .init = eac3_decode_init,
     .close = eac3_decode_end,
     .decode = eac3_decode_frame,



More information about the FFmpeg-soc mailing list