Signed-off-by: Mans Rullgard <mans@mansr.com>
| ... | ... |
@@ -1238,7 +1238,7 @@ rdft_select="fft" |
| 1238 | 1238 |
aac_decoder_select="mdct rdft sinewin" |
| 1239 | 1239 |
aac_encoder_select="mdct sinewin" |
| 1240 | 1240 |
aac_latm_decoder_select="aac_decoder aac_latm_parser" |
| 1241 |
-ac3_decoder_select="mdct ac3_parser" |
|
| 1241 |
+ac3_decoder_select="mdct ac3dsp ac3_parser" |
|
| 1242 | 1242 |
ac3_encoder_select="mdct ac3dsp" |
| 1243 | 1243 |
ac3_fixed_encoder_select="ac3dsp" |
| 1244 | 1244 |
alac_encoder_select="lpc" |
| ... | ... |
@@ -31,7 +31,7 @@ |
| 31 | 31 |
/** |
| 32 | 32 |
* Starting frequency coefficient bin for each critical band. |
| 33 | 33 |
*/ |
| 34 |
-static const uint8_t band_start_tab[AC3_CRITICAL_BANDS+1] = {
|
|
| 34 |
+const uint8_t ff_ac3_band_start_tab[AC3_CRITICAL_BANDS+1] = {
|
|
| 35 | 35 |
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, |
| 36 | 36 |
10, 11, 12, 13, 14, 15, 16, 17, 18, 19, |
| 37 | 37 |
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] = {
|
| 44 | 44 |
/** |
| 45 | 45 |
* Map each frequency coefficient bin to the critical band that contains it. |
| 46 | 46 |
*/ |
| 47 |
-static const uint8_t bin_to_band_tab[253] = {
|
|
| 47 |
+const uint8_t ff_ac3_bin_to_band_tab[253] = {
|
|
| 48 | 48 |
0, |
| 49 | 49 |
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, |
| 50 | 50 |
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] = {
|
| 70 | 70 |
}; |
| 71 | 71 |
|
| 72 | 72 |
#else /* CONFIG_HARDCODED_TABLES */ |
| 73 |
-static uint8_t bin_to_band_tab[253]; |
|
| 73 |
+uint8_t ff_ac3_bin_to_band_tab[253]; |
|
| 74 | 74 |
#endif |
| 75 | 75 |
|
| 76 | 76 |
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, |
| 106 | 106 |
|
| 107 | 107 |
/* PSD integration */ |
| 108 | 108 |
bin = start; |
| 109 |
- band = bin_to_band_tab[start]; |
|
| 109 |
+ band = ff_ac3_bin_to_band_tab[start]; |
|
| 110 | 110 |
do {
|
| 111 | 111 |
int v = psd[bin++]; |
| 112 |
- int band_end = FFMIN(band_start_tab[band+1], end); |
|
| 112 |
+ int band_end = FFMIN(ff_ac3_band_start_tab[band+1], end); |
|
| 113 | 113 |
for (; bin < band_end; bin++) {
|
| 114 | 114 |
int max = FFMAX(v, psd[bin]); |
| 115 | 115 |
/* logadd */ |
| ... | ... |
@@ -117,7 +117,7 @@ void ff_ac3_bit_alloc_calc_psd(int8_t *exp, int start, int end, int16_t *psd, |
| 117 | 117 |
v = max + ff_ac3_log_add_tab[adr]; |
| 118 | 118 |
} |
| 119 | 119 |
band_psd[band++] = v; |
| 120 |
- } while (end > band_start_tab[band]); |
|
| 120 |
+ } while (end > ff_ac3_band_start_tab[band]); |
|
| 121 | 121 |
} |
| 122 | 122 |
|
| 123 | 123 |
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, |
| 132 | 132 |
int lowcomp, fastleak, slowleak; |
| 133 | 133 |
|
| 134 | 134 |
/* excitation function */ |
| 135 |
- band_start = bin_to_band_tab[start]; |
|
| 136 |
- band_end = bin_to_band_tab[end-1] + 1; |
|
| 135 |
+ band_start = ff_ac3_bin_to_band_tab[start]; |
|
| 136 |
+ band_end = ff_ac3_bin_to_band_tab[end-1] + 1; |
|
| 137 | 137 |
|
| 138 | 138 |
if (band_start == 0) {
|
| 139 | 139 |
lowcomp = 0; |
| ... | ... |
@@ -212,30 +212,6 @@ int ff_ac3_bit_alloc_calc_mask(AC3BitAllocParameters *s, int16_t *band_psd, |
| 212 | 212 |
return 0; |
| 213 | 213 |
} |
| 214 | 214 |
|
| 215 |
-void ff_ac3_bit_alloc_calc_bap(int16_t *mask, int16_t *psd, int start, int end, |
|
| 216 |
- int snr_offset, int floor, |
|
| 217 |
- const uint8_t *bap_tab, uint8_t *bap) |
|
| 218 |
-{
|
|
| 219 |
- int bin, band; |
|
| 220 |
- |
|
| 221 |
- /* special case, if snr offset is -960, set all bap's to zero */ |
|
| 222 |
- if (snr_offset == -960) {
|
|
| 223 |
- memset(bap, 0, AC3_MAX_COEFS); |
|
| 224 |
- return; |
|
| 225 |
- } |
|
| 226 |
- |
|
| 227 |
- bin = start; |
|
| 228 |
- band = bin_to_band_tab[start]; |
|
| 229 |
- do {
|
|
| 230 |
- int m = (FFMAX(mask[band] - snr_offset - floor, 0) & 0x1FE0) + floor; |
|
| 231 |
- int band_end = FFMIN(band_start_tab[band+1], end); |
|
| 232 |
- for (; bin < band_end; bin++) {
|
|
| 233 |
- int address = av_clip((psd[bin] - m) >> 5, 0, 63); |
|
| 234 |
- bap[bin] = bap_tab[address]; |
|
| 235 |
- } |
|
| 236 |
- } while (end > band_start_tab[band++]); |
|
| 237 |
-} |
|
| 238 |
- |
|
| 239 | 215 |
/** |
| 240 | 216 |
* Initialize some tables. |
| 241 | 217 |
* 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, |
| 244 | 244 |
av_cold void ff_ac3_common_init(void) |
| 245 | 245 |
{
|
| 246 | 246 |
#if !CONFIG_HARDCODED_TABLES |
| 247 |
- /* compute bin_to_band_tab from band_start_tab */ |
|
| 247 |
+ /* compute ff_ac3_bin_to_band_tab from ff_ac3_band_start_tab */ |
|
| 248 | 248 |
int bin = 0, band; |
| 249 | 249 |
for (band = 0; band < AC3_CRITICAL_BANDS; band++) {
|
| 250 |
- int band_end = band_start_tab[band+1]; |
|
| 250 |
+ int band_end = ff_ac3_band_start_tab[band+1]; |
|
| 251 | 251 |
while (bin < band_end) |
| 252 |
- bin_to_band_tab[bin++] = band; |
|
| 252 |
+ ff_ac3_bin_to_band_tab[bin++] = band; |
|
| 253 | 253 |
} |
| 254 | 254 |
#endif /* !CONFIG_HARDCODED_TABLES */ |
| 255 | 255 |
} |
| ... | ... |
@@ -175,23 +175,4 @@ int ff_ac3_bit_alloc_calc_mask(AC3BitAllocParameters *s, int16_t *band_psd, |
| 175 | 175 |
uint8_t *dba_lengths, uint8_t *dba_values, |
| 176 | 176 |
int16_t *mask); |
| 177 | 177 |
|
| 178 |
-/** |
|
| 179 |
- * Calculate bit allocation pointers. |
|
| 180 |
- * The SNR is the difference between the masking curve and the signal. AC-3 |
|
| 181 |
- * uses this value for each frequency bin to allocate bits. The snroffset |
|
| 182 |
- * parameter is a global adjustment to the SNR for all bins. |
|
| 183 |
- * |
|
| 184 |
- * @param[in] mask masking curve |
|
| 185 |
- * @param[in] psd signal power for each frequency bin |
|
| 186 |
- * @param[in] start starting bin location |
|
| 187 |
- * @param[in] end ending bin location |
|
| 188 |
- * @param[in] snr_offset SNR adjustment |
|
| 189 |
- * @param[in] floor noise floor |
|
| 190 |
- * @param[in] bap_tab look-up table for bit allocation pointers |
|
| 191 |
- * @param[out] bap bit allocation pointers |
|
| 192 |
- */ |
|
| 193 |
-void ff_ac3_bit_alloc_calc_bap(int16_t *mask, int16_t *psd, int start, int end, |
|
| 194 |
- int snr_offset, int floor, |
|
| 195 |
- const uint8_t *bap_tab, uint8_t *bap); |
|
| 196 |
- |
|
| 197 | 178 |
#endif /* AVCODEC_AC3_H */ |
| ... | ... |
@@ -184,6 +184,7 @@ static av_cold int ac3_decode_init(AVCodecContext *avctx) |
| 184 | 184 |
ff_mdct_init(&s->imdct_512, 9, 1, 1.0); |
| 185 | 185 |
ff_kbd_window_init(s->window, 5.0, 256); |
| 186 | 186 |
dsputil_init(&s->dsp, avctx); |
| 187 |
+ ff_ac3dsp_init(&s->ac3dsp, avctx->flags & CODEC_FLAG_BITEXACT); |
|
| 187 | 188 |
ff_fmt_convert_init(&s->fmt_conv, avctx); |
| 188 | 189 |
av_lfg_init(&s->dith_state, 0); |
| 189 | 190 |
|
| ... | ... |
@@ -1213,7 +1214,7 @@ static int decode_audio_block(AC3DecodeContext *s, int blk) |
| 1213 | 1213 |
/* Compute bit allocation */ |
| 1214 | 1214 |
const uint8_t *bap_tab = s->channel_uses_aht[ch] ? |
| 1215 | 1215 |
ff_eac3_hebap_tab : ff_ac3_bap_tab; |
| 1216 |
- ff_ac3_bit_alloc_calc_bap(s->mask[ch], s->psd[ch], |
|
| 1216 |
+ s->ac3dsp.bit_alloc_calc_bap(s->mask[ch], s->psd[ch], |
|
| 1217 | 1217 |
s->start_freq[ch], s->end_freq[ch], |
| 1218 | 1218 |
s->snr_offset[ch], |
| 1219 | 1219 |
s->bit_alloc_params.floor, |
| ... | ... |
@@ -52,6 +52,7 @@ |
| 52 | 52 |
|
| 53 | 53 |
#include "libavutil/lfg.h" |
| 54 | 54 |
#include "ac3.h" |
| 55 |
+#include "ac3dsp.h" |
|
| 55 | 56 |
#include "get_bits.h" |
| 56 | 57 |
#include "dsputil.h" |
| 57 | 58 |
#include "fft.h" |
| ... | ... |
@@ -192,6 +193,7 @@ typedef struct {
|
| 192 | 192 |
|
| 193 | 193 |
///@defgroup opt optimization |
| 194 | 194 |
DSPContext dsp; ///< for optimization |
| 195 |
+ AC3DSPContext ac3dsp; |
|
| 195 | 196 |
FmtConvertContext fmt_conv; ///< optimized conversion functions |
| 196 | 197 |
float mul_bias; ///< scaling for float_to_int16 conversion |
| 197 | 198 |
///@} |
| ... | ... |
@@ -20,6 +20,7 @@ |
| 20 | 20 |
*/ |
| 21 | 21 |
|
| 22 | 22 |
#include "avcodec.h" |
| 23 |
+#include "ac3.h" |
|
| 23 | 24 |
#include "ac3dsp.h" |
| 24 | 25 |
|
| 25 | 26 |
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) |
| 101 | 101 |
} while (len > 0); |
| 102 | 102 |
} |
| 103 | 103 |
|
| 104 |
+static void ac3_bit_alloc_calc_bap_c(int16_t *mask, int16_t *psd, |
|
| 105 |
+ int start, int end, |
|
| 106 |
+ int snr_offset, int floor, |
|
| 107 |
+ const uint8_t *bap_tab, uint8_t *bap) |
|
| 108 |
+{
|
|
| 109 |
+ int bin, band; |
|
| 110 |
+ |
|
| 111 |
+ /* special case, if snr offset is -960, set all bap's to zero */ |
|
| 112 |
+ if (snr_offset == -960) {
|
|
| 113 |
+ memset(bap, 0, AC3_MAX_COEFS); |
|
| 114 |
+ return; |
|
| 115 |
+ } |
|
| 116 |
+ |
|
| 117 |
+ bin = start; |
|
| 118 |
+ band = ff_ac3_bin_to_band_tab[start]; |
|
| 119 |
+ do {
|
|
| 120 |
+ int m = (FFMAX(mask[band] - snr_offset - floor, 0) & 0x1FE0) + floor; |
|
| 121 |
+ int band_end = FFMIN(ff_ac3_band_start_tab[band+1], end); |
|
| 122 |
+ for (; bin < band_end; bin++) {
|
|
| 123 |
+ int address = av_clip((psd[bin] - m) >> 5, 0, 63); |
|
| 124 |
+ bap[bin] = bap_tab[address]; |
|
| 125 |
+ } |
|
| 126 |
+ } while (end > ff_ac3_band_start_tab[band++]); |
|
| 127 |
+} |
|
| 128 |
+ |
|
| 104 | 129 |
av_cold void ff_ac3dsp_init(AC3DSPContext *c, int bit_exact) |
| 105 | 130 |
{
|
| 106 | 131 |
c->ac3_exponent_min = ac3_exponent_min_c; |
| ... | ... |
@@ -108,6 +134,7 @@ av_cold void ff_ac3dsp_init(AC3DSPContext *c, int bit_exact) |
| 108 | 108 |
c->ac3_lshift_int16 = ac3_lshift_int16_c; |
| 109 | 109 |
c->ac3_rshift_int32 = ac3_rshift_int32_c; |
| 110 | 110 |
c->float_to_fixed24 = float_to_fixed24_c; |
| 111 |
+ c->bit_alloc_calc_bap = ac3_bit_alloc_calc_bap_c; |
|
| 111 | 112 |
|
| 112 | 113 |
if (ARCH_ARM) |
| 113 | 114 |
ff_ac3dsp_init_arm(c, bit_exact); |
| ... | ... |
@@ -81,6 +81,25 @@ typedef struct AC3DSPContext {
|
| 81 | 81 |
* constraints: multiple of 32 greater than zero |
| 82 | 82 |
*/ |
| 83 | 83 |
void (*float_to_fixed24)(int32_t *dst, const float *src, unsigned int len); |
| 84 |
+ |
|
| 85 |
+ /** |
|
| 86 |
+ * Calculate bit allocation pointers. |
|
| 87 |
+ * The SNR is the difference between the masking curve and the signal. AC-3 |
|
| 88 |
+ * uses this value for each frequency bin to allocate bits. The snroffset |
|
| 89 |
+ * parameter is a global adjustment to the SNR for all bins. |
|
| 90 |
+ * |
|
| 91 |
+ * @param[in] mask masking curve |
|
| 92 |
+ * @param[in] psd signal power for each frequency bin |
|
| 93 |
+ * @param[in] start starting bin location |
|
| 94 |
+ * @param[in] end ending bin location |
|
| 95 |
+ * @param[in] snr_offset SNR adjustment |
|
| 96 |
+ * @param[in] floor noise floor |
|
| 97 |
+ * @param[in] bap_tab look-up table for bit allocation pointers |
|
| 98 |
+ * @param[out] bap bit allocation pointers |
|
| 99 |
+ */ |
|
| 100 |
+ void (*bit_alloc_calc_bap)(int16_t *mask, int16_t *psd, int start, int end, |
|
| 101 |
+ int snr_offset, int floor, |
|
| 102 |
+ const uint8_t *bap_tab, uint8_t *bap); |
|
| 84 | 103 |
} AC3DSPContext; |
| 85 | 104 |
|
| 86 | 105 |
void ff_ac3dsp_init (AC3DSPContext *c, int bit_exact); |
| ... | ... |
@@ -1047,7 +1047,7 @@ static int bit_alloc(AC3EncodeContext *s, int snr_offset) |
| 1047 | 1047 |
whenever we reuse exponents. */ |
| 1048 | 1048 |
block = s->blocks[blk].exp_ref_block[ch]; |
| 1049 | 1049 |
if (s->exp_strategy[ch][blk] != EXP_REUSE) {
|
| 1050 |
- ff_ac3_bit_alloc_calc_bap(block->mask[ch], block->psd[ch], 0, |
|
| 1050 |
+ s->ac3dsp.bit_alloc_calc_bap(block->mask[ch], block->psd[ch], 0, |
|
| 1051 | 1051 |
s->nb_coefs[ch], snr_offset, |
| 1052 | 1052 |
s->bit_alloc.floor, ff_ac3_bap_tab, |
| 1053 | 1053 |
block->bap[ch]); |
| ... | ... |
@@ -25,6 +25,12 @@ |
| 25 | 25 |
#include "libavutil/common.h" |
| 26 | 26 |
#include "ac3.h" |
| 27 | 27 |
|
| 28 |
+#if CONFIG_HARDCODED_TABLES |
|
| 29 |
+# define HCONST const |
|
| 30 |
+#else |
|
| 31 |
+# define HCONST |
|
| 32 |
+#endif |
|
| 33 |
+ |
|
| 28 | 34 |
extern const uint16_t ff_ac3_frame_size_tab[38][3]; |
| 29 | 35 |
extern const uint8_t ff_ac3_channels_tab[8]; |
| 30 | 36 |
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]; |
| 44 | 44 |
extern const int16_t ff_ac3_floor_tab[8]; |
| 45 | 45 |
extern const uint16_t ff_ac3_fast_gain_tab[8]; |
| 46 | 46 |
extern const uint16_t ff_eac3_default_chmap[8]; |
| 47 |
+extern const uint8_t ff_ac3_band_start_tab[AC3_CRITICAL_BANDS+1]; |
|
| 48 |
+extern HCONST uint8_t ff_ac3_bin_to_band_tab[253]; |
|
| 47 | 49 |
|
| 48 | 50 |
/** Custom channel map locations bitmask |
| 49 | 51 |
* Other channels described in documentation: |