FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/aac/aacdec_fixed_dequant.h
Date: 2026-08-15 14:54:27
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 791554 static void inline vector_pow43(int *coefs, int len)
38 {
39 int i, coef;
40
41
2/2
✓ Branch 0 taken 10634144 times.
✓ Branch 1 taken 791554 times.
11425698 for (i=0; i<len; i++) {
42 10634144 coef = coefs[i];
43
2/2
✓ Branch 0 taken 1853285 times.
✓ Branch 1 taken 8780859 times.
10634144 if (coef < 0)
44 1853285 coef = -(int)ff_cbrt_tab_fixed[(-coef) & 8191];
45 else
46 8780859 coef = (int)ff_cbrt_tab_fixed[ coef & 8191];
47 10634144 coefs[i] = coef;
48 }
49 791554 }
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 809509 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 791556 times.
✓ Branch 1 taken 17953 times.
809509 int ssign = scale < 0 ? -1 : 1;
61 809509 int s = FFABS(scale);
62 unsigned int round;
63 809509 int i, out, c = exp2tab[s & 3];
64
65 809509 s = offset - (s >> 2);
66
67
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 809509 times.
809509 if (s > 31) {
68 for (i=0; i<len; i++) {
69 dst[i] = 0;
70 }
71
2/2
✓ Branch 0 taken 94538 times.
✓ Branch 1 taken 714971 times.
809509 } else if (s > 0) {
72 94538 round = 1 << (s-1);
73
2/2
✓ Branch 0 taken 1294676 times.
✓ Branch 1 taken 94538 times.
1389214 for (i=0; i<len; i++) {
74 1294676 out = (int)(((int64_t)src[i] * c) >> 32);
75 1294676 dst[i] = ((int)(out+round) >> s) * ssign;
76 }
77
1/2
✓ Branch 0 taken 714971 times.
✗ Branch 1 not taken.
714971 } else if (s > -32) {
78 714971 s = s + 32;
79 714971 round = 1U << (s-1);
80
2/2
✓ Branch 0 taken 9874668 times.
✓ Branch 1 taken 714971 times.
10589639 for (i=0; i<len; i++) {
81 9874668 out = (int)((int64_t)((int64_t)src[i] * c + round) >> s);
82 9874668 dst[i] = out * (unsigned)ssign;
83 }
84 } else {
85 av_log(log_context, AV_LOG_ERROR, "Overflow in subband_scale()\n");
86 }
87 809509 }
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 680176 static inline int *DEC_SPAIR(int *dst, unsigned idx)
131 {
132 680176 dst[0] = (idx & 15) - 4;
133 680176 dst[1] = (idx >> 4 & 15) - 4;
134
135 680176 return dst + 2;
136 }
137
138 979225 static inline int *DEC_SQUAD(int *dst, unsigned idx)
139 {
140 979225 dst[0] = (idx & 3) - 1;
141 979225 dst[1] = (idx >> 2 & 3) - 1;
142 979225 dst[2] = (idx >> 4 & 3) - 1;
143 979225 dst[3] = (idx >> 6 & 3) - 1;
144
145 979225 return dst + 4;
146 }
147
148 714422 static inline int *DEC_UPAIR(int *dst, unsigned idx, unsigned sign)
149 {
150 714422 dst[0] = (idx & 15) * (1 - (sign & 0xFFFFFFFE));
151 714422 dst[1] = (idx >> 4 & 15) * (1 - ((sign & 1) * 2));
152
153 714422 return dst + 2;
154 }
155
156 818091 static inline int *DEC_UQUAD(int *dst, unsigned idx, unsigned sign)
157 {
158 818091 unsigned nz = idx >> 12;
159
160 818091 dst[0] = (idx & 3) * (1 + (((int)sign >> 31) * 2));
161 818091 sign <<= nz & 1;
162 818091 nz >>= 1;
163 818091 dst[1] = (idx >> 2 & 3) * (1 + (((int)sign >> 31) * 2));
164 818091 sign <<= nz & 1;
165 818091 nz >>= 1;
166 818091 dst[2] = (idx >> 4 & 3) * (1 + (((int)sign >> 31) * 2));
167 818091 sign <<= nz & 1;
168 818091 nz >>= 1;
169 818091 dst[3] = (idx >> 6 & 3) * (1 + (((int)sign >> 31) * 2));
170
171 818091 return dst + 4;
172 }
173
174 #endif /* AVCODEC_AAC_AACDEC_FIXED_DEQUANT_H */
175