summaryrefslogtreecommitdiff
path: root/libavcodec/ac3dsp.c
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2011-03-30 03:01:41 +0200
committerMichael Niedermayer <michaelni@gmx.at>2011-03-30 03:09:08 +0200
commit445fdc014017a236fa7aa2645ffad7e8d0b45bee (patch)
tree1bd6be8b1dbf95535926c0e1348c63027ecb4339 /libavcodec/ac3dsp.c
parent55ce3c67bb25cd44889f2143ce9fd7dac3ab4a9d (diff)
parent52fd16a264d1eb14b1a84b7b38041da1756fb216 (diff)
Merge remote-tracking branch 'newdev/master'
* newdev/master: ac3enc: move compute_mantissa_size() to ac3dsp ac3enc: move mant*_cnt and qmant*_ptr out of AC3EncodeContext Remove support for stripping executables ac3enc: NEON optimised float_to_fixed24 ac3: move ff_ac3_bit_alloc_calc_bap to ac3dsp dfa: protect pointer range checks against overflows. Duplicate: mimic: implement multithreading. Merged-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavcodec/ac3dsp.c')
-rw-r--r--libavcodec/ac3dsp.c50
1 files changed, 50 insertions, 0 deletions
diff --git a/libavcodec/ac3dsp.c b/libavcodec/ac3dsp.c
index 511a94f212..ec0b82d4fc 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,53 @@ 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++]);
+}
+
+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;
@@ -108,6 +156,8 @@ 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;
+ c->compute_mantissa_size = ac3_compute_mantissa_size_c;
if (ARCH_ARM)
ff_ac3dsp_init_arm(c, bit_exact);