From 47ae6e795b64aaf29c47730cc552d48bb27a0e40 Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Tue, 14 Dec 2010 14:51:40 +0000 Subject: [PATCH] define AC3_CRITICAL_BANDS and use it in the AC-3 encoder and decoder. Originally committed as revision 25967 to svn://svn.ffmpeg.org/ffmpeg/trunk --- libavcodec/ac3.c | 14 +++++++------- libavcodec/ac3.h | 1 + libavcodec/ac3dec.h | 4 ++-- libavcodec/ac3enc.c | 10 +++++----- 4 files changed, 15 insertions(+), 14 deletions(-) diff --git a/libavcodec/ac3.c b/libavcodec/ac3.c index 1f5ab32eb8..9e979def51 100644 --- a/libavcodec/ac3.c +++ b/libavcodec/ac3.c @@ -33,7 +33,7 @@ /** * Starting frequency coefficient bin for each critical band. */ -static const uint8_t band_start_tab[51] = { +static const uint8_t band_start_tab[AC3_CRITICAL_BANDS+1] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 31, @@ -127,7 +127,7 @@ int ff_ac3_bit_alloc_calc_mask(AC3BitAllocParameters *s, int16_t *band_psd, uint8_t *dba_lengths, uint8_t *dba_values, int16_t *mask) { - int16_t excite[50]; /* excitation */ + int16_t excite[AC3_CRITICAL_BANDS]; /* excitation */ int band; int band_start, band_end, begin, end1; int lowcomp, fastleak, slowleak; @@ -198,7 +198,7 @@ int ff_ac3_bit_alloc_calc_mask(AC3BitAllocParameters *s, int16_t *band_psd, band = 0; for (seg = 0; seg < dba_nsegs; seg++) { band += dba_offsets[seg]; - if (band >= 50 || dba_lengths[seg] > 50-band) + if (band >= AC3_CRITICAL_BANDS || dba_lengths[seg] > AC3_CRITICAL_BANDS-band) return -1; if (dba_values[seg] >= 4) { delta = (dba_values[seg] - 3) << 7; @@ -247,8 +247,8 @@ void ac3_parametric_bit_allocation(AC3BitAllocParameters *s, uint8_t *bap, uint8_t *dba_values) { int16_t psd[256]; /* scaled exponents */ - int16_t band_psd[50]; /* interpolated exponents */ - int16_t mask[50]; /* masking value */ + int16_t band_psd[AC3_CRITICAL_BANDS]; /* interpolated exponents */ + int16_t mask[AC3_CRITICAL_BANDS]; /* masking value */ ff_ac3_bit_alloc_calc_psd(exp, start, end, psd, band_psd); @@ -270,12 +270,12 @@ av_cold void ac3_common_init(void) #if !CONFIG_HARDCODED_TABLES /* compute bndtab and masktab from bandsz */ int bin = 0, band; - for (band = 0; band < 50; band++) { + for (band = 0; band < AC3_CRITICAL_BANDS; band++) { int band_end = bin + ff_ac3_critical_band_size_tab[band]; band_start_tab[band] = bin; while (bin < band_end) bin_to_band_tab[bin++] = band; } - band_start_tab[50] = bin; + band_start_tab[AC3_CRITICAL_BANDS] = bin; #endif /* !CONFIG_HARDCODED_TABLES */ } diff --git a/libavcodec/ac3.h b/libavcodec/ac3.h index 1840766813..a9f68dba8a 100644 --- a/libavcodec/ac3.h +++ b/libavcodec/ac3.h @@ -37,6 +37,7 @@ #define AC3_MAX_BLOCKS 6 #define AC3_FRAME_SIZE (AC3_MAX_BLOCKS * 256) #define AC3_WINDOW_SIZE (AC3_BLOCK_SIZE * 2) +#define AC3_CRITICAL_BANDS 50 /* exponent encoding strategy */ #define EXP_REUSE 0 diff --git a/libavcodec/ac3dec.h b/libavcodec/ac3dec.h index c163a1d3d6..0707769478 100644 --- a/libavcodec/ac3dec.h +++ b/libavcodec/ac3dec.h @@ -168,8 +168,8 @@ typedef struct { int fast_gain[AC3_MAX_CHANNELS]; ///< fast gain values/SMR's (fgain) uint8_t bap[AC3_MAX_CHANNELS][AC3_MAX_COEFS]; ///< bit allocation pointers int16_t psd[AC3_MAX_CHANNELS][AC3_MAX_COEFS]; ///< scaled exponents - int16_t band_psd[AC3_MAX_CHANNELS][50]; ///< interpolated exponents - int16_t mask[AC3_MAX_CHANNELS][50]; ///< masking curve values + int16_t band_psd[AC3_MAX_CHANNELS][AC3_CRITICAL_BANDS]; ///< interpolated exponents + int16_t mask[AC3_MAX_CHANNELS][AC3_CRITICAL_BANDS]; ///< masking curve values int dba_mode[AC3_MAX_CHANNELS]; ///< delta bit allocation mode int dba_nsegs[AC3_MAX_CHANNELS]; ///< number of delta segments uint8_t dba_offsets[AC3_MAX_CHANNELS][8]; ///< delta segment offsets diff --git a/libavcodec/ac3enc.c b/libavcodec/ac3enc.c index ebba7f53eb..17aa89c846 100644 --- a/libavcodec/ac3enc.c +++ b/libavcodec/ac3enc.c @@ -506,16 +506,16 @@ static void bit_alloc_masking(AC3EncodeContext *s, uint8_t encoded_exp[AC3_MAX_BLOCKS][AC3_MAX_CHANNELS][AC3_MAX_COEFS], uint8_t exp_strategy[AC3_MAX_BLOCKS][AC3_MAX_CHANNELS], int16_t psd[AC3_MAX_BLOCKS][AC3_MAX_CHANNELS][AC3_MAX_COEFS], - int16_t mask[AC3_MAX_BLOCKS][AC3_MAX_CHANNELS][50]) + int16_t mask[AC3_MAX_BLOCKS][AC3_MAX_CHANNELS][AC3_CRITICAL_BANDS]) { int blk, ch; - int16_t band_psd[AC3_MAX_BLOCKS][AC3_MAX_CHANNELS][50]; + int16_t band_psd[AC3_MAX_BLOCKS][AC3_MAX_CHANNELS][AC3_CRITICAL_BANDS]; for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) { for (ch = 0; ch < s->channels; ch++) { if(exp_strategy[blk][ch] == EXP_REUSE) { memcpy(psd[blk][ch], psd[blk-1][ch], AC3_MAX_COEFS*sizeof(psd[0][0][0])); - memcpy(mask[blk][ch], mask[blk-1][ch], 50*sizeof(mask[0][0][0])); + memcpy(mask[blk][ch], mask[blk-1][ch], AC3_CRITICAL_BANDS*sizeof(mask[0][0][0])); } else { ff_ac3_bit_alloc_calc_psd(encoded_exp[blk][ch], 0, s->nb_coefs[ch], @@ -540,7 +540,7 @@ static void bit_alloc_masking(AC3EncodeContext *s, * SNR offset is used to quantize the mantissas. */ static int bit_alloc(AC3EncodeContext *s, - int16_t mask[AC3_MAX_BLOCKS][AC3_MAX_CHANNELS][50], + int16_t mask[AC3_MAX_BLOCKS][AC3_MAX_CHANNELS][AC3_CRITICAL_BANDS], int16_t psd[AC3_MAX_BLOCKS][AC3_MAX_CHANNELS][AC3_MAX_COEFS], uint8_t bap[AC3_MAX_BLOCKS][AC3_MAX_CHANNELS][AC3_MAX_COEFS], int frame_bits, int coarse_snr_offset, int fine_snr_offset) @@ -584,7 +584,7 @@ static int compute_bit_allocation(AC3EncodeContext *s, int coarse_snr_offset, fine_snr_offset; uint8_t bap1[AC3_MAX_BLOCKS][AC3_MAX_CHANNELS][AC3_MAX_COEFS]; int16_t psd[AC3_MAX_BLOCKS][AC3_MAX_CHANNELS][AC3_MAX_COEFS]; - int16_t mask[AC3_MAX_BLOCKS][AC3_MAX_CHANNELS][50]; + int16_t mask[AC3_MAX_BLOCKS][AC3_MAX_CHANNELS][AC3_CRITICAL_BANDS]; static const int frame_bits_inc[8] = { 0, 0, 2, 2, 2, 4, 2, 4 }; /* init default parameters */