# HG changeset patch # User jbr # Date 1212270811 0 # Node ID 6eb895971766786e7b3b73635e8d39cf762407a6 # Parent 9984c30bf2339b7fd2e18da3178b923ccb240622 only calculate number of exponent groups when exponents are not reused. diff -r 9984c30bf233 -r 6eb895971766 ac3dec.c --- a/ac3dec.c Sat May 31 21:37:28 2008 +0000 +++ b/ac3dec.c Sat May 31 21:53:31 2008 +0000 @@ -154,6 +154,7 @@ int end_freq[AC3_MAX_CHANNELS]; ///< end frequency bin AC3BitAllocParameters bit_alloc_params; ///< bit allocation parameters + int num_exp_groups[AC3_MAX_CHANNELS]; ///< Number of exponent groups 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 @@ -907,6 +908,7 @@ for (ch = 1; ch <= fbw_channels; ch++) { s->start_freq[ch] = 0; if (s->exp_strategy[ch] != EXP_REUSE) { + int group_size; int prev = s->end_freq[ch]; if (s->channel_in_cpl[ch]) s->end_freq[ch] = s->start_freq[CPL_CH]; @@ -918,26 +920,26 @@ } s->end_freq[ch] = bandwidth_code * 3 + 73; } + group_size = 3 << (s->exp_strategy[ch] - 1); + s->num_exp_groups[ch] = (s->end_freq[ch]+group_size-4) / group_size; if(blk > 0 && s->end_freq[ch] != prev) memset(bit_alloc_stages, 3, AC3_MAX_CHANNELS); } } s->start_freq[s->lfe_ch] = 0; s->end_freq[s->lfe_ch] = 7; + s->num_exp_groups[s->lfe_ch] = 2; + if (s->cpl_in_use && s->exp_strategy[CPL_CH] != EXP_REUSE) { + s->num_exp_groups[CPL_CH] = (s->end_freq[CPL_CH] - s->start_freq[CPL_CH]) / + (3 << (s->exp_strategy[CPL_CH] - 1)); + } /* decode exponents for each channel */ for (ch = !s->cpl_in_use; ch <= s->channels; ch++) { if (s->exp_strategy[ch] != EXP_REUSE) { - int group_size, num_groups; - group_size = 3 << (s->exp_strategy[ch] - 1); - if(ch == CPL_CH) - num_groups = (s->end_freq[ch] - s->start_freq[ch]) / group_size; - else if(ch == s->lfe_ch) - num_groups = 2; - else - num_groups = (s->end_freq[ch] + group_size - 4) / group_size; s->dexps[ch][0] = get_bits(gbc, 4) << !ch; - decode_exponents(gbc, s->exp_strategy[ch], num_groups, s->dexps[ch][0], + decode_exponents(gbc, s->exp_strategy[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 */