# HG changeset patch # User jbr # Date 1249439434 0 # Node ID 3fccd61e69d14cc6e2866feaad775ffb29cb5bc7 # Parent 9ff48c350a3288eb5721f7832c4159b76e5441ba ac3dec: simplify zero-bit mantissa dithering by calculating it conditionally during mantissa decoding, then only removing it from the coupling range for coupled channels which do not use dithering. diff -r 9ff48c350a32 -r 3fccd61e69d1 ac3dec.c --- a/ac3dec.c Wed Aug 05 01:58:28 2009 +0000 +++ b/ac3dec.c Wed Aug 05 02:30:34 2009 +0000 @@ -452,6 +452,7 @@ uint8_t *baps = s->bap[ch_index]; int8_t *exps = s->dexps[ch_index]; int *coeffs = s->fixed_coeffs[ch_index]; + int dither = (ch_index == CPL_CH) || s->dither_flag[ch_index]; GetBitContext *gbc = &s->gbc; int freq; @@ -460,7 +461,10 @@ int mantissa; switch(bap){ case 0: + if (dither) mantissa = (av_lfg_get(&s->dith_state) & 0x7FFFFF) - 0x400000; + else + mantissa = 0; break; case 1: if(m->b1){ @@ -517,33 +521,18 @@ } /** - * Remove random dithering from coefficients with zero-bit mantissas + * Remove random dithering from coupling range coefficients with zero-bit + * mantissas for coupled channels which do not use dithering. * reference: Section 7.3.4 Dither for Zero Bit Mantissas (bap=0) */ static void remove_dithering(AC3DecodeContext *s) { int ch, i; - int end=0; - int *coeffs; - uint8_t *bap; for(ch=1; ch<=s->fbw_channels; ch++) { - if(!s->dither_flag[ch]) { - coeffs = s->fixed_coeffs[ch]; - bap = s->bap[ch]; - if(s->channel_in_cpl[ch]) - end = s->start_freq[CPL_CH]; - else - end = s->end_freq[ch]; - for(i=0; ichannel_in_cpl[ch]) { - bap = s->bap[CPL_CH]; - for(; iend_freq[CPL_CH]; i++) { - if(!bap[i]) - coeffs[i] = 0; - } + if(!s->dither_flag[ch] && s->channel_in_cpl[ch]) { + for(i = s->start_freq[CPL_CH]; iend_freq[CPL_CH]; i++) { + if(!s->bap[CPL_CH][i]) + s->fixed_coeffs[ch][i] = 0; } } }