aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMans Rullgard <mans@mansr.com>2011-03-11 02:49:55 +0000
committerMans Rullgard <mans@mansr.com>2011-03-29 19:31:45 +0100
commit6d9f52b2cd760eacf6cc6b7d694b0b00d991f1de (patch)
treeb6275771445a9cf058d92cb5fb2847698a3414a8
parentd38345878cbb89e4d8d33bd79f47836d4e9cd637 (diff)
downloadffmpeg-6d9f52b2cd760eacf6cc6b7d694b0b00d991f1de.tar.gz
ac3: move ff_ac3_bit_alloc_calc_bap to ac3dsp
Signed-off-by: Mans Rullgard <mans@mansr.com>
-rwxr-xr-xconfigure2
-rw-r--r--libavcodec/ac3.c46
-rw-r--r--libavcodec/ac3.h19
-rw-r--r--libavcodec/ac3dec.c3
-rw-r--r--libavcodec/ac3dec.h2
-rw-r--r--libavcodec/ac3dsp.c27
-rw-r--r--libavcodec/ac3dsp.h19
-rw-r--r--libavcodec/ac3enc.c2
-rw-r--r--libavcodec/ac3tab.h8
9 files changed, 71 insertions, 57 deletions
diff --git a/configure b/configure
index 0f8b8491e5..2634cef093 100755
--- a/configure
+++ b/configure
@@ -1238,7 +1238,7 @@ rdft_select="fft"
aac_decoder_select="mdct rdft sinewin"
aac_encoder_select="mdct sinewin"
aac_latm_decoder_select="aac_decoder aac_latm_parser"
-ac3_decoder_select="mdct ac3_parser"
+ac3_decoder_select="mdct ac3dsp ac3_parser"
ac3_encoder_select="mdct ac3dsp"
ac3_fixed_encoder_select="ac3dsp"
alac_encoder_select="lpc"
diff --git a/libavcodec/ac3.c b/libavcodec/ac3.c
index c8659fe6f5..704c6e03a6 100644
--- a/libavcodec/ac3.c
+++ b/libavcodec/ac3.c
@@ -31,7 +31,7 @@
/**
* Starting frequency coefficient bin for each critical band.
*/
-static const uint8_t band_start_tab[AC3_CRITICAL_BANDS+1] = {
+const uint8_t ff_ac3_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,
@@ -44,7 +44,7 @@ static const uint8_t band_start_tab[AC3_CRITICAL_BANDS+1] = {
/**
* Map each frequency coefficient bin to the critical band that contains it.
*/
-static const uint8_t bin_to_band_tab[253] = {
+const uint8_t ff_ac3_bin_to_band_tab[253] = {
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,
@@ -70,7 +70,7 @@ static const uint8_t bin_to_band_tab[253] = {
};
#else /* CONFIG_HARDCODED_TABLES */
-static uint8_t bin_to_band_tab[253];
+uint8_t ff_ac3_bin_to_band_tab[253];
#endif
static inline int calc_lowcomp1(int a, int b0, int b1, int c)
@@ -106,10 +106,10 @@ void ff_ac3_bit_alloc_calc_psd(int8_t *exp, int start, int end, int16_t *psd,
/* PSD integration */
bin = start;
- band = bin_to_band_tab[start];
+ band = ff_ac3_bin_to_band_tab[start];
do {
int v = psd[bin++];
- int band_end = FFMIN(band_start_tab[band+1], end);
+ int band_end = FFMIN(ff_ac3_band_start_tab[band+1], end);
for (; bin < band_end; bin++) {
int max = FFMAX(v, psd[bin]);
/* logadd */
@@ -117,7 +117,7 @@ void ff_ac3_bit_alloc_calc_psd(int8_t *exp, int start, int end, int16_t *psd,
v = max + ff_ac3_log_add_tab[adr];
}
band_psd[band++] = v;
- } while (end > band_start_tab[band]);
+ } while (end > ff_ac3_band_start_tab[band]);
}
int ff_ac3_bit_alloc_calc_mask(AC3BitAllocParameters *s, int16_t *band_psd,
@@ -132,8 +132,8 @@ int ff_ac3_bit_alloc_calc_mask(AC3BitAllocParameters *s, int16_t *band_psd,
int lowcomp, fastleak, slowleak;
/* excitation function */
- band_start = bin_to_band_tab[start];
- band_end = bin_to_band_tab[end-1] + 1;
+ band_start = ff_ac3_bin_to_band_tab[start];
+ band_end = ff_ac3_bin_to_band_tab[end-1] + 1;
if (band_start == 0) {
lowcomp = 0;
@@ -212,30 +212,6 @@ int ff_ac3_bit_alloc_calc_mask(AC3BitAllocParameters *s, int16_t *band_psd,
return 0;
}
-void ff_ac3_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)
-{
- int bin, band;
-
- /* special case, if snr offset is -960, set all bap's to zero */
- if (snr_offset == -960) {
- memset(bap, 0, AC3_MAX_COEFS);
- return;
- }
-
- bin = start;
- band = bin_to_band_tab[start];
- do {
- int m = (FFMAX(mask[band] - snr_offset - floor, 0) & 0x1FE0) + floor;
- int band_end = FFMIN(band_start_tab[band+1], end);
- for (; bin < band_end; bin++) {
- int address = av_clip((psd[bin] - m) >> 5, 0, 63);
- bap[bin] = bap_tab[address];
- }
- } while (end > band_start_tab[band++]);
-}
-
/**
* Initialize some tables.
* note: This function must remain thread safe because it is called by the
@@ -244,12 +220,12 @@ void ff_ac3_bit_alloc_calc_bap(int16_t *mask, int16_t *psd, int start, int end,
av_cold void ff_ac3_common_init(void)
{
#if !CONFIG_HARDCODED_TABLES
- /* compute bin_to_band_tab from band_start_tab */
+ /* compute ff_ac3_bin_to_band_tab from ff_ac3_band_start_tab */
int bin = 0, band;
for (band = 0; band < AC3_CRITICAL_BANDS; band++) {
- int band_end = band_start_tab[band+1];
+ int band_end = ff_ac3_band_start_tab[band+1];
while (bin < band_end)
- bin_to_band_tab[bin++] = band;
+ ff_ac3_bin_to_band_tab[bin++] = band;
}
#endif /* !CONFIG_HARDCODED_TABLES */
}
diff --git a/libavcodec/ac3.h b/libavcodec/ac3.h
index 133c5b9a78..4ed8c2523b 100644
--- a/libavcodec/ac3.h
+++ b/libavcodec/ac3.h
@@ -175,23 +175,4 @@ int ff_ac3_bit_alloc_calc_mask(AC3BitAllocParameters *s, int16_t *band_psd,
uint8_t *dba_lengths, uint8_t *dba_values,
int16_t *mask);
-/**
- * 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 ff_ac3_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);
-
#endif /* AVCODEC_AC3_H */
diff --git a/libavcodec/ac3dec.c b/libavcodec/ac3dec.c
index e08efa104c..396df87fed 100644
--- a/libavcodec/ac3dec.c
+++ b/libavcodec/ac3dec.c
@@ -184,6 +184,7 @@ static av_cold int ac3_decode_init(AVCodecContext *avctx)
ff_mdct_init(&s->imdct_512, 9, 1, 1.0);
ff_kbd_window_init(s->window, 5.0, 256);
dsputil_init(&s->dsp, avctx);
+ ff_ac3dsp_init(&s->ac3dsp, avctx->flags & CODEC_FLAG_BITEXACT);
ff_fmt_convert_init(&s->fmt_conv, avctx);
av_lfg_init(&s->dith_state, 0);
@@ -1213,7 +1214,7 @@ static int decode_audio_block(AC3DecodeContext *s, int blk)
/* Compute bit allocation */
const uint8_t *bap_tab = s->channel_uses_aht[ch] ?
ff_eac3_hebap_tab : ff_ac3_bap_tab;
- ff_ac3_bit_alloc_calc_bap(s->mask[ch], s->psd[ch],
+ s->ac3dsp.bit_alloc_calc_bap(s->mask[ch], s->psd[ch],
s->start_freq[ch], s->end_freq[ch],
s->snr_offset[ch],
s->bit_alloc_params.floor,
diff --git a/libavcodec/ac3dec.h b/libavcodec/ac3dec.h
index 9d0ffc313e..3459441bbd 100644
--- a/libavcodec/ac3dec.h
+++ b/libavcodec/ac3dec.h
@@ -52,6 +52,7 @@
#include "libavutil/lfg.h"
#include "ac3.h"
+#include "ac3dsp.h"
#include "get_bits.h"
#include "dsputil.h"
#include "fft.h"
@@ -192,6 +193,7 @@ typedef struct {
///@defgroup opt optimization
DSPContext dsp; ///< for optimization
+ AC3DSPContext ac3dsp;
FmtConvertContext fmt_conv; ///< optimized conversion functions
float mul_bias; ///< scaling for float_to_int16 conversion
///@}
diff --git a/libavcodec/ac3dsp.c b/libavcodec/ac3dsp.c
index 42b44f7db8..77250a351b 100644
--- a/libavcodec/ac3dsp.c
+++ b/libavcodec/ac3dsp.c
@@ -20,6 +20,7 @@
*/
#include "avcodec.h"
+#include "ac3.h"
#include "ac3dsp.h"
static void ac3_exponent_min_c(uint8_t *exp, int num_reuse_blocks, int nb_coefs)
@@ -101,6 +102,31 @@ static void float_to_fixed24_c(int32_t *dst, const float *src, unsigned int len)
} while (len > 0);
}
+static void ac3_bit_alloc_calc_bap_c(int16_t *mask, int16_t *psd,
+ int start, int end,
+ int snr_offset, int floor,
+ const uint8_t *bap_tab, uint8_t *bap)
+{
+ int bin, band;
+
+ /* special case, if snr offset is -960, set all bap's to zero */
+ if (snr_offset == -960) {
+ memset(bap, 0, AC3_MAX_COEFS);
+ return;
+ }
+
+ bin = start;
+ band = ff_ac3_bin_to_band_tab[start];
+ do {
+ int m = (FFMAX(mask[band] - snr_offset - floor, 0) & 0x1FE0) + floor;
+ int band_end = FFMIN(ff_ac3_band_start_tab[band+1], end);
+ for (; bin < band_end; bin++) {
+ int address = av_clip((psd[bin] - m) >> 5, 0, 63);
+ bap[bin] = bap_tab[address];
+ }
+ } while (end > ff_ac3_band_start_tab[band++]);
+}
+
av_cold void ff_ac3dsp_init(AC3DSPContext *c, int bit_exact)
{
c->ac3_exponent_min = ac3_exponent_min_c;
@@ -108,6 +134,7 @@ av_cold void ff_ac3dsp_init(AC3DSPContext *c, int bit_exact)
c->ac3_lshift_int16 = ac3_lshift_int16_c;
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;
if (ARCH_ARM)
ff_ac3dsp_init_arm(c, bit_exact);
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);
diff --git a/libavcodec/ac3enc.c b/libavcodec/ac3enc.c
index c641400a2d..e62ded62c8 100644
--- a/libavcodec/ac3enc.c
+++ b/libavcodec/ac3enc.c
@@ -1047,7 +1047,7 @@ static int bit_alloc(AC3EncodeContext *s, int snr_offset)
whenever we reuse exponents. */
block = s->blocks[blk].exp_ref_block[ch];
if (s->exp_strategy[ch][blk] != EXP_REUSE) {
- ff_ac3_bit_alloc_calc_bap(block->mask[ch], block->psd[ch], 0,
+ s->ac3dsp.bit_alloc_calc_bap(block->mask[ch], block->psd[ch], 0,
s->nb_coefs[ch], snr_offset,
s->bit_alloc.floor, ff_ac3_bap_tab,
block->bap[ch]);
diff --git a/libavcodec/ac3tab.h b/libavcodec/ac3tab.h
index e3fda9715a..292ce0d32f 100644
--- a/libavcodec/ac3tab.h
+++ b/libavcodec/ac3tab.h
@@ -25,6 +25,12 @@
#include "libavutil/common.h"
#include "ac3.h"
+#if CONFIG_HARDCODED_TABLES
+# define HCONST const
+#else
+# define HCONST
+#endif
+
extern const uint16_t ff_ac3_frame_size_tab[38][3];
extern const uint8_t ff_ac3_channels_tab[8];
extern const uint16_t ff_ac3_channel_layout_tab[8];
@@ -44,6 +50,8 @@ extern const uint16_t ff_ac3_db_per_bit_tab[4];
extern const int16_t ff_ac3_floor_tab[8];
extern const uint16_t ff_ac3_fast_gain_tab[8];
extern const uint16_t ff_eac3_default_chmap[8];
+extern const uint8_t ff_ac3_band_start_tab[AC3_CRITICAL_BANDS+1];
+extern HCONST uint8_t ff_ac3_bin_to_band_tab[253];
/** Custom channel map locations bitmask
* Other channels described in documentation: