FFmpeg
Loading...
Searching...
No Matches
aacdec_fixed_dequant.h
Go to the documentation of this file.
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
37static 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 */
52static const int exp2tab[4] = {
53 Q31(1.0000000000/2), Q31(1.1892071150/2),
54 Q31(1.4142135624/2), Q31(1.6817928305/2)
55};
56
57static 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
89static 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
130static 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
138static 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
148static 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
156static 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 */
#define Q31(x)
static void subband_scale(int *dst, int *src, int scale, int offset, int len, void *log_context)
static const int exp2tab[4]
static int * DEC_UPAIR(int *dst, unsigned idx, unsigned sign)
static int * DEC_SPAIR(int *dst, unsigned idx)
static int * DEC_SQUAD(int *dst, unsigned idx)
static void vector_pow43(int *coefs, int len)
static void noise_scale(int *coefs, int scale, int band_energy, int len)
static int * DEC_UQUAD(int *dst, unsigned idx, unsigned sign)
AAC decoder data.
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition dsp.h:87
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition avassert.h:42
const uint32_t ff_cbrt_tab_fixed[LUT_SIZE]
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
#define s(width, name)
Definition cbs_vp9.c:198
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
Definition common.h:74
long long int64_t
Definition coverity.c:34
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition log.h:210
static void scale(int *out, const int *in, const int w, const int h, const int shift)
Definition intra.c:278
unsigned offset
Definition libaomenc.c:763
static av_always_inline av_const double round(double x)
Definition libm.h:446
#define av_log(a,...)
#define src
Definition vp8dsp.c:248
static FILE * out
Definition movenc.c:55
int len
static double c[64]