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

bwolowiec subversion at mplayerhq.hu
Thu Aug 16 12:58:48 CEST 2007


Author: bwolowiec
Date: Thu Aug 16 12:58:48 2007
New Revision: 846

Log:
adding rematrixing, clearing the code


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

Modified: eac3/ac3dec.c
==============================================================================
--- eac3/ac3dec.c	(original)
+++ eac3/ac3dec.c	Thu Aug 16 12:58:48 2007
@@ -637,22 +637,20 @@ static int get_transform_coeffs(AC3Decod
  * Stereo rematrixing.
  * reference: Section 7.5.4 Rematrixing : Decoding Technique
  */
-static void do_rematrixing(AC3DecodeContext *ctx)
+void ff_ac3_do_rematrixing(float (*transform_coeffs)[256], int end, int nrematbnd, int *rematflg)
 {
     int bnd, i;
-    int end, bndend;
+    int bndend;
     float tmp0, tmp1;
 
-    end = FFMIN(ctx->endmant[1], ctx->endmant[2]);
-
-    for(bnd=0; bnd<ctx->nrematbnd; bnd++) {
-        if(ctx->rematflg[bnd]) {
+    for(bnd=0; bnd<nrematbnd; bnd++) {
+        if(rematflg[bnd]) {
             bndend = FFMIN(end, rematrix_band_tbl[bnd+1]);
             for(i=rematrix_band_tbl[bnd]; i<bndend; i++) {
-                tmp0 = ctx->transform_coeffs[1][i];
-                tmp1 = ctx->transform_coeffs[2][i];
-                ctx->transform_coeffs[1][i] = tmp0 + tmp1;
-                ctx->transform_coeffs[2][i] = tmp0 - tmp1;
+                tmp0 = transform_coeffs[1][i];
+                tmp1 = transform_coeffs[2][i];
+                transform_coeffs[1][i] = tmp0 + tmp1;
+                transform_coeffs[2][i] = tmp0 - tmp1;
             }
         }
     }
@@ -1034,7 +1032,9 @@ static int ac3_parse_audio_block(AC3Deco
 
     /* recover coefficients if rematrixing is in use */
     if(ctx->acmod == AC3_ACMOD_STEREO)
-        do_rematrixing(ctx);
+        ff_ac3_do_rematrixing(ctx->transform_coeffs,
+                FFMIN(ctx->endmant[1], ctx->endmant[2]),
+                ctx->nrematbnd, ctx->rematflg);
 
     /* apply scaling to coefficients (headroom, dialnorm, dynrng) */
     for(ch=1; ch<=ctx->nchans; ch++) {

Modified: eac3/ac3dec.h
==============================================================================
--- eac3/ac3dec.h	(original)
+++ eac3/ac3dec.h	Thu Aug 16 12:58:48 2007
@@ -80,5 +80,6 @@ typedef struct {
 int ff_ac3_get_transform_coeffs_ch(mant_groups *m, GetBitContext *gb, uint8_t *exps,
         uint8_t *bap, float *coeffs, int start, int end, AVRandomState *dith_state);
 
+void ff_ac3_do_rematrixing(float (*transform_coeffs)[256], int end, int nrematbnd, int *rematflg);
 
 #endif /* AC3DEC_H */

Modified: eac3/eac3.h
==============================================================================
--- eac3/eac3.h	(original)
+++ eac3/eac3.h	Thu Aug 16 12:58:48 2007
@@ -83,9 +83,8 @@ typedef struct EAC3Context{
     int acmod; // 3);                ///< Audio coding mode
     int lfeon; // 1);                ///< Low frequency effect channel on
     int bsid; // 5);                 ///< Bit stream identification
-    int dialnorm[2]; // 5);          ///< Dialogue normalization
-    int compr; // 8);                ///< Compression gain word
-    int compr2; // 8);               ///< Compression gain word ch2
+    float dialnorm[2]; // 5);        ///< Dialogue normalization
+    int compr[2]; // 8);             ///< Compression gain word
     int chanmap; // 16);             ///< Custom channel map
     int mixmdate; // 1);             ///< Mixing meta-data exists
     int dmixmod; // 2);              ///<
@@ -95,13 +94,11 @@ typedef struct EAC3Context{
     int lorosurmixlev; // 3);
     int lfemixlevcode; // 1);        ///< lfe mix level code exists
     int lfemixlevcod; // 5);         ///< lfe mix level code
-    int pgmscl; // 6);               ///< Program scale factor
-    int pgmscl2; // 6);              ///< Program scale factor #2
+    int pgmscl[2]; // 6);            ///< Program scale factor
     int extpgmscl; // 6);            ///< External program scale factor
     int mixdef; // 2);               ///< Mix control type
     int mixdeflen; // 5);            ///< Length of mixing parameter data field
-    int paninfo; // 14);             ///< Pan information
-    int paninfo2; // 14);            ///< Pan information 2
+    int paninfo[2]; // 14);          ///< Pan information
     int frmmixcfginfoe; // 1);       ///< Frame mixing configuration information exists
     int blkmixcfginfo0; // 5);
     int blkmixcfginfoe; // 1);       ///< Block mixing configuration information exists
@@ -113,14 +110,11 @@ typedef struct EAC3Context{
     int dsurmod; // 2);
     int dheadphonmod; // 2);
     int dsurexmod; // 2);
-    int audprodie; // 1);
-    int mixlevel; // 5);             ///< Mix level
-    int roomtyp; // 2);              ///< Room type
-    int adconvtyp; // 1);            ///< A/D converter type
+    int audprodie[2]; // 1);
+    int mixlevel[2]; // 5);          ///< Mix level
+    int roomtyp[2]; // 2);           ///< Room type
+    int adconvtyp[2]; // 1);         ///< A/D converter type
     int audprodi2e; // 1);           ///< Audio production information exists ch2
-    int mixlevel2; // 5);            ///< Mixing level ch2
-    int roomtyp2; // 2);             ///< room type ch2
-    int adconvtyp2; // 1);           ///< A/D converter type
     int sourcefscod; // 1);          ///< Source sample rate code
     int frmsizecod; // 6);           ///< Frame size code
     int addbsie; // 1);              ///< Additional bit stream information exists

Modified: eac3/eac3_parser.c
==============================================================================
--- eac3/eac3_parser.c	(original)
+++ eac3/eac3_parser.c	Thu Aug 16 12:58:48 2007
@@ -91,19 +91,12 @@ int ff_eac3_parse_bsi(GetBitContext *gbc
         return -1;
     }
 
-    GET_BITS(s->dialnorm[0], gbc, 5);
-    if(get_bits1(gbc)) {
-        GET_BITS(s->compr, gbc, 8);
-    }else{
-        //TODO default compr
-    }
-    if(s->acmod == 0x0) /* if 1+1 mode (dual mono, so some items need a second value) */
-    {
-        GET_BITS(s->dialnorm[1], gbc, 5);
+    for(i = 0; i < (s->acmod?1:2); i++){
+        s->dialnorm[i] = ff_ac3_dialnorm_tbl[get_bits(gbc, 5)];
         if(get_bits1(gbc)) {
-            GET_BITS(s->compr2, gbc, 8);
+            GET_BITS(s->compr[i], gbc, 8);
         }else{
-            //TODO default compr2
+            //TODO default compr
         }
     }
     if(s->strmtyp == 0x1) /* if dependent stream */
@@ -140,17 +133,11 @@ int ff_eac3_parse_bsi(GetBitContext *gbc
         }
         if(s->strmtyp == 0x0) /* if independent stream */
         {
-            if(get_bits1(gbc)) {
-                GET_BITS(s->pgmscl, gbc, 6);
-            }else{
-                //TODO program scale factor = 0dB
-            }
-            if(s->acmod == 0x0) /* if 1+1 mode (dual mono, so some items need a second value) */
-            {
+            for(i = 0; i < (s->acmod?1:2); i++){
                 if(get_bits1(gbc)) {
-                    GET_BITS(s->pgmscl2, gbc, 6);
+                    GET_BITS(s->pgmscl[i], gbc, 6);
                 }else{
-                    //TODO program scale factor 2 = 0dB
+                    //TODO program scale factor = 0dB
                 }
             }
             if(get_bits1(gbc)) {
@@ -170,13 +157,11 @@ int ff_eac3_parse_bsi(GetBitContext *gbc
             }
             if(s->acmod < 0x2) /* if mono or dual mono source */
             {
-                if(get_bits1(gbc)) {
-                    GET_BITS(s->paninfo, gbc, 14);
-                }
-                if(s->acmod == 0x0) /* if 1+1 mode (dual mono, so some items need a second value) */
-                {
+                for(i = 0; i < (s->acmod?1:2); i++){
                     if(get_bits1(gbc)) {
-                        GET_BITS(s->paninfo2, gbc, 14);
+                        GET_BITS(s->paninfo[i], gbc, 14);
+                    }else{
+                        //TODO default = center
                     }
                 }
             }
@@ -214,21 +199,13 @@ int ff_eac3_parse_bsi(GetBitContext *gbc
         if(s->acmod >= 0x6) /* if both surround channels exist */ {
             GET_BITS(s->dsurexmod, gbc, 2);
         }
-        GET_BITS(s->audprodie, gbc, 1);
-        if(s->audprodie)
-        {
-            GET_BITS(s->mixlevel, gbc, 5);
-            GET_BITS(s->roomtyp, gbc, 2);
-            GET_BITS(s->adconvtyp, gbc, 1);
-        }
-        if(s->acmod == 0x0) /* if 1+1 mode (dual mono, so some items need a second value) */
-        {
-            GET_BITS(s->audprodi2e, gbc, 1);
-            if(s->audprodi2e)
+        for(i = 0; i < (s->acmod?1:2); i++){
+            GET_BITS(s->audprodie[i], gbc, 1);
+            if(s->audprodie[i])
             {
-                GET_BITS(s->mixlevel2, gbc, 5);
-                GET_BITS(s->roomtyp2, gbc, 2);
-                GET_BITS(s->adconvtyp2, gbc, 1);
+                GET_BITS(s->mixlevel[i], gbc, 5);
+                GET_BITS(s->roomtyp[i], gbc, 2);
+                GET_BITS(s->adconvtyp[i], gbc, 1);
             }
         }
         if(s->fscod < 0x3) /* if not half sample rate */ {
@@ -324,13 +301,7 @@ int ff_eac3_parse_audfrm(GetBitContext *
     {
         int frmchexpstr;
         /* cplexpstr[blk] and chexpstr[blk][ch] derived from table lookups. see Table E2.14 */
-        if( (s->acmod > 0x1) && (s->ncplblks > 0) ) {
-            GET_BITS(frmchexpstr, gbc, 5);
-            for(blk=0; blk<6; blk++){
-                s->chexpstr[blk][CPL_CH] = ff_eac3_frm_expstr[frmchexpstr][blk];
-            }
-        }
-        for(ch = 1; ch <= s->nfchans; ch++) {
+        for(ch = !((s->acmod > 0x1) && (s->ncplblks > 0)); ch <= s->nfchans; ch++) {
             GET_BITS(frmchexpstr, gbc, 5);
             for(blk=0; blk<6; blk++){
                 s->chexpstr[blk][ch] = ff_eac3_frm_expstr[frmchexpstr][blk];
@@ -576,8 +547,6 @@ int ff_eac3_parse_audblk(GetBitContext *
             }
             GET_BITS(s->spxbndstrce, gbc, 1);
 
-            assert(blk || s->spxbndstrce); // TODO default values..
-
             if(s->spxbndstrce)
             {
                 for(bnd = s->spxbegf+1; bnd < s->spxendf; bnd++) {
@@ -929,6 +898,7 @@ int ff_eac3_parse_audblk(GetBitContext *
         if(s->chexpstr[blk][ch] != EXP_REUSE)
         {
             grpsize = 3 << (s->chexpstr[blk][ch] - 1);
+            s->strtmant[ch] = 0;
             if(s->chincpl[ch]){
                 s->endmant[ch] = s->strtmant[CPL_CH]; /* channel is coupled */
             }else if(s->chinspx[ch]){
@@ -1136,7 +1106,6 @@ int ff_eac3_parse_audblk(GetBitContext *
 
     /* run bit allocation */
     for(ch = !s->cplinu[blk]; ch<=s->nfchans+s->lfeon; ch++) {
-
         int start=0, end=0;
         start = s->strtmant[ch];
         end = s->endmant[ch];
@@ -1144,31 +1113,24 @@ int ff_eac3_parse_audblk(GetBitContext *
         ff_ac3_bit_alloc_calc_psd((int8_t *)s->dexps[ch], start, end,
                 s->psd[ch], s->bndpsd[ch]);
 
-
         s->bit_alloc_params.fscod = s->fscod;
         s->bit_alloc_params.halfratecod = 0;
 
-        {
-            ff_ac3_bit_alloc_calc_mask(&s->bit_alloc_params,
-                    s->bndpsd[ch], start, end, s->fgain[ch],
-                    (ch == s->lfe_channel),
-                    s->deltbae[ch], s->deltnseg[ch],
-                    s->deltoffst[ch], s->deltlen[ch],
-                    s->deltba[ch], s->mask[ch]);
-        }
-
-        {
-            if(s->chahtinu[ch]==0)
-                ff_ac3_bit_alloc_calc_bap(s->mask[ch], s->psd[ch], start, end,
-                        s->snroffst[ch], s->bit_alloc_params.floor, ff_ac3_baptab,
-                        s->bap[ch]);
-            else if(s->chahtinu[ch]==1)
-                ff_ac3_bit_alloc_calc_bap(s->mask[ch], s->psd[ch], start, end,
-                        s->snroffst[ch], s->bit_alloc_params.floor, ff_ac3_hebaptab,
-                        s->hebap[ch]);
-        }
-
+        ff_ac3_bit_alloc_calc_mask(&s->bit_alloc_params,
+                s->bndpsd[ch], start, end, s->fgain[ch],
+                (ch == s->lfe_channel),
+                s->deltbae[ch], s->deltnseg[ch],
+                s->deltoffst[ch], s->deltlen[ch],
+                s->deltba[ch], s->mask[ch]);
 
+        if(s->chahtinu[ch]==0)
+            ff_ac3_bit_alloc_calc_bap(s->mask[ch], s->psd[ch], start, end,
+                    s->snroffst[ch], s->bit_alloc_params.floor, ff_ac3_baptab,
+                    s->bap[ch]);
+        else if(s->chahtinu[ch]==1)
+            ff_ac3_bit_alloc_calc_bap(s->mask[ch], s->psd[ch], start, end,
+                    s->snroffst[ch], s->bit_alloc_params.floor, ff_ac3_hebaptab,
+                    s->hebap[ch]);
     }
 
 

Modified: eac3/eac3dec.c
==============================================================================
--- eac3/eac3dec.c	(original)
+++ eac3/eac3dec.c	Thu Aug 16 12:58:48 2007
@@ -138,16 +138,21 @@ static int eac3_decode_frame(AVCodecCont
 #ifdef DEBUG
     av_log(NULL, AV_LOG_INFO, "-------END BLK-------\n");
 #endif
-        //TODO rematrixing
+
+    /* recover coefficients if rematrixing is in use */
+    if(c->acmod == AC3_ACMOD_STEREO)
+        ff_ac3_do_rematrixing(c->transform_coeffs,
+                FFMIN(c->endmant[1], c->endmant[2]),
+                c->nrematbnds, c->rematflg);
         //TODO downmix_scaling...
 
         /* apply scaling to coefficients (dialnorm, dynrng) */
         for(ch=1; ch<=c->nfchans + c->lfeon; ch++) {
             float gain=2.0f;
             if(c->acmod == AC3_ACMOD_DUALMONO) {
-                gain *= ff_ac3_dialnorm_tbl[c->dialnorm[ch-1]] * ff_ac3_dynrng_tbl[c->dynrng[ch-1]];
+                gain *= c->dialnorm[ch-1] * ff_ac3_dynrng_tbl[c->dynrng[ch-1]];
             } else {
-                gain *= ff_ac3_dialnorm_tbl[c->dialnorm[0]] * ff_ac3_dynrng_tbl[c->dynrng[0]];
+                gain *= c->dialnorm[0] * ff_ac3_dynrng_tbl[c->dynrng[0]];
             }
             for(i=0; i<c->endmant[ch]; i++) {
                 c->transform_coeffs[ch][i] *= gain;



More information about the FFmpeg-soc mailing list