From 6d9f52b2cd760eacf6cc6b7d694b0b00d991f1de Mon Sep 17 00:00:00 2001 From: Mans Rullgard Date: Fri, 11 Mar 2011 02:49:55 +0000 Subject: ac3: move ff_ac3_bit_alloc_calc_bap to ac3dsp Signed-off-by: Mans Rullgard --- libavcodec/ac3dsp.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'libavcodec/ac3dsp.h') diff --git a/libavcodec/ac3dsp.h b/libavcodec/ac3dsp.h index eeaa56cbbf..bf4fc144d7 100644 --- a/libavcodec/ac3dsp.h +++ b/libavcodec/ac3dsp.h @@ -81,6 +81,25 @@ typedef struct AC3DSPContext { * constraints: multiple of 32 greater than zero */ void (*float_to_fixed24)(int32_t *dst, const float *src, unsigned int len); + + /** + * Calculate bit allocation pointers. + * The SNR is the difference between the masking curve and the signal. AC-3 + * uses this value for each frequency bin to allocate bits. The snroffset + * parameter is a global adjustment to the SNR for all bins. + * + * @param[in] mask masking curve + * @param[in] psd signal power for each frequency bin + * @param[in] start starting bin location + * @param[in] end ending bin location + * @param[in] snr_offset SNR adjustment + * @param[in] floor noise floor + * @param[in] bap_tab look-up table for bit allocation pointers + * @param[out] bap bit allocation pointers + */ + void (*bit_alloc_calc_bap)(int16_t *mask, int16_t *psd, int start, int end, + int snr_offset, int floor, + const uint8_t *bap_tab, uint8_t *bap); } AC3DSPContext; void ff_ac3dsp_init (AC3DSPContext *c, int bit_exact); -- cgit v1.2.3 From 52fd16a264d1eb14b1a84b7b38041da1756fb216 Mon Sep 17 00:00:00 2001 From: Mans Rullgard Date: Fri, 11 Mar 2011 17:16:27 +0000 Subject: ac3enc: move compute_mantissa_size() to ac3dsp Signed-off-by: Mans Rullgard --- libavcodec/ac3dsp.c | 23 +++++++++++++++++++++++ libavcodec/ac3dsp.h | 5 +++++ libavcodec/ac3enc.c | 27 +-------------------------- 3 files changed, 29 insertions(+), 26 deletions(-) (limited to 'libavcodec/ac3dsp.h') diff --git a/libavcodec/ac3dsp.c b/libavcodec/ac3dsp.c index 77250a351b..cd4d30b8f2 100644 --- a/libavcodec/ac3dsp.c +++ b/libavcodec/ac3dsp.c @@ -127,6 +127,28 @@ static void ac3_bit_alloc_calc_bap_c(int16_t *mask, int16_t *psd, } while (end > ff_ac3_band_start_tab[band++]); } +static int ac3_compute_mantissa_size_c(int mant_cnt[5], uint8_t *bap, + int nb_coefs) +{ + int bits, b, i; + + bits = 0; + for (i = 0; i < nb_coefs; i++) { + b = bap[i]; + if (b <= 4) { + // bap=1 to bap=4 will be counted in compute_mantissa_size_final + mant_cnt[b]++; + } else if (b <= 13) { + // bap=5 to bap=13 use (bap-1) bits + bits += b - 1; + } else { + // bap=14 uses 14 bits and bap=15 uses 16 bits + bits += (b == 14) ? 14 : 16; + } + } + return bits; +} + av_cold void ff_ac3dsp_init(AC3DSPContext *c, int bit_exact) { c->ac3_exponent_min = ac3_exponent_min_c; @@ -135,6 +157,7 @@ av_cold void ff_ac3dsp_init(AC3DSPContext *c, int bit_exact) c->ac3_rshift_int32 = ac3_rshift_int32_c; c->float_to_fixed24 = float_to_fixed24_c; c->bit_alloc_calc_bap = ac3_bit_alloc_calc_bap_c; + c->compute_mantissa_size = ac3_compute_mantissa_size_c; if (ARCH_ARM) ff_ac3dsp_init_arm(c, bit_exact); diff --git a/libavcodec/ac3dsp.h b/libavcodec/ac3dsp.h index bf4fc144d7..aa605a8b29 100644 --- a/libavcodec/ac3dsp.h +++ b/libavcodec/ac3dsp.h @@ -100,6 +100,11 @@ typedef struct AC3DSPContext { void (*bit_alloc_calc_bap)(int16_t *mask, int16_t *psd, int start, int end, int snr_offset, int floor, const uint8_t *bap_tab, uint8_t *bap); + + /** + * Calculate the number of bits needed to encode a set of mantissas. + */ + int (*compute_mantissa_size)(int mant_cnt[5], uint8_t *bap, int nb_coefs); } AC3DSPContext; void ff_ac3dsp_init (AC3DSPContext *c, int bit_exact); diff --git a/libavcodec/ac3enc.c b/libavcodec/ac3enc.c index fc591d9716..18e4dae26a 100644 --- a/libavcodec/ac3enc.c +++ b/libavcodec/ac3enc.c @@ -927,31 +927,6 @@ static void count_frame_bits(AC3EncodeContext *s) } -/** - * Calculate the number of bits needed to encode a set of mantissas. - */ -static int compute_mantissa_size(int mant_cnt[5], uint8_t *bap, int nb_coefs) -{ - int bits, b, i; - - bits = 0; - for (i = 0; i < nb_coefs; i++) { - b = bap[i]; - if (b <= 4) { - // bap=1 to bap=4 will be counted in compute_mantissa_size_final - mant_cnt[b]++; - } else if (b <= 13) { - // bap=5 to bap=13 use (bap-1) bits - bits += b - 1; - } else { - // bap=14 uses 14 bits and bap=15 uses 16 bits - bits += (b == 14) ? 14 : 16; - } - } - return bits; -} - - /** * Finalize the mantissa bit count by adding in the grouped mantissas. */ @@ -1052,7 +1027,7 @@ static int bit_alloc(AC3EncodeContext *s, int snr_offset) s->bit_alloc.floor, ff_ac3_bap_tab, block->bap[ch]); } - mantissa_bits += compute_mantissa_size(mant_cnt, block->bap[ch], s->nb_coefs[ch]); + mantissa_bits += s->ac3dsp.compute_mantissa_size(mant_cnt, block->bap[ch], s->nb_coefs[ch]); } mantissa_bits += compute_mantissa_size_final(mant_cnt); } -- cgit v1.2.3