FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/aac/aacdec_fixed_dequant.h
Date: 2024-11-20 23:03:26
Exec Total Coverage
Lines: 76 83 91.6%
Functions: 7 7 100.0%
Branches: 27 38 71.1%

Line Branch Exec Source
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 798771 static void inline vector_pow43(int *coefs, int len)
38 {
39 int i, coef;
40
41
2/2
✓ Branch 0 taken 10768416 times.
✓ Branch 1 taken 798771 times.
11567187 for (i=0; i<len; i++) {
42 10768416 coef = coefs[i];
43
2/2
✓ Branch 0 taken 1879416 times.
✓ Branch 1 taken 8889000 times.
10768416 if (coef < 0)
44 1879416 coef = -(int)ff_cbrt_tab_fixed[(-coef) & 8191];
45 else
46 8889000 coef = (int)ff_cbrt_tab_fixed[ coef & 8191];
47 10768416 coefs[i] = coef;
48 }
49 798771 }
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 816726 static void inline subband_scale(int *dst, int *src, int scale,
58 int offset, int len, void *log_context)
59 {
60
2/2
✓ Branch 0 taken 798773 times.
✓ Branch 1 taken 17953 times.
816726 int ssign = scale < 0 ? -1 : 1;
61 816726 int s = FFABS(scale);
62 unsigned int round;
63 816726 int i, out, c = exp2tab[s & 3];
64
65 816726 s = offset - (s >> 2);
66
67
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 816726 times.
816726 if (s > 31) {
68 for (i=0; i<len; i++) {
69 dst[i] = 0;
70 }
71
2/2
✓ Branch 0 taken 94860 times.
✓ Branch 1 taken 721866 times.
816726 } else if (s > 0) {
72 94860 round = 1 << (s-1);
73
2/2
✓ Branch 0 taken 1297084 times.
✓ Branch 1 taken 94860 times.
1391944 for (i=0; i<len; i++) {
74 1297084 out = (int)(((int64_t)src[i] * c) >> 32);
75 1297084 dst[i] = ((int)(out+round) >> s) * ssign;
76 }
77
1/2
✓ Branch 0 taken 721866 times.
✗ Branch 1 not taken.
721866 } else if (s > -32) {
78 721866 s = s + 32;
79 721866 round = 1U << (s-1);
80
2/2
✓ Branch 0 taken 10006532 times.
✓ Branch 1 taken 721866 times.
10728398 for (i=0; i<len; i++) {
81 10006532 out = (int)((int64_t)((int64_t)src[i] * c + round) >> s);
82 10006532 dst[i] = out * (unsigned)ssign;
83 }
84 } else {
85 av_log(log_context, AV_LOG_ERROR, "Overflow in subband_scale()\n");
86 }
87 816726 }
88
89 137931 static void noise_scale(int *coefs, int scale, int band_energy, int len)
90 {
91 137931 int s = -scale;
92 unsigned int round;
93 137931 int i, out, c = exp2tab[s & 3];
94 137931 int nlz = 0;
95
96
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 137931 times.
137931 av_assert0(s >= 0);
97
2/2
✓ Branch 0 taken 2009279 times.
✓ Branch 1 taken 137931 times.
2147210 while (band_energy > 0x7fff) {
98 2009279 band_energy >>= 1;
99 2009279 nlz++;
100 }
101 137931 c /= band_energy;
102 137931 s = 21 + nlz - (s >> 2);
103
104
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 137931 times.
137931 if (s > 31) {
105 for (i=0; i<len; i++) {
106 coefs[i] = 0;
107 }
108
2/2
✓ Branch 0 taken 73177 times.
✓ Branch 1 taken 64754 times.
137931 } else if (s >= 0) {
109
2/2
✓ Branch 0 taken 67551 times.
✓ Branch 1 taken 5626 times.
73177 round = s ? 1 << (s-1) : 0;
110
2/2
✓ Branch 0 taken 2387284 times.
✓ Branch 1 taken 73177 times.
2460461 for (i=0; i<len; i++) {
111 2387284 out = (int)(((int64_t)coefs[i] * c) >> 32);
112 2387284 coefs[i] = -((int)(out+round) >> s);
113 }
114 }
115 else {
116 64754 s = s + 32;
117
1/2
✓ Branch 0 taken 64754 times.
✗ Branch 1 not taken.
64754 if (s > 0) {
118 64754 round = 1 << (s-1);
119
2/2
✓ Branch 0 taken 496192 times.
✓ Branch 1 taken 64754 times.
560946 for (i=0; i<len; i++) {
120 496192 out = (int)((int64_t)((int64_t)coefs[i] * c + round) >> s);
121 496192 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 137931 }
129
130 690688 static inline int *DEC_SPAIR(int *dst, unsigned idx)
131 {
132 690688 dst[0] = (idx & 15) - 4;
133 690688 dst[1] = (idx >> 4 & 15) - 4;
134
135 690688 return dst + 2;
136 }
137
138 996762 static inline int *DEC_SQUAD(int *dst, unsigned idx)
139 {
140 996762 dst[0] = (idx & 3) - 1;
141 996762 dst[1] = (idx >> 2 & 3) - 1;
142 996762 dst[2] = (idx >> 4 & 3) - 1;
143 996762 dst[3] = (idx >> 6 & 3) - 1;
144
145 996762 return dst + 4;
146 }
147
148 718254 static inline int *DEC_UPAIR(int *dst, unsigned idx, unsigned sign)
149 {
150 718254 dst[0] = (idx & 15) * (1 - (sign & 0xFFFFFFFE));
151 718254 dst[1] = (idx >> 4 & 15) * (1 - ((sign & 1) * 2));
152
153 718254 return dst + 2;
154 }
155
156 826740 static inline int *DEC_UQUAD(int *dst, unsigned idx, unsigned sign)
157 {
158 826740 unsigned nz = idx >> 12;
159
160 826740 dst[0] = (idx & 3) * (1 + (((int)sign >> 31) * 2));
161 826740 sign <<= nz & 1;
162 826740 nz >>= 1;
163 826740 dst[1] = (idx >> 2 & 3) * (1 + (((int)sign >> 31) * 2));
164 826740 sign <<= nz & 1;
165 826740 nz >>= 1;
166 826740 dst[2] = (idx >> 4 & 3) * (1 + (((int)sign >> 31) * 2));
167 826740 sign <<= nz & 1;
168 826740 nz >>= 1;
169 826740 dst[3] = (idx >> 6 & 3) * (1 + (((int)sign >> 31) * 2));
170
171 826740 return dst + 4;
172 }
173
174 #endif /* AVCODEC_AAC_AACDEC_FIXED_DEQUANT_H */
175