[FFmpeg-soc] [soc]: r3013 - in eac3: TODO eac3dec.c

jbr subversion at mplayerhq.hu
Tue Aug 5 01:33:02 CEST 2008


Author: jbr
Date: Tue Aug  5 01:33:02 2008
New Revision: 3013

Log:
Remove untested code for spectral extension and enhanced coupling. It can be
resurrected later if we ever get samples to test with.

Modified:
   eac3/TODO
   eac3/eac3dec.c

Modified: eac3/TODO
==============================================================================
--- eac3/TODO	(original)
+++ eac3/TODO	Tue Aug  5 01:33:02 2008
@@ -32,3 +32,6 @@ Features:
 Cosmetic:
 * Add more useful comments and remove bad comments
 * Add specification references
+
+NOTE: Untested code for spectral extension and enhanced coupling can be
+found in GSoC SVN revisions before r3012.

Modified: eac3/eac3dec.c
==============================================================================
--- eac3/eac3dec.c	(original)
+++ eac3/eac3dec.c	Tue Aug  5 01:33:02 2008
@@ -39,13 +39,6 @@ static int idct_cos_tab[6][5];
 
 static int gaq_ungroup_tab[32][3];
 
-#if TEST_SPX
-/**
- * Table E3.14 Spectral Extension Attenuation Table
- */
-static float spx_attenuation_tab[32][3];
-#endif
-
 void ff_eac3_log_missing_feature(AVCodecContext *avctx, const char *log){
     av_log(avctx, AV_LOG_ERROR, "%s is not implemented. If you want to help, "
             "update your FFmpeg version to the newest one from SVN. If the "
@@ -56,119 +49,6 @@ void ff_eac3_log_missing_feature(AVCodec
             "mailing list.\n", log);
 }
 
-#if 0
-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];
-    int bandsize, bnd, bin, spxmant, filtbin, ch;
-    float nratio, accum, nscale, sscale, spxcotemp;
-    float noffset[AC3_MAX_CHANNELS], nblendfact[AC3_MAX_CHANNELS][18], sblendfact[AC3_MAX_CHANNELS][18];
-    float rmsenergy[AC3_MAX_CHANNELS][18];
-
-    //XXX spxbandtable[bnd] = 25 + 12 * bnd ?
-
-    copystartmant = spxbandtable[s->spxstrtf];
-    copyendmant = spxbandtable[s->spxbegf];
-
-    for (ch = 1; ch <= s->fbw_channels; ch++) {
-        if (!s->chinspx[ch])
-            continue;
-
-        copyindex = copystartmant;
-        insertindex = copyendmant;
-
-        for (bnd = 0; bnd < s->nspxbnds; bnd++){
-            bandsize = s->spxbndsztab[bnd];
-            if ((copyindex + bandsize) > copyendmant) {
-                copyindex = copystartmant;
-                wrapflag[bnd] = 1;
-            } else
-                wrapflag[bnd] = 0;
-            for (bin = 0; bin < bandsize; bin++){
-                if (copyindex == copyendmant)
-                    copyindex = copystartmant;
-                s->transform_coeffs[ch][insertindex++] = s->transform_coeffs[ch][copyindex++];
-            }
-        }
-
-        noffset[ch] = s->spxblnd[ch] / 32.0;
-        spxmant = spxbandtable[s->spxbegf];
-        if (s->spxcoe[ch]) {
-            for (bnd = 0; bnd < s->nspxbnds; bnd++){
-                bandsize = s->spxbndsztab[bnd];
-                nratio = ((spxmant + 0.5*bandsize) / spxbandtable[s->spxendf]) - noffset[ch];
-                nratio = FFMAX(FFMIN(nratio, 1.0), 0.0);
-                nblendfact[ch][bnd] = sqrt(nratio);
-                sblendfact[ch][bnd] = sqrt(1 - nratio);
-                spxmant += bandsize;
-            }
-        }
-
-        spxmant = spxbandtable[s->spxbegf];
-        for (bnd = 0; bnd < s->nspxbnds; bnd++){
-            bandsize = s->spxbndsztab[bnd];
-            accum = 0;
-            for (bin = 0; bin < bandsize; bin++){
-                accum += (s->transform_coeffs[ch][spxmant] * s->transform_coeffs[ch][spxmant]);
-                spxmant++;
-            }
-            rmsenergy[ch][bnd] = sqrt(accum / bandsize);
-        }
-
-        if (s->channel_uses_spx[ch]) {
-            /* apply notch filter at baseband / extension region border */
-            filtbin = spxbandtable[s->spxbegf] - 2;
-            for (bin = 0; bin < 3; bin++){
-                s->transform_coeffs[ch][filtbin] *= ff_eac3_spxattentab[s->spx_atten_code[ch]][bin];
-                filtbin++;
-            }
-            for (bin = 1; bin >= 0; bin--){
-                s->transform_coeffs[ch][filtbin] *= ff_eac3_spxattentab[s->spx_atten_code[ch]][bin];
-                filtbin++;
-            }
-            filtbin += s->spxbndsztab[0];
-            /* apply notch at all other wrap points */
-            for (bnd = 1; bnd < s->nspxbnds; bnd++){
-                if (wrapflag[bnd]) {
-                    filtbin -= 5;
-                    for (bin = 0; bin < 3; bin++){
-                        s->transform_coeffs[ch][filtbin] *= ff_eac3_spxattentab[s->spx_atten_code[ch]][bin];
-                        filtbin++;
-                    }
-                    for (bin = 1; bin >= 0; bin--){
-                        s->transform_coeffs[ch][filtbin] *= ff_eac3_spxattentab[s->spx_atten_code[ch]][bin];
-                        filtbin++;
-                    }
-                }
-                filtbin += s->spxbndsztab[bnd];
-            }
-        }
-
-        spxmant = spxbandtable[s->spxbegf];
-        for (bnd = 0; bnd < s->nspxbnds; bnd++){
-            nscale = rmsenergy[ch][bnd] * nblendfact[ch][bnd];
-            sscale = sblendfact[ch][bnd];
-            for (bin = 0; bin < s->spxbndsztab[bnd]; bin++){
-                //TODO generate noise()
-                s->transform_coeffs[ch][spxmant] =
-                    s->transform_coeffs[ch][spxmant] * sscale + noise() * nscale;
-                spxmant++;
-            }
-        }
-
-        spxmant = spxbandtable[s->spxbegf];
-        for (bnd = 0; bnd < s->nspxbnds; bnd++){
-            spxcotemp = s->spxco[ch][bnd];
-            for (bin = 0; bin < s->spxbndsztab[bnd]; bin++){
-                s->transform_coeffs[ch][spxmant] *= spxcotemp * 32;
-                spxmant++;
-            }
-        }
-    }
-}
-#endif
-
 void ff_eac3_get_transform_coeffs_aht_ch(AC3DecodeContext *s, int ch){
     int bin, blk, gs;
     int end_bap, gaq_mode;
@@ -579,21 +459,6 @@ static int parse_audfrm(AC3DecodeContext
         }
     }
 
-#if TEST_SPX
-    /* Spectral extension attenuation data */
-    if (parse_spx_atten_data) {
-        for (ch = 1; ch <= s->fbw_channels; ch++) {
-            s->channel_uses_spx[ch] = get_bits1(gbc);
-            if (s->channel_uses_spx[ch]) {
-                s->spx_atten_code[ch] = get_bits(gbc, 5);
-            }
-        }
-    } else {
-        for (ch = 1; ch <= s->fbw_channels; ch++)
-            s->channel_uses_spx[ch]=0;
-    }
-#endif
-
     /* Block start information */
     if (s->num_blocks > 1 && get_bits1(gbc)) {
         /* reference: Section E2.3.2.27
@@ -606,9 +471,6 @@ static int parse_audfrm(AC3DecodeContext
 
     /* Syntax state initialization */
     for (ch = 1; ch <= s->fbw_channels; ch++) {
-#if TEST_SPX
-        s->firstspxcos[ch] = 1;
-#endif
         s->first_cpl_coords[ch] = 1;
     }
     s->first_cpl_leak = 1;
@@ -624,597 +486,6 @@ int ff_eac3_parse_header(AC3DecodeContex
     return err;
 }
 
-#if 0
-int ff_eac3_parse_audio_block(AC3DecodeContext *s, const int blk){
-    //int grp, sbnd, n, bin;
-    int seg, bnd, ch, i, chbwcod, grpsize;
-    int got_cplchan;
-    int ecpl_in_use=0;
-    GetBitContext *gbc = &s->gbc;
-    uint8_t bit_alloc_stages[AC3_MAX_CHANNELS];
-
-    memset(bit_alloc_stages, 0, AC3_MAX_CHANNELS);
-
-    /* Block switch and dither flags */
-    if (!s->eac3 || s->block_switch_syntax) {
-        for (ch = 1; ch <= s->fbw_channels; ch++) {
-            s->block_switch[ch] = get_bits1(gbc);
-        }
-    }
-    if (!s->eac3 || s->dither_flag_syntax) {
-        s->dither_all = 1;
-        for (ch = 1; ch <= s->fbw_channels; ch++) {
-            s->dither_flag[ch] = get_bits1(gbc);
-            if(!s->dither_flag[ch])
-                s->dither_all = 0;
-        }
-    }
-
-    /* Dynamic range control */
-    for (i = 0; i < (s->channel_mode ? 1 : 2); i++) {
-        if (get_bits1(gbc)) {
-            s->dynamic_range[i] = ff_ac3_dynamic_range_tab[get_bits(gbc, 8)];
-        } else if (!blk) {
-            s->dynamic_range[i] = 1.0f;
-        }
-    }
-    /* Spectral extension strategy information */
-    if (s->eac3 && (!blk || get_bits1(gbc))) {
-        s->spx_in_use = get_bits1(gbc);
-        if (s->spx_in_use) {
-#if TEST_SPX
-            if (s->channel_mode == AC3_CHMODE_MONO) {
-                s->chinspx[1] = 1;
-            } else {
-                for (ch = 1; ch <= s->fbw_channels; ch++) {
-                    s->chinspx[ch] = get_bits1(gbc);
-                }
-            }
-#if 0
-            {
-                int nspx=0;
-                for (ch = 1; ch <= s->fbw_channels; ch++) {
-                    nspx+=s->chinspx[ch];
-                }
-                if (!nspx)
-                    av_log(s->avctx, AV_LOG_INFO, "No channels in spectral extension\n");
-            }
-#endif
-            s->spxstrtf = get_bits(gbc, 2);
-            s->spxbegf = get_bits(gbc, 3);
-            s->spxendf = get_bits(gbc, 3);
-            if (s->spxbegf < 6) {
-                s->spxbegf += 2;
-            } else {
-                s->spxbegf = s->spxbegf * 2 - 3;
-            }
-            if (s->spxendf < 3) {
-                s->spxendf += 5;
-            } else {
-                s->spxendf = s->spxendf * 2 + 3;
-            }
-            for (ch = 1; ch <= s->fbw_channels; ch++) {
-                if (s->chinspx[ch])
-                    s->end_freq[ch] = 25 + 12 * s->spxbegf;
-            }
-            if (get_bits1(gbc)) {
-                for (bnd = s->spxbegf + 1; bnd < s->spxendf; bnd++) {
-                    s->spxbndstrc[bnd] = get_bits1(gbc);
-                }
-            } else if (!blk) {
-                for (bnd = 0; bnd < 17; bnd++)
-                    s->spxbndstrc[bnd] = ff_eac3_defspxbndstrc[bnd];
-            }
-            // calculate number of spectral extension bands
-            s->nspxbnds = 1;
-            s->spxbndsztab[0] = 12;
-            for (bnd = s->spxbegf+1; bnd < s->spxendf; bnd ++){
-                if (!s->spxbndstrc[bnd]) {
-                    s->spxbndsztab[s->nspxbnds] = 12;
-                    s->nspxbnds++;
-                } else {
-                    s->spxbndsztab[s->nspxbnds - 1] += 12;
-                }
-            }
-#else
-            ff_eac3_log_missing_feature(s->avctx, "Spectral extension");
-            return -1;
-#endif
-#if TEST_SPX
-        } else {
-            /* !spx_in_use */
-            for (ch = 1; ch <= s->fbw_channels; ch++) {
-                s->chinspx[ch] = 0;
-                s->firstspxcos[ch] = 1;
-            }
-#endif
-        }
-    }
-
-#if TEST_SPX
-    /* Spectral extension coordinates */
-    if (s->spx_in_use) {
-        for (ch = 1; ch <= s->fbw_channels; ch++) {
-            if (s->chinspx[ch]) {
-                if (s->firstspxcos[ch]) {
-                    s->spxcoe[ch] = 1;
-                    s->firstspxcos[ch] = 0;
-                } else {
-                    /* !firstspxcos[ch] */
-                    s->spxcoe[ch] = get_bits1(gbc);
-                }
-                if (!blk && !s->spxcoe[ch]) {
-                    av_log(s->avctx, AV_LOG_ERROR, "no spectral extension coordinates in first block\n");
-                    return -1;
-                }
-
-                if (s->spxcoe[ch]) {
-                    int spxcoexp, spxcomant, mstrspxco;
-                    s->spxblnd[ch] = get_bits(gbc, 5);
-                    mstrspxco = get_bits(gbc, 2);
-                    mstrspxco*=3;
-                    /* nspxbnds determined from spxbegf, spxendf, and spxbndstrc[ ] */
-                    for (bnd = 0; bnd < s->nspxbnds; bnd++) {
-                        spxcoexp = get_bits(gbc, 4);
-                        spxcomant = get_bits(gbc, 2);
-                        if (spxcoexp == 15)
-                            s->spxco[ch][bnd] = spxcomant / 4.0f;
-                        else
-                            s->spxco[ch][bnd] = (spxcomant+4) / 8.0f;
-                        s->spxco[ch][bnd] *= ff_ac3_scale_factors[spxcoexp + mstrspxco];
-                    }
-                }
-            } else {
-                /* !chinspx[ch] */
-                s->firstspxcos[ch] = 1;
-            }
-        }
-    }
-#endif
-
-    /* Coupling strategy and enhanced coupling strategy information */
-    if ((s->eac3 && s->cpl_strategy_exists[blk]) || (!s->eac3 && get_bits1(gbc))) {
-        memset(bit_alloc_stages, 3, AC3_MAX_CHANNELS);
-        if (!s->eac3)
-            s->cpl_in_use[blk] = get_bits1(gbc);
-        if (s->cpl_in_use[blk]) {
-            if (s->eac3)
-                ecpl_in_use = get_bits1(gbc);
-            else
-                ecpl_in_use = 0;
-            if (s->eac3 && s->channel_mode == AC3_CHMODE_STEREO) {
-                s->channel_in_cpl[1] = 1;
-                s->channel_in_cpl[2] = 1;
-            } else {
-                for (ch = 1; ch <= s->fbw_channels; ch++) {
-                    s->channel_in_cpl[ch] = get_bits1(gbc);
-                }
-            }
-            if (!ecpl_in_use) {
-                /* standard coupling in use */
-                int cpl_begin, cpl_end;
-
-                /* determine if phase flags are used */
-                if (s->channel_mode == AC3_CHMODE_STEREO) {
-                    s->phase_flags_in_use = get_bits1(gbc);
-                }
-
-                /* get start and end subbands for coupling */
-                cpl_begin = get_bits(gbc, 4);
-#if TEST_SPX
-                if (!s->eac3 || !s->spx_in_use) {
-                    cpl_end = get_bits(gbc, 4) + 3;
-                } else {
-                    cpl_end = s->spxbegf - 1;
-                }
-#else
-                cpl_end = get_bits(gbc, 4) + 3;
-#endif
-                s->num_cpl_subbands =  cpl_end - cpl_begin;
-
-                /* calculate start and end frequency bins for coupling */
-                s->start_freq[CPL_CH] = 37 + (12 * cpl_begin);
-                s->end_freq[CPL_CH] = 37 + (12 * cpl_end);
-                if (s->start_freq[CPL_CH] > s->end_freq[CPL_CH]) {
-                    av_log(s->avctx, AV_LOG_ERROR, "cplstrtmant > cplendmant [blk=%i]\n", blk);
-                    return -1;
-                }
-                for (ch = 1; ch <= s->fbw_channels; ch++) {
-                    if (s->channel_in_cpl[ch])
-                        s->end_freq[ch] = s->start_freq[CPL_CH];
-                }
-
-                /* read coupling band structure or use default */
-                if (!s->eac3 || get_bits1(gbc)) {
-                    for (bnd = 0; bnd < s->num_cpl_subbands-1; bnd++) {
-                        s->cpl_band_struct[bnd] = get_bits1(gbc);
-                    }
-                } else if (!blk) {
-                    for (bnd = 0; bnd < s->num_cpl_subbands-1; bnd++)
-                        s->cpl_band_struct[bnd] = ff_eac3_default_cpl_band_struct[bnd+cpl_begin+1];
-                }
-                s->cpl_band_struct[s->num_cpl_subbands-1] = 0;
-
-                /* calculate number of coupling bands based on band structure */
-                s->num_cpl_bands = s->num_cpl_subbands;
-                for (bnd = 0; bnd < s->num_cpl_subbands-1; bnd++) {
-                    s->num_cpl_bands -= s->cpl_band_struct[bnd];
-                }
-            } else {
-                /* enhanced coupling in use */
-#if TEST_ECPL
-                int sbnd;
-                s->ecplbegf = get_bits(gbc, 4);
-                if (s->ecplbegf < 3) {
-                    s->ecpl_start_subbnd = s->ecplbegf * 2;
-                } else {
-                    if (s->ecplbegf < 13) {
-                        s->ecpl_start_subbnd = s->ecplbegf + 2;
-                    } else {
-                        s->ecpl_start_subbnd = s->ecplbegf * 2 - 10;
-                    }
-                }
-                if (!s->spx_in_use) {
-                    /* if SPX not in use */
-                    s->ecplendf = get_bits(gbc, 4);
-                    s->ecpl_end_subbnd = s->ecplendf + 7;
-                } else {
-                    /* SPX in use */
-                    if (s->spxbegf < 6) {
-                        s->ecpl_end_subbnd = s->spxbegf + 5;
-                    } else {
-                        s->ecpl_end_subbnd = s->spxbegf * 2;
-                    }
-                }
-                if (get_bits1(gbc)) {
-                    for (sbnd = FFMAX(9, s->ecpl_start_subbnd + 1);
-                            sbnd < s->ecpl_end_subbnd; sbnd++){
-                        s->ecplbndstrc[sbnd] = get_bits1(gbc);
-                    }
-                } else if (!blk) {
-                    for (sbnd = 0; sbnd < 22; sbnd++)
-                        s->ecplbndstrc[sbnd] = ff_eac3_defecplbndstrc[sbnd];
-                }
-                //necplbnd = ecpl_end_subbnd - ecpl_start_subbnd;
-                //necplbnd -= ecplbndstrc[ecpl_start_subbnd] + ... + ecplbndstrc[ecpl_end_subbnd -1]
-                s->necplbnd = s->ecpl_end_subbnd - s->ecpl_start_subbnd;
-                for (bnd = s->ecpl_start_subbnd; bnd < s->ecpl_end_subbnd; bnd++) {
-                    s->necplbnd -= s->ecplbndstrc[bnd];
-                }
-#else
-                ff_eac3_log_missing_feature(s->avctx, "Enhanced coupling");
-                return -1;
-#endif
-            }
-        } else {
-            /* coupling not used for this block */
-            for (ch = 1; ch <= s->fbw_channels; ch++) {
-                s->channel_in_cpl[ch] = 0;
-                s->first_cpl_coords[ch] = 1;
-            }
-            s->first_cpl_leak = 1;
-            s->phase_flags_in_use = 0;
-            ecpl_in_use = 0;
-        }
-    } else if (!s->eac3 && blk) {
-        /* for AC3, copy coupling use strategy from last block */
-        s->cpl_in_use[blk] = s->cpl_in_use[blk-1];
-    }
-    /* Coupling coordinates */
-    if (s->cpl_in_use[blk]) {
-        if (!ecpl_in_use) {
-            /* standard coupling in use */
-            int cpl_coords_exist = 0;
-            for (ch = 1; ch <= s->fbw_channels; ch++) {
-                if (s->channel_in_cpl[ch]) {
-                    int cpl_coords_ch = 0;
-
-                    /* determine if coupling coordinates are new or reused */
-                    if (s->eac3 && s->first_cpl_coords[ch]) {
-                        cpl_coords_ch = 1;
-                        s->first_cpl_coords[ch] = 0;
-                    } else {
-                        cpl_coords_ch = get_bits1(gbc);
-                    }
-                    cpl_coords_exist |= cpl_coords_ch;
-
-                    if (cpl_coords_ch) {
-                        /* read coupling coordinates from bitstream */
-                        int cpl_exp, cpl_mant, cpl_master;
-                        cpl_master = 3 * get_bits(gbc, 2);
-                        for (bnd = 0; bnd < s->num_cpl_bands; bnd++) {
-                            cpl_exp = get_bits(gbc, 4);
-                            cpl_mant = get_bits(gbc, 4);
-                            if (cpl_exp == 15)
-                                s->cpl_coords[ch][bnd] = cpl_mant / 16.0f;
-                            else
-                                s->cpl_coords[ch][bnd] = (cpl_mant + 16.0f) / 32.0f;
-                            s->cpl_coords[ch][bnd] *= ff_ac3_scale_factors[cpl_exp + cpl_master];
-                        }
-                    } else if (!blk) {
-                        av_log(s->avctx, AV_LOG_ERROR,  "no coupling coordinates in first block\n");
-                        return -1;
-                    }
-                } else {
-                    /* channel not in coupling */
-                    s->first_cpl_coords[ch] = 1;
-                }
-            }
-            if (s->channel_mode == AC3_CHMODE_STEREO && cpl_coords_exist) {
-                for (bnd = 0; bnd < s->num_cpl_bands; bnd++) {
-                    s->phase_flags[bnd] = s->phase_flags_in_use? get_bits1(gbc) : 0;
-                }
-            }
-        } else {
-            /* enhanced coupling in use */
-            //TODO calc nchgrps[CPL_CH]
-#if TEST_ECPL
-            s->firstchincpl = -1;
-            s->ecplangleintrp = get_bits1(gbc);
-            for (ch = 1; ch <= s->fbw_channels; ch++) {
-                if (s->channel_in_cpl[ch]) {
-                    if (s->firstchincpl == -1) {
-                        s->firstchincpl = ch;
-                    }
-                    if (s->first_cpl_coords[ch]) {
-                        s->ecplparam1e[ch] = 1;
-                        if (ch > s->firstchincpl) {
-                            s->ecplparam2e[ch] = 1;
-                        } else {
-                            s->ecplparam2e[ch] = 0;
-                        }
-                        s->first_cpl_coords[ch] = 0;
-                    } else {
-                        s->ecplparam1e[ch] = get_bits1(gbc);
-                        if (ch > s->firstchincpl) {
-                            s->ecplparam2e[ch] = get_bits1(gbc);
-                        } else {
-                            s->ecplparam2e[ch] = 0;
-                        }
-                    }
-                    if (s->ecplparam1e[ch]) {
-                        /* necplbnd derived from ecpl_start_subbnd, ecpl_end_subbnd, and ecplbndstrc */
-                        for (bnd = 0; bnd < s->necplbnd; bnd++) {
-                            s->ecplamp[ch][bnd] = get_bits(gbc, 5);
-                        }
-                    }
-                    if (s->ecplparam2e[ch]) {
-                        /* necplbnd derived from ecpl_start_subbnd, ecpl_end_subbnd, and ecplbndstrc */
-                        for (bnd = 0; bnd < s->necplbnd; bnd++) {
-                            s->ecplangle[ch][bnd] = get_bits(gbc, 6);
-                            s->ecplchaos[ch][bnd] = get_bits(gbc, 3);
-                        }
-                    }
-                    if (ch > s->firstchincpl) {
-                        s->ecpltrans[ch] = get_bits1(gbc);
-                    }
-                } else {
-                    /* !chincpl[ch] */
-                    s->first_cpl_coords[ch] = 1;
-                }
-            } /* ch */
-#endif
-        }
-    }
-    /* Rematrixing operation in the 2/0 mode */
-    if (s->channel_mode == AC3_CHMODE_STEREO && ((s->eac3 && !blk) || get_bits1(gbc))) {
-        /* nrematbnds determined from cplinu, ecplinu, spx_in_use, cplbegf, ecplbegf and spxbegf */
-        // TODO spx in one channel
-        int end = (s->cpl_in_use[blk] || (s->eac3 && s->spx_in_use)) ?
-            FFMIN(s->end_freq[1], s->end_freq[2]) : (ff_ac3_rematrix_band_tab[4]-1);
-        for (bnd = 0; ff_ac3_rematrix_band_tab[bnd] <= end; bnd++) {
-            s->rematrixing_flags[bnd] = get_bits1(gbc);
-        }
-        s->num_rematrixing_bands = bnd;
-    }
-
-    /* AC-3 exponent strategy */
-    if(!s->eac3) {
-        s->exp_strategy[blk][CPL_CH] = EXP_REUSE;
-        s->exp_strategy[blk][s->lfe_ch] = EXP_REUSE;
-        for (ch = !s->cpl_in_use[blk]; ch <= s->channels; ch++) {
-            if(ch == s->lfe_ch)
-                s->exp_strategy[blk][ch] = get_bits(gbc, 1);
-            else
-                s->exp_strategy[blk][ch] = get_bits(gbc, 2);
-        }
-    }
-    s->num_exp_groups[CPL_CH] = (s->end_freq[CPL_CH] - s->start_freq[CPL_CH]) /
-                         (3 << (s->exp_strategy[blk][CPL_CH] - 1));
-
-    /* check exponent strategies to set bit allocation stages */
-    for (ch = !s->cpl_in_use[blk]; ch <= s->channels; ch++) {
-        if(s->exp_strategy[blk][ch] != EXP_REUSE)
-            bit_alloc_stages[ch] = 3;
-    }
-
-    /* Channel bandwidth code */
-    for (ch = 1; ch <= s->fbw_channels; ch++) {
-        if (!blk && s->exp_strategy[blk][ch] == EXP_REUSE) {
-            av_log(s->avctx, AV_LOG_ERROR,  "no channel exponent strategy in first block\n");
-            return -1;
-        }
-        if (s->exp_strategy[blk][ch] != EXP_REUSE) {
-            s->start_freq[ch] = 0;
-#if TEST_SPX
-            if ((!s->channel_in_cpl[ch]) && (!s->eac3 || !s->chinspx[ch])) {
-#else
-            if (!s->channel_in_cpl[ch]) {
-#endif
-                int prev = s->end_freq[ch];
-                chbwcod = get_bits(gbc, 6);
-                if (chbwcod > 60) {
-                    av_log(s->avctx, AV_LOG_ERROR, "chbwcod > 60\n");
-                    return -1;
-                }
-                s->end_freq[ch] = ((chbwcod + 12) * 3) + 37; /* (ch is not coupled) */
-                /* if bandwidth changes, run full bit allocation */
-                if(blk && s->end_freq[ch] != prev) {
-                    bit_alloc_stages[ch] = 3;
-                }
-            }
-            grpsize = 3 << (s->exp_strategy[blk][ch] - 1);
-            s->num_exp_groups[ch] = (s->end_freq[ch] + grpsize - 4) / grpsize;
-        }
-    }
-    /* Exponents */
-    for (ch = !s->cpl_in_use[blk]; ch <= s->channels; ch++) {
-        if (s->exp_strategy[blk][ch] != EXP_REUSE) {
-            s->dexps[ch][0] = get_bits(gbc, 4) << !ch;
-            ff_ac3_decode_exponents(gbc, s->exp_strategy[blk][ch], s->num_exp_groups[ch],
-                    s->dexps[ch][0], s->dexps[ch]+s->start_freq[ch]+!!ch);
-            if (ch != CPL_CH && ch != s->lfe_ch)
-                skip_bits(gbc, 2); /* skip gainrng */
-        }
-    }
-
-    /* Bit-allocation parametric information */
-    if (!s->eac3 || s->bit_allocation_syntax) {
-        if (get_bits1(gbc)) {
-            s->bit_alloc_params.slow_decay = ff_ac3_slow_decay_tab[get_bits(gbc, 2)];   /* Table 7.6 */
-            s->bit_alloc_params.fast_decay = ff_ac3_fast_decay_tab[get_bits(gbc, 2)];   /* Table 7.7 */
-            s->bit_alloc_params.slow_gain  = ff_ac3_slow_gain_tab [get_bits(gbc, 2)];   /* Table 7.8 */
-            s->bit_alloc_params.db_per_bit = ff_ac3_db_per_bit_tab[get_bits(gbc, 2)];   /* Table 7.9 */
-            s->bit_alloc_params.floor      = ff_ac3_floor_tab     [get_bits(gbc, 3)];   /* Table 7.10 */
-            /* run at least last 2 stages of bit allocation */
-            for(ch=!s->cpl_in_use[blk]; ch<=s->channels; ch++) {
-                bit_alloc_stages[ch] = FFMAX(bit_alloc_stages[ch], 2);
-            }
-        } else if (!blk) {
-            av_log(s->avctx, AV_LOG_ERROR, "no bit allocation information in first block\n");
-            return -1;
-        }
-    }
-
-    if ((!s->eac3 || (s->snr_offset_strategy && !blk)) && get_bits1(gbc)) {
-        int csnroffst = (get_bits(gbc, 6) - 15) << 4;
-        int snroffst = 0;
-        for (ch = !s->cpl_in_use[blk]; ch <= s->channels; ch++){
-            if (!s->eac3 || ch == !s->cpl_in_use[blk] || s->snr_offset_strategy == 2)
-                snroffst = (csnroffst + get_bits(gbc, 4)) << 2;
-            /* run at least last bit allocation stage if snr offset changes */
-            if(blk && s->snr_offset[ch] != snroffst) {
-                bit_alloc_stages[ch] = FFMAX(bit_alloc_stages[ch], 1);
-            }
-            s->snr_offset[ch] = snroffst;
-            if(!s->eac3) {
-                int prev = s->fast_gain[ch];
-                s->fast_gain[ch] = ff_ac3_fast_gain_tab[get_bits(gbc, 3)];
-                /* run last 2 bit allocation stages if fast gain changes */
-                if(blk && prev != s->fast_gain[ch])
-                    bit_alloc_stages[ch] = 2;
-            }
-        }
-    }
-
-    if(s->eac3) {
-        if (s->fast_gain_syntax && get_bits1(gbc)) {
-            for (ch = !s->cpl_in_use[blk]; ch <= s->channels; ch++) {
-                int prev = s->fast_gain[ch];
-                s->fast_gain[ch] = ff_ac3_fast_gain_tab[get_bits(gbc, 3)];
-                /* run last 2 bit allocation stages if fast gain changes */
-                if(blk && prev != s->fast_gain[ch])
-                    bit_alloc_stages[ch] = 2;
-            }
-        } else if (!blk) {
-            for (ch = !s->cpl_in_use[blk]; ch <= s->channels; ch++)
-                s->fast_gain[ch] = ff_ac3_fast_gain_tab[4];
-        }
-        if (s->frame_type == EAC3_FRAME_TYPE_INDEPENDENT && get_bits1(gbc)) {
-            skip_bits(gbc, 10); //Converter SNR offset
-        }
-    }
-    if (s->cpl_in_use[blk]) {
-        if ((s->eac3 && s->first_cpl_leak) || get_bits1(gbc)) {
-            int prev_fl = s->bit_alloc_params.cpl_fast_leak;
-            int prev_sl = s->bit_alloc_params.cpl_slow_leak;
-            s->bit_alloc_params.cpl_fast_leak = get_bits(gbc, 3);
-            s->bit_alloc_params.cpl_slow_leak = get_bits(gbc, 3);
-            /* run last 2 bit allocation stages for coupling channel if
-               coupling leak changes */
-            if(blk && (prev_fl != s->bit_alloc_params.cpl_fast_leak ||
-                    prev_sl != s->bit_alloc_params.cpl_slow_leak)) {
-                bit_alloc_stages[CPL_CH] = FFMAX(bit_alloc_stages[CPL_CH], 2);
-            }
-        }
-        if(s->first_cpl_leak)
-            s->first_cpl_leak = 0;
-    }
-    /* Delta bit allocation information */
-    if ((!s->eac3 || s->dba_syntax) && get_bits1(gbc)) {
-        for (ch = !s->cpl_in_use[blk]; ch <= s->fbw_channels; ch++) {
-            s->dba_mode[ch] = get_bits(gbc, 2);
-        }
-        for (ch = !s->cpl_in_use[blk]; ch <= s->fbw_channels; ch++) {
-            if (s->dba_mode[ch] == DBA_NEW) {
-                s->dba_nsegs[ch] = get_bits(gbc, 3);
-                for (seg = 0; seg <= s->dba_nsegs[ch]; seg++) {
-                    s->dba_offsets[ch][seg] = get_bits(gbc, 5);
-                    s->dba_lengths[ch][seg] = get_bits(gbc, 4);
-                    s->dba_values[ch][seg] = get_bits(gbc, 3);
-                }
-                /* run last 2 bit allocation stages if dba values change */
-                bit_alloc_stages[ch] = FFMAX(bit_alloc_stages[ch], 2);
-            }
-        }
-    } else if (!blk) {
-        for (ch = 0; ch <= s->channels; ch++) {
-            s->dba_mode[ch] = DBA_NONE;
-        }
-    }
-
-    /* Inclusion of unused dummy data */
-    if ((!s->eac3 || s->skip_syntax) && get_bits1(gbc)) {
-        int skipl = get_bits(gbc, 9);
-        while(skipl--) skip_bits(gbc, 8);
-    }
-
-    /* run bit allocation */
-    for (ch = !s->cpl_in_use[blk]; ch <= s->channels; ch++) {
-        if(bit_alloc_stages[ch] > 2) {
-            ff_ac3_bit_alloc_calc_psd((int8_t *)s->dexps[ch], s->start_freq[ch],
-                    s->end_freq[ch], s->psd[ch], s->band_psd[ch]);
-        }
-
-        if(bit_alloc_stages[ch] > 1) {
-            ff_ac3_bit_alloc_calc_mask(&s->bit_alloc_params, s->band_psd[ch],
-                    s->start_freq[ch], s->end_freq[ch], s->fast_gain[ch],
-                    (ch == s->lfe_ch), s->dba_mode[ch], s->dba_nsegs[ch],
-                    s->dba_offsets[ch], s->dba_lengths[ch], s->dba_values[ch],
-                    s->mask[ch]);
-        }
-
-        if(bit_alloc_stages[ch] > 0) {
-            if (!s->eac3 || s->channel_uses_aht[ch] == 0)
-                ff_ac3_bit_alloc_calc_bap(s->mask[ch], s->psd[ch],
-                        s->start_freq[ch], s->end_freq[ch], s->snr_offset[ch],
-                        s->bit_alloc_params.floor, ff_ac3_bap_tab, s->bap[ch]);
-            else if (s->channel_uses_aht[ch] == 1)
-                ff_ac3_bit_alloc_calc_bap(s->mask[ch], s->psd[ch],
-                        s->start_freq[ch], s->end_freq[ch], s->snr_offset[ch],
-                        s->bit_alloc_params.floor, ff_eac3_hebap_tab,
-                        s->hebap[ch]);
-        }
-    }
-
-    got_cplchan = 0;
-
-    /* Quantized mantissa values */
-    if(ff_ac3_get_transform_coeffs(s, blk)) {
-        av_log(s->avctx, AV_LOG_ERROR, "error decoding transform coefficients\n");
-        return -1;
-    }
-
-#if 0
-    //apply spectral extension
-    if (s->spx_in_use)
-        spectral_extension(s);
-#endif
-
-    return 0;
-}
-#endif
-
 void ff_eac3_tables_init(void) {
     int blk, i;
 
@@ -1231,17 +502,4 @@ void ff_eac3_tables_init(void) {
         gaq_ungroup_tab[i][1] = (i % 9) / 3;
         gaq_ungroup_tab[i][2] = i % 3;
     }
-
-#if TEST_SPX
-    {
-    int j;
-    /* initialize spectral extension attenuation table */
-    for (j = 0; j < 3; j++) {
-        for (i = 0; i < 32; i++) {
-            spx_attenuation_tab[i][j] = pow(2.0, (i+1.0)*(j+1.0)/-15.0);
-            av_log(NULL, AV_LOG_DEBUG, "spxattentab[%d][%d] = %1.9f\n", j, i, spx_attenuation_tab[i][j]);
-        }
-    }
-    }
-#endif
 }



More information about the FFmpeg-soc mailing list