[FFmpeg-devel] AAC decoder round 7

Michael Niedermayer michaelni
Tue Aug 12 20:05:44 CEST 2008


On Tue, Aug 12, 2008 at 06:45:35PM +0100, Robert Swain wrote:
> 2008/8/12 Michael Niedermayer <michaelni at gmx.at>:
[...]

> >> >>  /**
> >> >> + * Decode spectral data; reference: table 4.50.
> >> >> + *
> >> >> + * @param   band_type   array of the used band type
> >> >> + * @param   icoef       array of quantized spectral data
> >> >> + *
> >> >> + * @return  Returns error status. 0 - OK, !0 - error
> >> >> + */
> >> >> +static int decode_spectrum(AACContext * ac, int icoef[1024], GetBitContext * gb,
> >> >> +        const IndividualChannelStream * ics, enum BandType band_type[120]) {
> >> >> +    int i, k, g, idx = 0;
> >> >> +    const uint16_t * offsets = ics->swb_offset;
> >> >> +
> >> >> +    for (g = 0; g < ics->num_window_groups; g++) {
> >> >> +        for (i = 0; i < ics->max_sfb; i++, idx++) {
> >> >> +            const int cur_band_type = band_type[idx];
> >> >> +            const int dim = cur_band_type >= FIRST_PAIR_BT ? 2 : 4;
> >> >> +            const int is_cb_unsigned = IS_CODEBOOK_UNSIGNED(cur_band_type);
> >> >> +            int group;
> >> >> +            if (cur_band_type == ZERO_BT) {
> >> >> +                for (group = 0; group < ics->group_len[g]; group++) {
> >> >> +                    memset(icoef + group * 128 + offsets[i], 0, (offsets[i+1] - offsets[i])*sizeof(int));
> >> >> +                }
> >> >> +            }else if (cur_band_type != NOISE_BT && cur_band_type != INTENSITY_BT2 && cur_band_type != INTENSITY_BT) {
> >> >> +                for (group = 0; group < ics->group_len[g]; group++) {
> >> >> +                    for (k = offsets[i]; k < offsets[i+1]; k += dim) {
> >> >> +                        const int index = get_vlc2(gb, vlc_spectral[cur_band_type - 1].table, 6, 3);
> >> >> +                        const int coef_idx = (group << 7) + k;
> >> >> +                        const int8_t *vq_ptr;
> >> >> +                        int j;
> >> >> +                        if(index >= ff_aac_spectral_sizes[cur_band_type - 1]) {
> >> >> +                            av_log(ac->avccontext, AV_LOG_ERROR,
> >> >> +                                "Read beyond end of ff_aac_codebook_vectors[%d][]. index %d >= %d\n",
> >> >> +                                cur_band_type - 1, index, ff_aac_spectral_sizes[cur_band_type - 1]);
> >> >> +                            return -1;
> >> >> +                        }
> >> >> +                        vq_ptr = &ff_aac_codebook_vectors[cur_band_type - 1][index * dim];
> >> >> +                        if (is_cb_unsigned) {
> >> >> +                            for (j = 0; j < dim; j++)
> >> >> +                                if (vq_ptr[j])
> >> >> +                                    icoef[coef_idx + j] = 1 - 2*get_bits1(gb);
> >> >> +                        }else {
> >> >> +                            for (j = 0; j < dim; j++)
> >> >> +                                icoef[coef_idx + j] = 1;
> >> >> +                        }
> >> >> +                        if (cur_band_type == ESC_BT) {
> >> >> +                            for (j = 0; j < 2; j++) {
> >> >> +                                if (vq_ptr[j] == 16) {
> >> >> +                                    int n = 4;
> >> >> +                                    /* The total length of escape_sequence must be < 22 bits according
> >> >> +                                       to the specification (i.e. max is 11111111110xxxxxxxxxx). */
> >> >> +                                    while (get_bits1(gb) && n < 15) n++;
> >> >> +                                    if(n == 15) {
> >> >> +                                        av_log(ac->avccontext, AV_LOG_ERROR, "error in spectral data, ESC overflow\n");
> >> >> +                                        return -1;
> >> >> +                                    }
> >> >> +                                    icoef[coef_idx + j] *= (1<<n) + get_bits(gb, n);
> >> >> +                                }else
> >> >> +                                    icoef[coef_idx + j] *= vq_ptr[j];
> >> >> +                            }
> >> >> +                        }else
> >> >> +                            for (j = 0; j < dim; j++)
> >> >> +                                icoef[coef_idx + j] *= vq_ptr[j];
> >> >> +                    }
> >> >> +                }
> >> >> +            }
> >> >> +        }
> >> >> +        icoef += ics->group_len[g]<<7;
> >> >> +    }
> >> >> +    return 0;
> >> >> +}
> >> >> +
> >> >> +/**
> >> >>   * Add pulses with particular amplitudes to the quantized spectral data; reference: 4.6.3.3.
> >> >>   *
> >> >>   * @param   pulse   pointer to pulse data struct
> >> >> @@ -538,6 +780,46 @@
> >> >>  }
> >> >>
> >> >>  /**
> >> >> + * Dequantize and scale spectral data; reference: 4.6.3.3.
> >> >> + *
> >> >> + * @param   icoef       array of quantized spectral data
> >> >> + * @param   band_type   array of the used band type
> >> >> + * @param   sf          array of scalefactors or intensity stereo positions
> >> >> + * @param   coef        array of dequantized, scaled spectral data
> >> >> + */
> >> >> +static void dequant(AACContext * ac, float coef[1024], const int icoef[1024], float sf[120],
> >> >> +        const IndividualChannelStream * ics, enum BandType band_type[120]) {
> >> >> +    const uint16_t * offsets = ics->swb_offset;
> >> >> +    const int c = 1024/ics->num_windows;
> >> >> +    int g, i, group, k, idx = 0;
> >> >> +
> >> >> +    for (g = 0; g < ics->num_windows; g++)
> >> >> +        memset(coef + g * 128 + offsets[ics->max_sfb], 0, sizeof(float)*(c - offsets[ics->max_sfb]));
> >> >> +
> >> >> +    for (g = 0; g < ics->num_window_groups; g++) {
> >> >> +        for (i = 0; i < ics->max_sfb; i++, idx++) {
> >> >> +            if (band_type[idx] == NOISE_BT) {
> >> >> +                const float scale = sf[idx] / ((offsets[i+1] - offsets[i]) * PNS_MEAN_ENERGY);
> >> >> +                for (group = 0; group < ics->group_len[g]; group++) {
> >> >> +                    for (k = offsets[i]; k < offsets[i+1]; k++) {
> >> >> +                        ac->random_state  = lcg_random(ac->random_state);
> >> >> +                        coef[group*128+k] = ac->random_state * scale;
> >> >> +                    }
> >> >> +                }
> >> >> +            } else if (band_type[idx] != INTENSITY_BT && band_type[idx] != INTENSITY_BT2) {
> >> >> +                for (group = 0; group < ics->group_len[g]; group++) {
> >> >> +                    for (k = offsets[i]; k < offsets[i+1]; k++) {
> >> >> +                        coef[group*128+k] = ivquant(icoef[group*128+k]) * sf[idx];
> >> >> +                    }
> >> >> +                }
> >> >> +            }
> >> >> +        }
> >> >> +        coef  += ics->group_len[g]*128;
> >> >> +        icoef += ics->group_len[g]*128;
> >> >> +    }
> >> >> +}
> >> >> +
> >> >> +/**
> >> >
> >> > dequant and decode_spectrum() can be merged, especially the VQ tables can
> >> > already include ivquant().
> >> > and yes i know that this means add_pulses will be more tricky
> >>
> >> See attached (20080812-1422-merge_decspec_dequant.diff). It's not that
> >> nice to look at and svn diff makes it worse. Suggestions to improve it
> >> very welcome. Making add_pulse() recursive seemed like a good solution
> >> to avoid refactoring the main loops and conditions but maybe you have
> >> a better idea.
> >
> > yes i do :)
> > for(each pulse){
> >    float c= coeff[ pos[i] ];
> >    float ic= c / sqrtf(sqrtf(fabsf(c))) + amp[i];
> >    coeff[ pos[i] ]= cbrtf(fabsf(ic)) * ic;
> > }
> >
> > This idea is of course based on the assumtation that there are few pulses
> > compared to the number of coefficients, which as far as i understand is true
> > as there are max 4 pulses IIRC
> 
> You are correct. Good idea, though I don't know why I didn't think of
> doing it like that. :) See attached.

patch ok, but you still need to change the codebooks/vq to include ivquant()

[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

If a bugfix only changes things apparently unrelated to the bug with no
further explanation, that is a good sign that the bugfix is wrong.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20080812/a44610f3/attachment.pgp>



More information about the ffmpeg-devel mailing list