Unified · Split
| @@ -48,6 +48,9 @@ · 47 unmodified lines | |||
| 48 | extern const AACDecDSP aac_dsp; | 48 | extern const AACDecDSP aac_dsp; |
| 49 | extern const AACDecDSP aac_dsp_fixed; | 49 | extern const AACDecDSP aac_dsp_fixed; |
| 50 | 50 | ||
| 51 | extern const AACDecProc aac_proc; | ||
| 52 | extern const AACDecProc aac_proc_fixed; | ||
| 53 | |||
| 51 | av_cold int ff_aac_decode_close(AVCodecContext *avctx) | 54 | av_cold int ff_aac_decode_close(AVCodecContext *avctx) |
| 52 | { | 55 | { |
| 53 | AACDecContext *ac = avctx->priv_data; | 56 | AACDecContext *ac = avctx->priv_data; |
| @@ -119,6 +122,7 @@ av_cold int ff_aac_decode_init_common(AVCodecContext *avctx) · 65 unmodified lines | |||
| 119 | return ret; | 122 | return ret; |
| 120 | 123 | ||
| 121 | ac->dsp = is_fixed ? aac_dsp_fixed : aac_dsp; | 124 | ac->dsp = is_fixed ? aac_dsp_fixed : aac_dsp; |
| 125 | ac->proc = is_fixed ? aac_proc_fixed : aac_proc; | ||
| 122 | 126 | ||
| 123 | ac->dsp.init_tables(); | 127 | ac->dsp.init_tables(); |
| 124 | 128 | ||
| @@ -151,7 +151,7 @@ static void AAC_RENAME(apply_intensity_stereo)(AACDecContext *ac, · 150 unmodified lines | |||
| 151 | scale = c * sce1->AAC_RENAME(sf)[idx]; | 151 | scale = c * sce1->AAC_RENAME(sf)[idx]; |
| 152 | for (group = 0; group < ics->group_len[g]; group++) | 152 | for (group = 0; group < ics->group_len[g]; group++) |
| 153 | #if USE_FIXED | 153 | #if USE_FIXED |
| 154 | ac->subband_scale(coef1 + group * 128 + offsets[i], | 154 | subband_scale(coef1 + group * 128 + offsets[i], |
| 155 | coef0 + group * 128 + offsets[i], | 155 | coef0 + group * 128 + offsets[i], |
| 156 | scale, | 156 | scale, |
| 157 | 23, | 157 | 23, |
| @@ -38,6 +38,7 @@ · 37 unmodified lines | |||
| 38 | #include "libavcodec/aactab.h" | 38 | #include "libavcodec/aactab.h" |
| 39 | #include "libavcodec/sinewin_fixed_tablegen.h" | 39 | #include "libavcodec/sinewin_fixed_tablegen.h" |
| 40 | #include "libavcodec/kbdwin.h" | 40 | #include "libavcodec/kbdwin.h" |
| 41 | #include "libavcodec/cbrt_data.h" | ||
| 41 | 42 | ||
| 42 | DECLARE_ALIGNED(32, static INTFLOAT, AAC_RENAME2(aac_kbd_long_1024))[1024]; | 43 | DECLARE_ALIGNED(32, static INTFLOAT, AAC_RENAME2(aac_kbd_long_1024))[1024]; |
| 43 | DECLARE_ALIGNED(32, static INTFLOAT, AAC_RENAME2(aac_kbd_short_128))[128]; | 44 | DECLARE_ALIGNED(32, static INTFLOAT, AAC_RENAME2(aac_kbd_short_128))[128]; |
| @@ -61,4 +62,8 @@ static void init_tables_fixed(void) · 17 unmodified lines | |||
| 61 | ff_thread_once(&init_fixed_once, init_tables_fixed_fn); | 62 | ff_thread_once(&init_fixed_once, init_tables_fixed_fn); |
| 62 | } | 63 | } |
| 63 | 64 | ||
| 65 | /** Dequantization-related */ | ||
| 66 | #include "aacdec_fixed_dequant.h" | ||
| 67 | |||
| 64 | #include "aacdec_dsp_template.c" | 68 | #include "aacdec_dsp_template.c" |
| 69 | #include "aacdec_proc_template.c" | ||
| @@ -0,0 +1,174 @@ | |||
| 1 | /* | ||
| 2 | * AAC decoder | ||
| 3 | * Copyright (c) 2005-2006 Oded Shimon ( ods15 ods15 dyndns org ) | ||
| 4 | * Copyright (c) 2006-2007 Maxim Gavrilov ( maxim.gavrilov gmail com ) | ||
| 5 | * Copyright (c) 2008-2013 Alex Converse <alex.converse@gmail.com> | ||
| 6 | * | ||
| 7 | * AAC LATM decoder | ||
| 8 | * Copyright (c) 2008-2010 Paul Kendall <paul@kcbbs.gen.nz> | ||
| 9 | * Copyright (c) 2010 Janne Grunau <janne-libav@jannau.net> | ||
| 10 | * | ||
| 11 | * AAC decoder fixed-point implementation | ||
| 12 | * Copyright (c) 2013 | ||
| 13 | * MIPS Technologies, Inc., California. | ||
| 14 | * | ||
| 15 | * This file is part of FFmpeg. | ||
| 16 | * | ||
| 17 | * FFmpeg is free software; you can redistribute it and/or | ||
| 18 | * modify it under the terms of the GNU Lesser General Public | ||
| 19 | * License as published by the Free Software Foundation; either | ||
| 20 | * version 2.1 of the License, or (at your option) any later version. | ||
| 21 | * | ||
| 22 | * FFmpeg is distributed in the hope that it will be useful, | ||
| 23 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 24 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 25 | * Lesser General Public License for more details. | ||
| 26 | * | ||
| 27 | * You should have received a copy of the GNU Lesser General Public | ||
| 28 | * License along with FFmpeg; if not, write to the Free Software | ||
| 29 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 30 | */ | ||
| 31 | |||
| 32 | #ifndef AVCODEC_AAC_AACDEC_FIXED_DEQUANT_H | ||
| 33 | #define AVCODEC_AAC_AACDEC_FIXED_DEQUANT_H | ||
| 34 | |||
| 35 | #include "aacdec_tab.h" | ||
| 36 | |||
| 37 | static void inline vector_pow43(int *coefs, int len) | ||
| 38 | { | ||
| 39 | int i, coef; | ||
| 40 | |||
| 41 | for (i=0; i<len; i++) { | ||
| 42 | coef = coefs[i]; | ||
| 43 | if (coef < 0) | ||
| 44 | coef = -(int)ff_cbrt_tab_fixed[(-coef) & 8191]; | ||
| 45 | else | ||
| 46 | coef = (int)ff_cbrt_tab_fixed[ coef & 8191]; | ||
| 47 | coefs[i] = coef; | ||
| 48 | } | ||
| 49 | } | ||
| 50 | |||
| 51 | /* 2^0, 2^0.25, 2^0.5, 2^0.75 */ | ||
| 52 | static const int exp2tab[4] = { | ||
| 53 | Q31(1.0000000000/2), Q31(1.1892071150/2), | ||
| 54 | Q31(1.4142135624/2), Q31(1.6817928305/2) | ||
| 55 | }; | ||
| 56 | |||
| 57 | static void inline subband_scale(int *dst, int *src, int scale, | ||
| 58 | int offset, int len, void *log_context) | ||
| 59 | { | ||
| 60 | int ssign = scale < 0 ? -1 : 1; | ||
| 61 | int s = FFABS(scale); | ||
| 62 | unsigned int round; | ||
| 63 | int i, out, c = exp2tab[s & 3]; | ||
| 64 | |||
| 65 | s = offset - (s >> 2); | ||
| 66 | |||
| 67 | if (s > 31) { | ||
| 68 | for (i=0; i<len; i++) { | ||
| 69 | dst[i] = 0; | ||
| 70 | } | ||
| 71 | } else if (s > 0) { | ||
| 72 | round = 1 << (s-1); | ||
| 73 | for (i=0; i<len; i++) { | ||
| 74 | out = (int)(((int64_t)src[i] * c) >> 32); | ||
| 75 | dst[i] = ((int)(out+round) >> s) * ssign; | ||
| 76 | } | ||
| 77 | } else if (s > -32) { | ||
| 78 | s = s + 32; | ||
| 79 | round = 1U << (s-1); | ||
| 80 | for (i=0; i<len; i++) { | ||
| 81 | out = (int)((int64_t)((int64_t)src[i] * c + round) >> s); | ||
| 82 | dst[i] = out * (unsigned)ssign; | ||
| 83 | } | ||
| 84 | } else { | ||
| 85 | av_log(log_context, AV_LOG_ERROR, "Overflow in subband_scale()\n"); | ||
| 86 | } | ||
| 87 | } | ||
| 88 | |||
| 89 | static void noise_scale(int *coefs, int scale, int band_energy, int len) | ||
| 90 | { | ||
| 91 | int s = -scale; | ||
| 92 | unsigned int round; | ||
| 93 | int i, out, c = exp2tab[s & 3]; | ||
| 94 | int nlz = 0; | ||
| 95 | |||
| 96 | av_assert0(s >= 0); | ||
| 97 | while (band_energy > 0x7fff) { | ||
| 98 | band_energy >>= 1; | ||
| 99 | nlz++; | ||
| 100 | } | ||
| 101 | c /= band_energy; | ||
| 102 | s = 21 + nlz - (s >> 2); | ||
| 103 | |||
| 104 | if (s > 31) { | ||
| 105 | for (i=0; i<len; i++) { | ||
| 106 | coefs[i] = 0; | ||
| 107 | } | ||
| 108 | } else if (s >= 0) { | ||
| 109 | round = s ? 1 << (s-1) : 0; | ||
| 110 | for (i=0; i<len; i++) { | ||
| 111 | out = (int)(((int64_t)coefs[i] * c) >> 32); | ||
| 112 | coefs[i] = -((int)(out+round) >> s); | ||
| 113 | } | ||
| 114 | } | ||
| 115 | else { | ||
| 116 | s = s + 32; | ||
| 117 | if (s > 0) { | ||
| 118 | round = 1 << (s-1); | ||
| 119 | for (i=0; i<len; i++) { | ||
| 120 | out = (int)((int64_t)((int64_t)coefs[i] * c + round) >> s); | ||
| 121 | coefs[i] = -out; | ||
| 122 | } | ||
| 123 | } else { | ||
| 124 | for (i=0; i<len; i++) | ||
| 125 | coefs[i] = -(int64_t)coefs[i] * c * (1 << -s); | ||
| 126 | } | ||
| 127 | } | ||
| 128 | } | ||
| 129 | |||
| 130 | static inline int *DEC_SPAIR(int *dst, unsigned idx) | ||
| 131 | { | ||
| 132 | dst[0] = (idx & 15) - 4; | ||
| 133 | dst[1] = (idx >> 4 & 15) - 4; | ||
| 134 | |||
| 135 | return dst + 2; | ||
| 136 | } | ||
| 137 | |||
| 138 | static inline int *DEC_SQUAD(int *dst, unsigned idx) | ||
| 139 | { | ||
| 140 | dst[0] = (idx & 3) - 1; | ||
| 141 | dst[1] = (idx >> 2 & 3) - 1; | ||
| 142 | dst[2] = (idx >> 4 & 3) - 1; | ||
| 143 | dst[3] = (idx >> 6 & 3) - 1; | ||
| 144 | |||
| 145 | return dst + 4; | ||
| 146 | } | ||
| 147 | |||
| 148 | static inline int *DEC_UPAIR(int *dst, unsigned idx, unsigned sign) | ||
| 149 | { | ||
| 150 | dst[0] = (idx & 15) * (1 - (sign & 0xFFFFFFFE)); | ||
| 151 | dst[1] = (idx >> 4 & 15) * (1 - ((sign & 1) * 2)); | ||
| 152 | |||
| 153 | return dst + 2; | ||
| 154 | } | ||
| 155 | |||
| 156 | static inline int *DEC_UQUAD(int *dst, unsigned idx, unsigned sign) | ||
| 157 | { | ||
| 158 | unsigned nz = idx >> 12; | ||
| 159 | |||
| 160 | dst[0] = (idx & 3) * (1 + (((int)sign >> 31) * 2)); | ||
| 161 | sign <<= nz & 1; | ||
| 162 | nz >>= 1; | ||
| 163 | dst[1] = (idx >> 2 & 3) * (1 + (((int)sign >> 31) * 2)); | ||
| 164 | sign <<= nz & 1; | ||
| 165 | nz >>= 1; | ||
| 166 | dst[2] = (idx >> 4 & 3) * (1 + (((int)sign >> 31) * 2)); | ||
| 167 | sign <<= nz & 1; | ||
| 168 | nz >>= 1; | ||
| 169 | dst[3] = (idx >> 6 & 3) * (1 + (((int)sign >> 31) * 2)); | ||
| 170 | |||
| 171 | return dst + 4; | ||
| 172 | } | ||
| 173 | |||
| 174 | #endif /* AVCODEC_AAC_AACDEC_FIXED_DEQUANT_H */ | ||
| @@ -38,6 +38,7 @@ · 37 unmodified lines | |||
| 38 | #include "libavcodec/aactab.h" | 38 | #include "libavcodec/aactab.h" |
| 39 | #include "libavcodec/sinewin.h" | 39 | #include "libavcodec/sinewin.h" |
| 40 | #include "libavcodec/kbdwin.h" | 40 | #include "libavcodec/kbdwin.h" |
| 41 | #include "libavcodec/cbrt_data.h" | ||
| 41 | 42 | ||
| 42 | DECLARE_ALIGNED(32, static float, sine_120)[120]; | 43 | DECLARE_ALIGNED(32, static float, sine_120)[120]; |
| 43 | DECLARE_ALIGNED(32, static float, sine_960)[960]; | 44 | DECLARE_ALIGNED(32, static float, sine_960)[960]; |
| @@ -63,4 +64,77 @@ static void init_tables(void) · 19 unmodified lines | |||
| 63 | ff_thread_once(&init_float_once, init_tables_float_fn); | 64 | ff_thread_once(&init_float_once, init_tables_float_fn); |
| 64 | } | 65 | } |
| 65 | 66 | ||
| 67 | /** Dequantization-related **/ | ||
| 68 | #include "aacdec_tab.h" | ||
| 69 | #include "libavutil/intfloat.h" | ||
| 70 | |||
| 71 | #ifndef VMUL2 | ||
| 72 | static inline float *VMUL2(float *dst, const float *v, unsigned idx, | ||
| 73 | const float *scale) | ||
| 74 | { | ||
| 75 | float s = *scale; | ||
| 76 | *dst++ = v[idx & 15] * s; | ||
| 77 | *dst++ = v[idx>>4 & 15] * s; | ||
| 78 | return dst; | ||
| 79 | } | ||
| 80 | #endif | ||
| 81 | |||
| 82 | #ifndef VMUL4 | ||
| 83 | static inline float *VMUL4(float *dst, const float *v, unsigned idx, | ||
| 84 | const float *scale) | ||
| 85 | { | ||
| 86 | float s = *scale; | ||
| 87 | *dst++ = v[idx & 3] * s; | ||
| 88 | *dst++ = v[idx>>2 & 3] * s; | ||
| 89 | *dst++ = v[idx>>4 & 3] * s; | ||
| 90 | *dst++ = v[idx>>6 & 3] * s; | ||
| 91 | return dst; | ||
| 92 | } | ||
| 93 | #endif | ||
| 94 | |||
| 95 | #ifndef VMUL2S | ||
| 96 | static inline float *VMUL2S(float *dst, const float *v, unsigned idx, | ||
| 97 | unsigned sign, const float *scale) | ||
| 98 | { | ||
| 99 | union av_intfloat32 s0, s1; | ||
| 100 | |||
| 101 | s0.f = s1.f = *scale; | ||
| 102 | s0.i ^= sign >> 1 << 31; | ||
| 103 | s1.i ^= sign << 31; | ||
| 104 | |||
| 105 | *dst++ = v[idx & 15] * s0.f; | ||
| 106 | *dst++ = v[idx>>4 & 15] * s1.f; | ||
| 107 | |||
| 108 | return dst; | ||
| 109 | } | ||
| 110 | #endif | ||
| 111 | |||
| 112 | #ifndef VMUL4S | ||
| 113 | static inline float *VMUL4S(float *dst, const float *v, unsigned idx, | ||
| 114 | unsigned sign, const float *scale) | ||
| 115 | { | ||
| 116 | unsigned nz = idx >> 12; | ||
| 117 | union av_intfloat32 s = { .f = *scale }; | ||
| 118 | union av_intfloat32 t; | ||
| 119 | |||
| 120 | t.i = s.i ^ (sign & 1U<<31); | ||
| 121 | *dst++ = v[idx & 3] * t.f; | ||
| 122 | |||
| 123 | sign <<= nz & 1; nz >>= 1; | ||
| 124 | t.i = s.i ^ (sign & 1U<<31); | ||
| 125 | *dst++ = v[idx>>2 & 3] * t.f; | ||
| 126 | |||
| 127 | sign <<= nz & 1; nz >>= 1; | ||
| 128 | t.i = s.i ^ (sign & 1U<<31); | ||
| 129 | *dst++ = v[idx>>4 & 3] * t.f; | ||
| 130 | |||
| 131 | sign <<= nz & 1; | ||
| 132 | t.i = s.i ^ (sign & 1U<<31); | ||
| 133 | *dst++ = v[idx>>6 & 3] * t.f; | ||
| 134 | |||
| 135 | return dst; | ||
| 136 | } | ||
| 137 | #endif | ||
| 138 | |||
| 66 | #include "aacdec_dsp_template.c" | 139 | #include "aacdec_dsp_template.c" |
| 140 | #include "aacdec_proc_template.c" | ||
| @@ -0,0 +1,354 @@ | |||
| 1 | /* | ||
| 2 | * AAC decoder | ||
| 3 | * Copyright (c) 2005-2006 Oded Shimon ( ods15 ods15 dyndns org ) | ||
| 4 | * Copyright (c) 2006-2007 Maxim Gavrilov ( maxim.gavrilov gmail com ) | ||
| 5 | * Copyright (c) 2008-2013 Alex Converse <alex.converse@gmail.com> | ||
| 6 | * | ||
| 7 | * AAC LATM decoder | ||
| 8 | * Copyright (c) 2008-2010 Paul Kendall <paul@kcbbs.gen.nz> | ||
| 9 | * Copyright (c) 2010 Janne Grunau <janne-libav@jannau.net> | ||
| 10 | * | ||
| 11 | * AAC decoder fixed-point implementation | ||
| 12 | * Copyright (c) 2013 | ||
| 13 | * MIPS Technologies, Inc., California. | ||
| 14 | * | ||
| 15 | * This file is part of FFmpeg. | ||
| 16 | * | ||
| 17 | * FFmpeg is free software; you can redistribute it and/or | ||
| 18 | * modify it under the terms of the GNU Lesser General Public | ||
| 19 | * License as published by the Free Software Foundation; either | ||
| 20 | * version 2.1 of the License, or (at your option) any later version. | ||
| 21 | * | ||
| 22 | * FFmpeg is distributed in the hope that it will be useful, | ||
| 23 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 24 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 25 | * Lesser General Public License for more details. | ||
| 26 | * | ||
| 27 | * You should have received a copy of the GNU Lesser General Public | ||
| 28 | * License along with FFmpeg; if not, write to the Free Software | ||
| 29 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 30 | */ | ||
| 31 | |||
| 32 | /** | ||
| 33 | * linear congruential pseudorandom number generator | ||
| 34 | * | ||
| 35 | * @param previous_val pointer to the current state of the generator | ||
| 36 | * | ||
| 37 | * @return Returns a 32-bit pseudorandom integer | ||
| 38 | */ | ||
| 39 | static av_always_inline int lcg_random(unsigned previous_val) | ||
| 40 | { | ||
| 41 | union { unsigned u; int s; } v = { previous_val * 1664525u + 1013904223 }; | ||
| 42 | return v.s; | ||
| 43 | } | ||
| 44 | |||
| 45 | /** | ||
| 46 | * Decode spectral data; reference: table 4.50. | ||
| 47 | * Dequantize and scale spectral data; reference: 4.6.3.3. | ||
| 48 | * | ||
| 49 | * @param coef array of dequantized, scaled spectral data | ||
| 50 | * @param sf array of scalefactors or intensity stereo positions | ||
| 51 | * @param pulse_present set if pulses are present | ||
| 52 | * @param pulse pointer to pulse data struct | ||
| 53 | * @param band_type array of the used band type | ||
| 54 | * | ||
| 55 | * @return Returns error status. 0 - OK, !0 - error | ||
| 56 | */ | ||
| 57 | static int AAC_RENAME(decode_spectrum_and_dequant)(AACDecContext *ac, | ||
| 58 | GetBitContext *gb, | ||
| 59 | const Pulse *pulse, | ||
| 60 | SingleChannelElement *sce) | ||
| 61 | { | ||
| 62 | int i, k, g, idx = 0; | ||
| 63 | INTFLOAT *coef = sce->AAC_RENAME(coeffs); | ||
| 64 | IndividualChannelStream *ics = &sce->ics; | ||
| 65 | const int c = 1024 / ics->num_windows; | ||
| 66 | const uint16_t *offsets = ics->swb_offset; | ||
| 67 | const INTFLOAT *sf = sce->AAC_RENAME(sf); | ||
| 68 | const enum BandType *band_type = sce->band_type; | ||
| 69 | INTFLOAT *coef_base = coef; | ||
| 70 | |||
| 71 | for (g = 0; g < ics->num_windows; g++) | ||
| 72 | memset(coef + g * 128 + offsets[ics->max_sfb], 0, | ||
| 73 | sizeof(INTFLOAT) * (c - offsets[ics->max_sfb])); | ||
| 74 | |||
| 75 | for (g = 0; g < ics->num_window_groups; g++) { | ||
| 76 | unsigned g_len = ics->group_len[g]; | ||
| 77 | |||
| 78 | for (i = 0; i < ics->max_sfb; i++, idx++) { | ||
| 79 | const unsigned cbt_m1 = band_type[idx] - 1; | ||
| 80 | INTFLOAT *cfo = coef + offsets[i]; | ||
| 81 | int off_len = offsets[i + 1] - offsets[i]; | ||
| 82 | int group; | ||
| 83 | |||
| 84 | if (cbt_m1 >= INTENSITY_BT2 - 1) { | ||
| 85 | for (group = 0; group < (AAC_SIGNE)g_len; group++, cfo+=128) { | ||
| 86 | memset(cfo, 0, off_len * sizeof(*cfo)); | ||
| 87 | } | ||
| 88 | } else if (cbt_m1 == NOISE_BT - 1) { | ||
| 89 | for (group = 0; group < (AAC_SIGNE)g_len; group++, cfo+=128) { | ||
| 90 | INTFLOAT band_energy; | ||
| 91 | #if USE_FIXED | ||
| 92 | for (k = 0; k < off_len; k++) { | ||
| 93 | ac->random_state = lcg_random(ac->random_state); | ||
| 94 | cfo[k] = ac->random_state >> 3; | ||
| 95 | } | ||
| 96 | |||
| 97 | band_energy = ac->fdsp->scalarproduct_fixed(cfo, cfo, off_len); | ||
| 98 | band_energy = fixed_sqrt(band_energy, 31); | ||
| 99 | noise_scale(cfo, sf[idx], band_energy, off_len); | ||
| 100 | #else | ||
| 101 | float scale; | ||
| 102 | |||
| 103 | for (k = 0; k < off_len; k++) { | ||
| 104 | ac->random_state = lcg_random(ac->random_state); | ||
| 105 | cfo[k] = ac->random_state; | ||
| 106 | } | ||
| 107 | |||
| 108 | band_energy = ac->fdsp->scalarproduct_float(cfo, cfo, off_len); | ||
| 109 | scale = sf[idx] / sqrtf(band_energy); | ||
| 110 | ac->fdsp->vector_fmul_scalar(cfo, cfo, scale, off_len); | ||
| 111 | #endif /* USE_FIXED */ | ||
| 112 | } | ||
| 113 | } else { | ||
| 114 | #if !USE_FIXED | ||
| 115 | const float *vq = ff_aac_codebook_vector_vals[cbt_m1]; | ||
| 116 | #endif /* !USE_FIXED */ | ||
| 117 | const VLCElem *vlc_tab = ff_vlc_spectral[cbt_m1]; | ||
| 118 | OPEN_READER(re, gb); | ||
| 119 | |||
| 120 | switch (cbt_m1 >> 1) { | ||
| 121 | case 0: | ||
| 122 | for (group = 0; group < (AAC_SIGNE)g_len; group++, cfo+=128) { | ||
| 123 | INTFLOAT *cf = cfo; | ||
| 124 | int len = off_len; | ||
| 125 | |||
| 126 | do { | ||
| 127 | int code; | ||
| 128 | unsigned cb_idx; | ||
| 129 | |||
| 130 | UPDATE_CACHE(re, gb); | ||
| 131 | GET_VLC(code, re, gb, vlc_tab, 8, 2); | ||
| 132 | cb_idx = code; | ||
| 133 | #if USE_FIXED | ||
| 134 | cf = DEC_SQUAD(cf, cb_idx); | ||
| 135 | #else | ||
| 136 | cf = VMUL4(cf, vq, cb_idx, sf + idx); | ||
| 137 | #endif /* USE_FIXED */ | ||
| 138 | } while (len -= 4); | ||
| 139 | } | ||
| 140 | break; | ||
| 141 | |||
| 142 | case 1: | ||
| 143 | for (group = 0; group < (AAC_SIGNE)g_len; group++, cfo+=128) { | ||
| 144 | INTFLOAT *cf = cfo; | ||
| 145 | int len = off_len; | ||
| 146 | |||
| 147 | do { | ||
| 148 | int code; | ||
| 149 | unsigned nnz; | ||
| 150 | unsigned cb_idx; | ||
| 151 | uint32_t bits; | ||
| 152 | |||
| 153 | UPDATE_CACHE(re, gb); | ||
| 154 | GET_VLC(code, re, gb, vlc_tab, 8, 2); | ||
| 155 | cb_idx = code; | ||
| 156 | nnz = cb_idx >> 8 & 15; | ||
| 157 | bits = nnz ? GET_CACHE(re, gb) : 0; | ||
| 158 | LAST_SKIP_BITS(re, gb, nnz); | ||
| 159 | #if USE_FIXED | ||
| 160 | cf = DEC_UQUAD(cf, cb_idx, bits); | ||
| 161 | #else | ||
| 162 | cf = VMUL4S(cf, vq, cb_idx, bits, sf + idx); | ||
| 163 | #endif /* USE_FIXED */ | ||
| 164 | } while (len -= 4); | ||
| 165 | } | ||
| 166 | break; | ||
| 167 | |||
| 168 | case 2: | ||
| 169 | for (group = 0; group < (AAC_SIGNE)g_len; group++, cfo+=128) { | ||
| 170 | INTFLOAT *cf = cfo; | ||
| 171 | int len = off_len; | ||
| 172 | |||
| 173 | do { | ||
| 174 | int code; | ||
| 175 | unsigned cb_idx; | ||
| 176 | |||
| 177 | UPDATE_CACHE(re, gb); | ||
| 178 | GET_VLC(code, re, gb, vlc_tab, 8, 2); | ||
| 179 | cb_idx = code; | ||
| 180 | #if USE_FIXED | ||
| 181 | cf = DEC_SPAIR(cf, cb_idx); | ||
| 182 | #else | ||
| 183 | cf = VMUL2(cf, vq, cb_idx, sf + idx); | ||
| 184 | #endif /* USE_FIXED */ | ||
| 185 | } while (len -= 2); | ||
| 186 | } | ||
| 187 | break; | ||
| 188 | |||
| 189 | case 3: | ||
| 190 | case 4: | ||
| 191 | for (group = 0; group < (AAC_SIGNE)g_len; group++, cfo+=128) { | ||
| 192 | INTFLOAT *cf = cfo; | ||
| 193 | int len = off_len; | ||
| 194 | |||
| 195 | do { | ||
| 196 | int code; | ||
| 197 | unsigned nnz; | ||
| 198 | unsigned cb_idx; | ||
| 199 | unsigned sign; | ||
| 200 | |||
| 201 | UPDATE_CACHE(re, gb); | ||
| 202 | GET_VLC(code, re, gb, vlc_tab, 8, 2); | ||
| 203 | cb_idx = code; | ||
| 204 | nnz = cb_idx >> 8 & 15; | ||
| 205 | sign = nnz ? SHOW_UBITS(re, gb, nnz) << (cb_idx >> 12) : 0; | ||
| 206 | LAST_SKIP_BITS(re, gb, nnz); | ||
| 207 | #if USE_FIXED | ||
| 208 | cf = DEC_UPAIR(cf, cb_idx, sign); | ||
| 209 | #else | ||
| 210 | cf = VMUL2S(cf, vq, cb_idx, sign, sf + idx); | ||
| 211 | #endif /* USE_FIXED */ | ||
| 212 | } while (len -= 2); | ||
| 213 | } | ||
| 214 | break; | ||
| 215 | |||
| 216 | default: | ||
| 217 | for (group = 0; group < (AAC_SIGNE)g_len; group++, cfo+=128) { | ||
| 218 | #if USE_FIXED | ||
| 219 | int *icf = cfo; | ||
| 220 | int v; | ||
| 221 | #else | ||
| 222 | float *cf = cfo; | ||
| 223 | uint32_t *icf = (uint32_t *) cf; | ||
| 224 | #endif /* USE_FIXED */ | ||
| 225 | int len = off_len; | ||
| 226 | |||
| 227 | do { | ||
| 228 | int code; | ||
| 229 | unsigned nzt, nnz; | ||
| 230 | unsigned cb_idx; | ||
| 231 | uint32_t bits; | ||
| 232 | int j; | ||
| 233 | |||
| 234 | UPDATE_CACHE(re, gb); | ||
| 235 | GET_VLC(code, re, gb, vlc_tab, 8, 2); | ||
| 236 | cb_idx = code; | ||
| 237 | |||
| 238 | if (cb_idx == 0x0000) { | ||
| 239 | *icf++ = 0; | ||
| 240 | *icf++ = 0; | ||
| 241 | continue; | ||
| 242 | } | ||
| 243 | |||
| 244 | nnz = cb_idx >> 12; | ||
| 245 | nzt = cb_idx >> 8; | ||
| 246 | bits = SHOW_UBITS(re, gb, nnz) << (32-nnz); | ||
| 247 | LAST_SKIP_BITS(re, gb, nnz); | ||
| 248 | |||
| 249 | for (j = 0; j < 2; j++) { | ||
| 250 | if (nzt & 1<<j) { | ||
| 251 | uint32_t b; | ||
| 252 | int n; | ||
| 253 | /* The total length of escape_sequence must be < 22 bits according | ||
| 254 | to the specification (i.e. max is 111111110xxxxxxxxxxxx). */ | ||
| 255 | UPDATE_CACHE(re, gb); | ||
| 256 | b = GET_CACHE(re, gb); | ||
| 257 | b = 31 - av_log2(~b); | ||
| 258 | |||
| 259 | if (b > 8) { | ||
| 260 | av_log(ac->avctx, AV_LOG_ERROR, "error in spectral data, ESC overflow\n"); | ||
| 261 | return AVERROR_INVALIDDATA; | ||
| 262 | } | ||
| 263 | |||
| 264 | SKIP_BITS(re, gb, b + 1); | ||
| 265 | b += 4; | ||
| 266 | n = (1 << b) + SHOW_UBITS(re, gb, b); | ||
| 267 | LAST_SKIP_BITS(re, gb, b); | ||
| 268 | #if USE_FIXED | ||
| 269 | v = n; | ||
| 270 | if (bits & 1U<<31) | ||
| 271 | v = -v; | ||
| 272 | *icf++ = v; | ||
| 273 | #else | ||
| 274 | *icf++ = ff_cbrt_tab[n] | (bits & 1U<<31); | ||
| 275 | #endif /* USE_FIXED */ | ||
| 276 | bits <<= 1; | ||
| 277 | } else { | ||
| 278 | #if USE_FIXED | ||
| 279 | v = cb_idx & 15; | ||
| 280 | if (bits & 1U<<31) | ||
| 281 | v = -v; | ||
| 282 | *icf++ = v; | ||
| 283 | #else | ||
| 284 | unsigned v = ((const uint32_t*)vq)[cb_idx & 15]; | ||
| 285 | *icf++ = (bits & 1U<<31) | v; | ||
| 286 | #endif /* USE_FIXED */ | ||
| 287 | bits <<= !!v; | ||
| 288 | } | ||
| 289 | cb_idx >>= 4; | ||
| 290 | } | ||
| 291 | } while (len -= 2); | ||
| 292 | #if !USE_FIXED | ||
| 293 | ac->fdsp->vector_fmul_scalar(cfo, cfo, sf[idx], off_len); | ||
| 294 | #endif /* !USE_FIXED */ | ||
| 295 | } | ||
| 296 | } | ||
| 297 | |||
| 298 | CLOSE_READER(re, gb); | ||
| 299 | } | ||
| 300 | } | ||
| 301 | coef += g_len << 7; | ||
| 302 | } | ||
| 303 | |||
| 304 | if (pulse) { | ||
| 305 | idx = 0; | ||
| 306 | for (i = 0; i < pulse->num_pulse; i++) { | ||
| 307 | INTFLOAT co = coef_base[ pulse->pos[i] ]; | ||
| 308 | while (offsets[idx + 1] <= pulse->pos[i]) | ||
| 309 | idx++; | ||
| 310 | if (band_type[idx] != NOISE_BT && sf[idx]) { | ||
| 311 | INTFLOAT ico = -pulse->amp[i]; | ||
| 312 | #if USE_FIXED | ||
| 313 | if (co) { | ||
| 314 | ico = co + (co > 0 ? -ico : ico); | ||
| 315 | } | ||
| 316 | coef_base[ pulse->pos[i] ] = ico; | ||
| 317 | #else | ||
| 318 | if (co) { | ||
| 319 | co /= sf[idx]; | ||
| 320 | ico = co / sqrtf(sqrtf(fabsf(co))) + (co > 0 ? -ico : ico); | ||
| 321 | } | ||
| 322 | coef_base[ pulse->pos[i] ] = cbrtf(fabsf(ico)) * ico * sf[idx]; | ||
| 323 | #endif /* USE_FIXED */ | ||
| 324 | } | ||
| 325 | } | ||
| 326 | } | ||
| 327 | #if USE_FIXED | ||
| 328 | coef = coef_base; | ||
| 329 | idx = 0; | ||
| 330 | for (g = 0; g < ics->num_window_groups; g++) { | ||
| 331 | unsigned g_len = ics->group_len[g]; | ||
| 332 | |||
| 333 | for (i = 0; i < ics->max_sfb; i++, idx++) { | ||
| 334 | const unsigned cbt_m1 = band_type[idx] - 1; | ||
| 335 | int *cfo = coef + offsets[i]; | ||
| 336 | int off_len = offsets[i + 1] - offsets[i]; | ||
| 337 | int group; | ||
| 338 | |||
| 339 | if (cbt_m1 < NOISE_BT - 1) { | ||
| 340 | for (group = 0; group < (int)g_len; group++, cfo+=128) { | ||
| 341 | vector_pow43(cfo, off_len); | ||
| 342 | subband_scale(cfo, cfo, sf[idx], 34, off_len, ac->avctx); | ||
| 343 | } | ||
| 344 | } | ||
| 345 | } | ||
| 346 | coef += g_len << 7; | ||
| 347 | } | ||
| 348 | #endif /* USE_FIXED */ | ||
| 349 | return 0; | ||
| 350 | } | ||
| 351 | |||
| 352 | const AACDecProc AAC_RENAME(aac_proc) = { | ||
| 353 | .decode_spectrum_and_dequant = AAC_RENAME(decode_spectrum_and_dequant), | ||
| 354 | }; | ||
| @@ -78,74 +78,6 @@ static av_always_inline void reset_predict_state(PredictorState *ps) · 77 unmodified lines | |||
| 78 | ps->var1 = 1.0f; | 78 | ps->var1 = 1.0f; |
| 79 | } | 79 | } |
| 80 | 80 | ||
| 81 | #ifndef VMUL2 | ||
| 82 | static inline float *VMUL2(float *dst, const float *v, unsigned idx, | ||
| 83 | const float *scale) | ||
| 84 | { | ||
| 85 | float s = *scale; | ||
| 86 | *dst++ = v[idx & 15] * s; | ||
| 87 | *dst++ = v[idx>>4 & 15] * s; | ||
| 88 | return dst; | ||
| 89 | } | ||
| 90 | #endif | ||
| 91 | |||
| 92 | #ifndef VMUL4 | ||
| 93 | static inline float *VMUL4(float *dst, const float *v, unsigned idx, | ||
| 94 | const float *scale) | ||
| 95 | { | ||
| 96 | float s = *scale; | ||
| 97 | *dst++ = v[idx & 3] * s; | ||
| 98 | *dst++ = v[idx>>2 & 3] * s; | ||
| 99 | *dst++ = v[idx>>4 & 3] * s; | ||
| 100 | *dst++ = v[idx>>6 & 3] * s; | ||
| 101 | return dst; | ||
| 102 | } | ||
| 103 | #endif | ||
| 104 | |||
| 105 | #ifndef VMUL2S | ||
| 106 | static inline float *VMUL2S(float *dst, const float *v, unsigned idx, | ||
| 107 | unsigned sign, const float *scale) | ||
| 108 | { | ||
| 109 | union av_intfloat32 s0, s1; | ||
| 110 | |||
| 111 | s0.f = s1.f = *scale; | ||
| 112 | s0.i ^= sign >> 1 << 31; | ||
| 113 | s1.i ^= sign << 31; | ||
| 114 | |||
| 115 | *dst++ = v[idx & 15] * s0.f; | ||
| 116 | *dst++ = v[idx>>4 & 15] * s1.f; | ||
| 117 | |||
| 118 | return dst; | ||
| 119 | } | ||
| 120 | #endif | ||
| 121 | |||
| 122 | #ifndef VMUL4S | ||
| 123 | static inline float *VMUL4S(float *dst, const float *v, unsigned idx, | ||
| 124 | unsigned sign, const float *scale) | ||
| 125 | { | ||
| 126 | unsigned nz = idx >> 12; | ||
| 127 | union av_intfloat32 s = { .f = *scale }; | ||
| 128 | union av_intfloat32 t; | ||
| 129 | |||
| 130 | t.i = s.i ^ (sign & 1U<<31); | ||
| 131 | *dst++ = v[idx & 3] * t.f; | ||
| 132 | |||
| 133 | sign <<= nz & 1; nz >>= 1; | ||
| 134 | t.i = s.i ^ (sign & 1U<<31); | ||
| 135 | *dst++ = v[idx>>2 & 3] * t.f; | ||
| 136 | |||
| 137 | sign <<= nz & 1; nz >>= 1; | ||
| 138 | t.i = s.i ^ (sign & 1U<<31); | ||
| 139 | *dst++ = v[idx>>4 & 3] * t.f; | ||
| 140 | |||
| 141 | sign <<= nz & 1; | ||
| 142 | t.i = s.i ^ (sign & 1U<<31); | ||
| 143 | *dst++ = v[idx>>6 & 3] * t.f; | ||
| 144 | |||
| 145 | return dst; | ||
| 146 | } | ||
| 147 | #endif | ||
| 148 | |||
| 149 | static av_always_inline float flt16_round(float pf) | 81 | static av_always_inline float flt16_round(float pf) |
| 150 | { | 82 | { |
| 151 | union av_intfloat32 tmp; | 83 | union av_intfloat32 tmp; |
| @@ -200,6 +200,16 @@ typedef struct DynamicRangeControl { · 199 unmodified lines | |||
| 200 | */ | 200 | */ |
| 201 | } DynamicRangeControl; | 201 | } DynamicRangeControl; |
| 202 | 202 | ||
| 203 | /** | ||
| 204 | * Decode-specific primitives | ||
| 205 | */ | ||
| 206 | typedef struct AACDecProc { | ||
| 207 | int (*decode_spectrum_and_dequant)(AACDecContext *ac, | ||
| 208 | GetBitContext *gb, | ||
| 209 | const Pulse *pulse, | ||
| 210 | SingleChannelElement *sce); | ||
| 211 | } AACDecProc; | ||
| 212 | |||
| 203 | /** | 213 | /** |
| 204 | * DSP-specific primitives | 214 | * DSP-specific primitives |
| 205 | */ | 215 | */ |
| @@ -232,6 +242,7 @@ struct AACDecContext { · 26 unmodified lines | |||
| 232 | struct AVCodecContext *avctx; | 242 | struct AVCodecContext *avctx; |
| 233 | 243 | ||
| 234 | AACDecDSP dsp; | 244 | AACDecDSP dsp; |
| 245 | AACDecProc proc; | ||
| 235 | 246 | ||
| 236 | struct AVFrame *frame; | 247 | struct AVFrame *frame; |
| 237 | 248 | ||
| @@ -309,10 +320,6 @@ struct AACDecContext { · 71 unmodified lines | |||
| 309 | int warned_he_aac_mono; | 320 | int warned_he_aac_mono; |
| 310 | 321 | ||
| 311 | int is_fixed; | 322 | int is_fixed; |
| 312 | |||
| 313 | /* aacdec functions pointers */ | ||
| 314 | void (*vector_pow43)(int *coefs, int len); | ||
| 315 | void (*subband_scale)(int *dst, int *src, int scale, int offset, int len, void *log_context); | ||
| 316 | }; | 323 | }; |
| 317 | 324 | ||
| 318 | #if defined(USE_FIXED) && USE_FIXED | 325 | #if defined(USE_FIXED) && USE_FIXED |
| @@ -147,136 +147,6 @@ static av_always_inline void reset_predict_state(PredictorState *ps) · 146 unmodified lines | |||
| 147 | 147 | ||
| 148 | static const int exp2tab[4] = { Q31(1.0000000000/2), Q31(1.1892071150/2), Q31(1.4142135624/2), Q31(1.6817928305/2) }; // 2^0, 2^0.25, 2^0.5, 2^0.75 | 148 | static const int exp2tab[4] = { Q31(1.0000000000/2), Q31(1.1892071150/2), Q31(1.4142135624/2), Q31(1.6817928305/2) }; // 2^0, 2^0.25, 2^0.5, 2^0.75 |
| 149 | 149 | ||
| 150 | static inline int *DEC_SPAIR(int *dst, unsigned idx) | ||
| 151 | { | ||
| 152 | dst[0] = (idx & 15) - 4; | ||
| 153 | dst[1] = (idx >> 4 & 15) - 4; | ||
| 154 | |||
| 155 | return dst + 2; | ||
| 156 | } | ||
| 157 | |||
| 158 | static inline int *DEC_SQUAD(int *dst, unsigned idx) | ||
| 159 | { | ||
| 160 | dst[0] = (idx & 3) - 1; | ||
| 161 | dst[1] = (idx >> 2 & 3) - 1; | ||
| 162 | dst[2] = (idx >> 4 & 3) - 1; | ||
| 163 | dst[3] = (idx >> 6 & 3) - 1; | ||
| 164 | |||
| 165 | return dst + 4; | ||
| 166 | } | ||
| 167 | |||
| 168 | static inline int *DEC_UPAIR(int *dst, unsigned idx, unsigned sign) | ||
| 169 | { | ||
| 170 | dst[0] = (idx & 15) * (1 - (sign & 0xFFFFFFFE)); | ||
| 171 | dst[1] = (idx >> 4 & 15) * (1 - ((sign & 1) * 2)); | ||
| 172 | |||
| 173 | return dst + 2; | ||
| 174 | } | ||
| 175 | |||
| 176 | static inline int *DEC_UQUAD(int *dst, unsigned idx, unsigned sign) | ||
| 177 | { | ||
| 178 | unsigned nz = idx >> 12; | ||
| 179 | |||
| 180 | dst[0] = (idx & 3) * (1 + (((int)sign >> 31) * 2)); | ||
| 181 | sign <<= nz & 1; | ||
| 182 | nz >>= 1; | ||
| 183 | dst[1] = (idx >> 2 & 3) * (1 + (((int)sign >> 31) * 2)); | ||
| 184 | sign <<= nz & 1; | ||
| 185 | nz >>= 1; | ||
| 186 | dst[2] = (idx >> 4 & 3) * (1 + (((int)sign >> 31) * 2)); | ||
| 187 | sign <<= nz & 1; | ||
| 188 | nz >>= 1; | ||
| 189 | dst[3] = (idx >> 6 & 3) * (1 + (((int)sign >> 31) * 2)); | ||
| 190 | |||
| 191 | return dst + 4; | ||
| 192 | } | ||
| 193 | |||
| 194 | static void vector_pow43(int *coefs, int len) | ||
| 195 | { | ||
| 196 | int i, coef; | ||
| 197 | |||
| 198 | for (i=0; i<len; i++) { | ||
| 199 | coef = coefs[i]; | ||
| 200 | if (coef < 0) | ||
| 201 | coef = -(int)ff_cbrt_tab_fixed[(-coef) & 8191]; | ||
| 202 | else | ||
| 203 | coef = (int)ff_cbrt_tab_fixed[ coef & 8191]; | ||
| 204 | coefs[i] = coef; | ||
| 205 | } | ||
| 206 | } | ||
| 207 | |||
| 208 | static void subband_scale(int *dst, int *src, int scale, int offset, int len, void *log_context) | ||
| 209 | { | ||
| 210 | int ssign = scale < 0 ? -1 : 1; | ||
| 211 | int s = FFABS(scale); | ||
| 212 | unsigned int round; | ||
| 213 | int i, out, c = exp2tab[s & 3]; | ||
| 214 | |||
| 215 | s = offset - (s >> 2); | ||
| 216 | |||
| 217 | if (s > 31) { | ||
| 218 | for (i=0; i<len; i++) { | ||
| 219 | dst[i] = 0; | ||
| 220 | } | ||
| 221 | } else if (s > 0) { | ||
| 222 | round = 1 << (s-1); | ||
| 223 | for (i=0; i<len; i++) { | ||
| 224 | out = (int)(((int64_t)src[i] * c) >> 32); | ||
| 225 | dst[i] = ((int)(out+round) >> s) * ssign; | ||
| 226 | } | ||
| 227 | } else if (s > -32) { | ||
| 228 | s = s + 32; | ||
| 229 | round = 1U << (s-1); | ||
| 230 | for (i=0; i<len; i++) { | ||
| 231 | out = (int)((int64_t)((int64_t)src[i] * c + round) >> s); | ||
| 232 | dst[i] = out * (unsigned)ssign; | ||
| 233 | } | ||
| 234 | } else { | ||
| 235 | av_log(log_context, AV_LOG_ERROR, "Overflow in subband_scale()\n"); | ||
| 236 | } | ||
| 237 | } | ||
| 238 | |||
| 239 | static void noise_scale(int *coefs, int scale, int band_energy, int len) | ||
| 240 | { | ||
| 241 | int s = -scale; | ||
| 242 | unsigned int round; | ||
| 243 | int i, out, c = exp2tab[s & 3]; | ||
| 244 | int nlz = 0; | ||
| 245 | |||
| 246 | av_assert0(s >= 0); | ||
| 247 | while (band_energy > 0x7fff) { | ||
| 248 | band_energy >>= 1; | ||
| 249 | nlz++; | ||
| 250 | } | ||
| 251 | c /= band_energy; | ||
| 252 | s = 21 + nlz - (s >> 2); | ||
| 253 | |||
| 254 | if (s > 31) { | ||
| 255 | for (i=0; i<len; i++) { | ||
| 256 | coefs[i] = 0; | ||
| 257 | } | ||
| 258 | } else if (s >= 0) { | ||
| 259 | round = s ? 1 << (s-1) : 0; | ||
| 260 | for (i=0; i<len; i++) { | ||
| 261 | out = (int)(((int64_t)coefs[i] * c) >> 32); | ||
| 262 | coefs[i] = -((int)(out+round) >> s); | ||
| 263 | } | ||
| 264 | } | ||
| 265 | else { | ||
| 266 | s = s + 32; | ||
| 267 | if (s > 0) { | ||
| 268 | round = 1 << (s-1); | ||
| 269 | for (i=0; i<len; i++) { | ||
| 270 | out = (int)((int64_t)((int64_t)coefs[i] * c + round) >> s); | ||
| 271 | coefs[i] = -out; | ||
| 272 | } | ||
| 273 | } else { | ||
| 274 | for (i=0; i<len; i++) | ||
| 275 | coefs[i] = -(int64_t)coefs[i] * c * (1 << -s); | ||
| 276 | } | ||
| 277 | } | ||
| 278 | } | ||
| 279 | |||
| 280 | static av_always_inline SoftFloat flt16_round(SoftFloat pf) | 150 | static av_always_inline SoftFloat flt16_round(SoftFloat pf) |
| 281 | { | 151 | { |
| 282 | SoftFloat tmp; | 152 | SoftFloat tmp; |
| @@ -1072,19 +1072,6 @@ static int decode_audio_specific_config(AACDecContext *ac, · 1071 unmodified lines | |||
| 1072 | sync_extension); | 1072 | sync_extension); |
| 1073 | } | 1073 | } |
| 1074 | 1074 | ||
| 1075 | /** | ||
| 1076 | * linear congruential pseudorandom number generator | ||
| 1077 | * | ||
| 1078 | * @param previous_val pointer to the current state of the generator | ||
| 1079 | * | ||
| 1080 | * @return Returns a 32-bit pseudorandom integer | ||
| 1081 | */ | ||
| 1082 | static av_always_inline int lcg_random(unsigned previous_val) | ||
| 1083 | { | ||
| 1084 | union { unsigned u; int s; } v = { previous_val * 1664525u + 1013904223 }; | ||
| 1085 | return v.s; | ||
| 1086 | } | ||
| 1087 | |||
| 1088 | static void reset_all_predictors(PredictorState *ps) | 1075 | static void reset_all_predictors(PredictorState *ps) |
| 1089 | { | 1076 | { |
| 1090 | int i; | 1077 | int i; |
| @@ -1598,313 +1585,6 @@ static void decode_mid_side_stereo(ChannelElement *cpe, GetBitContext *gb, · 507 unmodified lines | |||
| 1598 | } | 1585 | } |
| 1599 | } | 1586 | } |
| 1600 | 1587 | ||
| 1601 | /** | ||
| 1602 | * Decode spectral data; reference: table 4.50. | ||
| 1603 | * Dequantize and scale spectral data; reference: 4.6.3.3. | ||
| 1604 | * | ||
| 1605 | * @param coef array of dequantized, scaled spectral data | ||
| 1606 | * @param sf array of scalefactors or intensity stereo positions | ||
| 1607 | * @param pulse_present set if pulses are present | ||
| 1608 | * @param pulse pointer to pulse data struct | ||
| 1609 | * @param band_type array of the used band type | ||
| 1610 | * | ||
| 1611 | * @return Returns error status. 0 - OK, !0 - error | ||
| 1612 | */ | ||
| 1613 | static int decode_spectrum_and_dequant(AACDecContext *ac, | ||
| 1614 | GetBitContext *gb, | ||
| 1615 | const Pulse *pulse, | ||
| 1616 | SingleChannelElement *sce) | ||
| 1617 | { | ||
| 1618 | int i, k, g, idx = 0; | ||
| 1619 | INTFLOAT *coef = sce->AAC_RENAME(coeffs); | ||
| 1620 | IndividualChannelStream *ics = &sce->ics; | ||
| 1621 | const int c = 1024 / ics->num_windows; | ||
| 1622 | const uint16_t *offsets = ics->swb_offset; | ||
| 1623 | const INTFLOAT *sf = sce->AAC_RENAME(sf); | ||
| 1624 | const enum BandType *band_type = sce->band_type; | ||
| 1625 | INTFLOAT *coef_base = coef; | ||
| 1626 | |||
| 1627 | for (g = 0; g < ics->num_windows; g++) | ||
| 1628 | memset(coef + g * 128 + offsets[ics->max_sfb], 0, | ||
| 1629 | sizeof(INTFLOAT) * (c - offsets[ics->max_sfb])); | ||
| 1630 | |||
| 1631 | for (g = 0; g < ics->num_window_groups; g++) { | ||
| 1632 | unsigned g_len = ics->group_len[g]; | ||
| 1633 | |||
| 1634 | for (i = 0; i < ics->max_sfb; i++, idx++) { | ||
| 1635 | const unsigned cbt_m1 = band_type[idx] - 1; | ||
| 1636 | INTFLOAT *cfo = coef + offsets[i]; | ||
| 1637 | int off_len = offsets[i + 1] - offsets[i]; | ||
| 1638 | int group; | ||
| 1639 | |||
| 1640 | if (cbt_m1 >= INTENSITY_BT2 - 1) { | ||
| 1641 | for (group = 0; group < (AAC_SIGNE)g_len; group++, cfo+=128) { | ||
| 1642 | memset(cfo, 0, off_len * sizeof(*cfo)); | ||
| 1643 | } | ||
| 1644 | } else if (cbt_m1 == NOISE_BT - 1) { | ||
| 1645 | for (group = 0; group < (AAC_SIGNE)g_len; group++, cfo+=128) { | ||
| 1646 | INTFLOAT band_energy; | ||
| 1647 | #if USE_FIXED | ||
| 1648 | for (k = 0; k < off_len; k++) { | ||
| 1649 | ac->random_state = lcg_random(ac->random_state); | ||
| 1650 | cfo[k] = ac->random_state >> 3; | ||
| 1651 | } | ||
| 1652 | |||
| 1653 | band_energy = ac->fdsp->scalarproduct_fixed(cfo, cfo, off_len); | ||
| 1654 | band_energy = fixed_sqrt(band_energy, 31); | ||
| 1655 | noise_scale(cfo, sf[idx], band_energy, off_len); | ||
| 1656 | #else | ||
| 1657 | float scale; | ||
| 1658 | |||
| 1659 | for (k = 0; k < off_len; k++) { | ||
| 1660 | ac->random_state = lcg_random(ac->random_state); | ||
| 1661 | cfo[k] = ac->random_state; | ||
| 1662 | } | ||
| 1663 | |||
| 1664 | band_energy = ac->fdsp->scalarproduct_float(cfo, cfo, off_len); | ||
| 1665 | scale = sf[idx] / sqrtf(band_energy); | ||
| 1666 | ac->fdsp->vector_fmul_scalar(cfo, cfo, scale, off_len); | ||
| 1667 | #endif /* USE_FIXED */ | ||
| 1668 | } | ||
| 1669 | } else { | ||
| 1670 | #if !USE_FIXED | ||
| 1671 | const float *vq = ff_aac_codebook_vector_vals[cbt_m1]; | ||
| 1672 | #endif /* !USE_FIXED */ | ||
| 1673 | const VLCElem *vlc_tab = ff_vlc_spectral[cbt_m1]; | ||
| 1674 | OPEN_READER(re, gb); | ||
| 1675 | |||
| 1676 | switch (cbt_m1 >> 1) { | ||
| 1677 | case 0: | ||
| 1678 | for (group = 0; group < (AAC_SIGNE)g_len; group++, cfo+=128) { | ||
| 1679 | INTFLOAT *cf = cfo; | ||
| 1680 | int len = off_len; | ||
| 1681 | |||
| 1682 | do { | ||
| 1683 | int code; | ||
| 1684 | unsigned cb_idx; | ||
| 1685 | |||
| 1686 | UPDATE_CACHE(re, gb); | ||
| 1687 | GET_VLC(code, re, gb, vlc_tab, 8, 2); | ||
| 1688 | cb_idx = code; | ||
| 1689 | #if USE_FIXED | ||
| 1690 | cf = DEC_SQUAD(cf, cb_idx); | ||
| 1691 | #else | ||
| 1692 | cf = VMUL4(cf, vq, cb_idx, sf + idx); | ||
| 1693 | #endif /* USE_FIXED */ | ||
| 1694 | } while (len -= 4); | ||
| 1695 | } | ||
| 1696 | break; | ||
| 1697 | |||
| 1698 | case 1: | ||
| 1699 | for (group = 0; group < (AAC_SIGNE)g_len; group++, cfo+=128) { | ||
| 1700 | INTFLOAT *cf = cfo; | ||
| 1701 | int len = off_len; | ||
| 1702 | |||
| 1703 | do { | ||
| 1704 | int code; | ||
| 1705 | unsigned nnz; | ||
| 1706 | unsigned cb_idx; | ||
| 1707 | uint32_t bits; | ||
| 1708 | |||
| 1709 | UPDATE_CACHE(re, gb); | ||
| 1710 | GET_VLC(code, re, gb, vlc_tab, 8, 2); | ||
| 1711 | cb_idx = code; | ||
| 1712 | nnz = cb_idx >> 8 & 15; | ||
| 1713 | bits = nnz ? GET_CACHE(re, gb) : 0; | ||
| 1714 | LAST_SKIP_BITS(re, gb, nnz); | ||
| 1715 | #if USE_FIXED | ||
| 1716 | cf = DEC_UQUAD(cf, cb_idx, bits); | ||
| 1717 | #else | ||
| 1718 | cf = VMUL4S(cf, vq, cb_idx, bits, sf + idx); | ||
| 1719 | #endif /* USE_FIXED */ | ||
| 1720 | } while (len -= 4); | ||
| 1721 | } | ||
| 1722 | break; | ||
| 1723 | |||
| 1724 | case 2: | ||
| 1725 | for (group = 0; group < (AAC_SIGNE)g_len; group++, cfo+=128) { | ||
| 1726 | INTFLOAT *cf = cfo; | ||
| 1727 | int len = off_len; | ||
| 1728 | |||
| 1729 | do { | ||
| 1730 | int code; | ||
| 1731 | unsigned cb_idx; | ||
| 1732 | |||
| 1733 | UPDATE_CACHE(re, gb); | ||
| 1734 | GET_VLC(code, re, gb, vlc_tab, 8, 2); | ||
| 1735 | cb_idx = code; | ||
| 1736 | #if USE_FIXED | ||
| 1737 | cf = DEC_SPAIR(cf, cb_idx); | ||
| 1738 | #else | ||
| 1739 | cf = VMUL2(cf, vq, cb_idx, sf + idx); | ||
| 1740 | #endif /* USE_FIXED */ | ||
| 1741 | } while (len -= 2); | ||
| 1742 | } | ||
| 1743 | break; | ||
| 1744 | |||
| 1745 | case 3: | ||
| 1746 | case 4: | ||
| 1747 | for (group = 0; group < (AAC_SIGNE)g_len; group++, cfo+=128) { | ||
| 1748 | INTFLOAT *cf = cfo; | ||
| 1749 | int len = off_len; | ||
| 1750 | |||
| 1751 | do { | ||
| 1752 | int code; | ||
| 1753 | unsigned nnz; | ||
| 1754 | unsigned cb_idx; | ||
| 1755 | unsigned sign; | ||
| 1756 | |||
| 1757 | UPDATE_CACHE(re, gb); | ||
| 1758 | GET_VLC(code, re, gb, vlc_tab, 8, 2); | ||
| 1759 | cb_idx = code; | ||
| 1760 | nnz = cb_idx >> 8 & 15; | ||
| 1761 | sign = nnz ? SHOW_UBITS(re, gb, nnz) << (cb_idx >> 12) : 0; | ||
| 1762 | LAST_SKIP_BITS(re, gb, nnz); | ||
| 1763 | #if USE_FIXED | ||
| 1764 | cf = DEC_UPAIR(cf, cb_idx, sign); | ||
| 1765 | #else | ||
| 1766 | cf = VMUL2S(cf, vq, cb_idx, sign, sf + idx); | ||
| 1767 | #endif /* USE_FIXED */ | ||
| 1768 | } while (len -= 2); | ||
| 1769 | } | ||
| 1770 | break; | ||
| 1771 | |||
| 1772 | default: | ||
| 1773 | for (group = 0; group < (AAC_SIGNE)g_len; group++, cfo+=128) { | ||
| 1774 | #if USE_FIXED | ||
| 1775 | int *icf = cfo; | ||
| 1776 | int v; | ||
| 1777 | #else | ||
| 1778 | float *cf = cfo; | ||
| 1779 | uint32_t *icf = (uint32_t *) cf; | ||
| 1780 | #endif /* USE_FIXED */ | ||
| 1781 | int len = off_len; | ||
| 1782 | |||
| 1783 | do { | ||
| 1784 | int code; | ||
| 1785 | unsigned nzt, nnz; | ||
| 1786 | unsigned cb_idx; | ||
| 1787 | uint32_t bits; | ||
| 1788 | int j; | ||
| 1789 | |||
| 1790 | UPDATE_CACHE(re, gb); | ||
| 1791 | GET_VLC(code, re, gb, vlc_tab, 8, 2); | ||
| 1792 | cb_idx = code; | ||
| 1793 | |||
| 1794 | if (cb_idx == 0x0000) { | ||
| 1795 | *icf++ = 0; | ||
| 1796 | *icf++ = 0; | ||
| 1797 | continue; | ||
| 1798 | } | ||
| 1799 | |||
| 1800 | nnz = cb_idx >> 12; | ||
| 1801 | nzt = cb_idx >> 8; | ||
| 1802 | bits = SHOW_UBITS(re, gb, nnz) << (32-nnz); | ||
| 1803 | LAST_SKIP_BITS(re, gb, nnz); | ||
| 1804 | |||
| 1805 | for (j = 0; j < 2; j++) { | ||
| 1806 | if (nzt & 1<<j) { | ||
| 1807 | uint32_t b; | ||
| 1808 | int n; | ||
| 1809 | /* The total length of escape_sequence must be < 22 bits according | ||
| 1810 | to the specification (i.e. max is 111111110xxxxxxxxxxxx). */ | ||
| 1811 | UPDATE_CACHE(re, gb); | ||
| 1812 | b = GET_CACHE(re, gb); | ||
| 1813 | b = 31 - av_log2(~b); | ||
| 1814 | |||
| 1815 | if (b > 8) { | ||
| 1816 | av_log(ac->avctx, AV_LOG_ERROR, "error in spectral data, ESC overflow\n"); | ||
| 1817 | return AVERROR_INVALIDDATA; | ||
| 1818 | } | ||
| 1819 | |||
| 1820 | SKIP_BITS(re, gb, b + 1); | ||
| 1821 | b += 4; | ||
| 1822 | n = (1 << b) + SHOW_UBITS(re, gb, b); | ||
| 1823 | LAST_SKIP_BITS(re, gb, b); | ||
| 1824 | #if USE_FIXED | ||
| 1825 | v = n; | ||
| 1826 | if (bits & 1U<<31) | ||
| 1827 | v = -v; | ||
| 1828 | *icf++ = v; | ||
| 1829 | #else | ||
| 1830 | *icf++ = ff_cbrt_tab[n] | (bits & 1U<<31); | ||
| 1831 | #endif /* USE_FIXED */ | ||
| 1832 | bits <<= 1; | ||
| 1833 | } else { | ||
| 1834 | #if USE_FIXED | ||
| 1835 | v = cb_idx & 15; | ||
| 1836 | if (bits & 1U<<31) | ||
| 1837 | v = -v; | ||
| 1838 | *icf++ = v; | ||
| 1839 | #else | ||
| 1840 | unsigned v = ((const uint32_t*)vq)[cb_idx & 15]; | ||
| 1841 | *icf++ = (bits & 1U<<31) | v; | ||
| 1842 | #endif /* USE_FIXED */ | ||
| 1843 | bits <<= !!v; | ||
| 1844 | } | ||
| 1845 | cb_idx >>= 4; | ||
| 1846 | } | ||
| 1847 | } while (len -= 2); | ||
| 1848 | #if !USE_FIXED | ||
| 1849 | ac->fdsp->vector_fmul_scalar(cfo, cfo, sf[idx], off_len); | ||
| 1850 | #endif /* !USE_FIXED */ | ||
| 1851 | } | ||
| 1852 | } | ||
| 1853 | |||
| 1854 | CLOSE_READER(re, gb); | ||
| 1855 | } | ||
| 1856 | } | ||
| 1857 | coef += g_len << 7; | ||
| 1858 | } | ||
| 1859 | |||
| 1860 | if (pulse) { | ||
| 1861 | idx = 0; | ||
| 1862 | for (i = 0; i < pulse->num_pulse; i++) { | ||
| 1863 | INTFLOAT co = coef_base[ pulse->pos[i] ]; | ||
| 1864 | while (offsets[idx + 1] <= pulse->pos[i]) | ||
| 1865 | idx++; | ||
| 1866 | if (band_type[idx] != NOISE_BT && sf[idx]) { | ||
| 1867 | INTFLOAT ico = -pulse->amp[i]; | ||
| 1868 | #if USE_FIXED | ||
| 1869 | if (co) { | ||
| 1870 | ico = co + (co > 0 ? -ico : ico); | ||
| 1871 | } | ||
| 1872 | coef_base[ pulse->pos[i] ] = ico; | ||
| 1873 | #else | ||
| 1874 | if (co) { | ||
| 1875 | co /= sf[idx]; | ||
| 1876 | ico = co / sqrtf(sqrtf(fabsf(co))) + (co > 0 ? -ico : ico); | ||
| 1877 | } | ||
| 1878 | coef_base[ pulse->pos[i] ] = cbrtf(fabsf(ico)) * ico * sf[idx]; | ||
| 1879 | #endif /* USE_FIXED */ | ||
| 1880 | } | ||
| 1881 | } | ||
| 1882 | } | ||
| 1883 | #if USE_FIXED | ||
| 1884 | coef = coef_base; | ||
| 1885 | idx = 0; | ||
| 1886 | for (g = 0; g < ics->num_window_groups; g++) { | ||
| 1887 | unsigned g_len = ics->group_len[g]; | ||
| 1888 | |||
| 1889 | for (i = 0; i < ics->max_sfb; i++, idx++) { | ||
| 1890 | const unsigned cbt_m1 = band_type[idx] - 1; | ||
| 1891 | int *cfo = coef + offsets[i]; | ||
| 1892 | int off_len = offsets[i + 1] - offsets[i]; | ||
| 1893 | int group; | ||
| 1894 | |||
| 1895 | if (cbt_m1 < NOISE_BT - 1) { | ||
| 1896 | for (group = 0; group < (int)g_len; group++, cfo+=128) { | ||
| 1897 | ac->vector_pow43(cfo, off_len); | ||
| 1898 | ac->subband_scale(cfo, cfo, sf[idx], 34, off_len, ac->avctx); | ||
| 1899 | } | ||
| 1900 | } | ||
| 1901 | } | ||
| 1902 | coef += g_len << 7; | ||
| 1903 | } | ||
| 1904 | #endif /* USE_FIXED */ | ||
| 1905 | return 0; | ||
| 1906 | } | ||
| 1907 | |||
| 1908 | /** | 1588 | /** |
| 1909 | * Apply AAC-Main style frequency domain prediction. | 1589 | * Apply AAC-Main style frequency domain prediction. |
| 1910 | */ | 1590 | */ |
| @@ -2047,9 +1727,9 @@ static int decode_ics(AACDecContext *ac, SingleChannelElement *sce, · 136 unmodified lines | |||
| 2047 | } | 1727 | } |
| 2048 | } | 1728 | } |
| 2049 | 1729 | ||
| 2050 | ret = decode_spectrum_and_dequant(ac, gb, | 1730 | ret = ac->proc.decode_spectrum_and_dequant(ac, gb, |
| 2051 | pulse_present ? &pulse : NULL, | 1731 | pulse_present ? &pulse : NULL, |
| 2052 | sce); | 1732 | sce); |
| 2053 | if (ret < 0) | 1733 | if (ret < 0) |
| 2054 | goto fail; | 1734 | goto fail; |
| 2055 | 1735 | ||
| @@ -2892,11 +2572,6 @@ static int aac_decode_frame(AVCodecContext *avctx, AVFrame *frame, · 836 unmodified lines | |||
| 2892 | 2572 | ||
| 2893 | static void aacdec_init(AACDecContext *c) | 2573 | static void aacdec_init(AACDecContext *c) |
| 2894 | { | 2574 | { |
| 2895 | #if USE_FIXED | ||
| 2896 | c->vector_pow43 = vector_pow43; | ||
| 2897 | c->subband_scale = subband_scale; | ||
| 2898 | #endif | ||
| 2899 | |||
| 2900 | #if !USE_FIXED | 2575 | #if !USE_FIXED |
| 2901 | #if ARCH_MIPS | 2576 | #if ARCH_MIPS |
| 2902 | ff_aacdec_init_mips(c); | 2577 | ff_aacdec_init_mips(c); |