FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/sbrdsp_fixed.c
Date: 2024-11-20 23:03:26
Exec Total Coverage
Lines: 168 178 94.4%
Functions: 11 11 100.0%
Branches: 45 52 86.5%

Line Branch Exec Source
1 /*
2 * AAC Spectral Band Replication decoding functions
3 * Copyright (c) 2008-2009 Robert Swain ( rob opendot cl )
4 * Copyright (c) 2009-2010 Alex Converse <alex.converse@gmail.com>
5 *
6 * This file is part of FFmpeg.
7 *
8 * FFmpeg is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * FFmpeg is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 *
22 * Note: Rounding-to-nearest used unless otherwise stated
23 *
24 */
25
26 #define USE_FIXED 1
27
28 #include "aac.h"
29 #include "libavutil/attributes.h"
30 #include "libavutil/intfloat.h"
31 #include "sbrdsp.h"
32
33 127837 static SoftFloat sbr_sum_square_c(int (*x)[2], int n)
34 {
35 SoftFloat ret;
36 127837 uint64_t accu = 0, round;
37 127837 uint64_t accu0 = 0, accu1 = 0, accu2 = 0, accu3 = 0;
38 int i, nz, nz0;
39 unsigned u;
40
41 127837 nz = 0;
42
2/2
✓ Branch 0 taken 1355792 times.
✓ Branch 1 taken 127837 times.
1483629 for (i = 0; i < n; i += 2) {
43 1355792 accu0 += (int64_t)x[i + 0][0] * x[i + 0][0];
44 1355792 accu1 += (int64_t)x[i + 0][1] * x[i + 0][1];
45 1355792 accu2 += (int64_t)x[i + 1][0] * x[i + 1][0];
46 1355792 accu3 += (int64_t)x[i + 1][1] * x[i + 1][1];
47
3/4
✓ Branch 0 taken 1355792 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 127837 times.
✓ Branch 3 taken 1227955 times.
1355792 if ((accu0|accu1|accu2|accu3) > UINT64_MAX - INT32_MIN*(int64_t)INT32_MIN || i+2>=n) {
48 127837 accu0 >>= nz;
49 127837 accu1 >>= nz;
50 127837 accu2 >>= nz;
51 127837 accu3 >>= nz;
52
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 127837 times.
127837 while ((accu0|accu1|accu2|accu3) > (UINT64_MAX - accu) >> 2) {
53 accu0 >>= 1;
54 accu1 >>= 1;
55 accu2 >>= 1;
56 accu3 >>= 1;
57 accu >>= 1;
58 nz ++;
59 }
60 127837 accu += accu0 + accu1 + accu2 + accu3;
61 127837 accu0 = accu1 = accu2 = accu3 = 0;
62 }
63 }
64
65 127837 nz0 = 15 - nz;
66
67 127837 u = accu >> 32;
68
2/2
✓ Branch 0 taken 120661 times.
✓ Branch 1 taken 7176 times.
127837 if (u) {
69 120661 nz = 33;
70
2/2
✓ Branch 0 taken 2486474 times.
✓ Branch 1 taken 120661 times.
2607135 while (u < 0x80000000U) {
71 2486474 u <<= 1;
72 2486474 nz--;
73 }
74 } else
75 7176 nz = 1;
76
77 127837 round = 1ULL << (nz-1);
78 127837 u = ((accu + round) >> nz);
79 127837 u >>= 1;
80 127837 ret = av_int2sf(u, nz0 - nz);
81
82 127837 return ret;
83 }
84
85 193024 static void sbr_neg_odd_64_c(int *x)
86 {
87 int i;
88
2/2
✓ Branch 0 taken 6176768 times.
✓ Branch 1 taken 193024 times.
6369792 for (i = 1; i < 64; i += 2)
89 6176768 x[i] = -(unsigned)x[i];
90 193024 }
91
92 266496 static void sbr_qmf_pre_shuffle_c(int *z)
93 {
94 int k;
95 266496 z[64] = z[0];
96 266496 z[65] = z[1];
97
2/2
✓ Branch 0 taken 8261376 times.
✓ Branch 1 taken 266496 times.
8527872 for (k = 1; k < 32; k++) {
98 8261376 z[64+2*k ] = -z[64 - k];
99 8261376 z[64+2*k+1] = z[ k + 1];
100 }
101 266496 }
102
103 266496 static void sbr_qmf_post_shuffle_c(int W[32][2], const int *z)
104 {
105 int k;
106
2/2
✓ Branch 0 taken 8527872 times.
✓ Branch 1 taken 266496 times.
8794368 for (k = 0; k < 32; k++) {
107 8527872 W[k][0] = -z[63-k];
108 8527872 W[k][1] = z[k];
109 }
110 266496 }
111
112 73472 static void sbr_qmf_deint_neg_c(int *v, const int *src)
113 {
114 int i;
115
2/2
✓ Branch 0 taken 2351104 times.
✓ Branch 1 taken 73472 times.
2424576 for (i = 0; i < 32; i++) {
116 2351104 v[ i] = (int)(0x10U + src[63 - 2*i ]) >> 5;
117 2351104 v[63 - i] = (int)(0x10U - src[63 - 2*i - 1]) >> 5;
118 }
119 73472 }
120
121 544784 static av_always_inline SoftFloat autocorr_calc(int64_t accu)
122 {
123 int nz, mant, expo;
124 unsigned round;
125 544784 int i = (int)(accu >> 32);
126
2/2
✓ Branch 0 taken 29400 times.
✓ Branch 1 taken 515384 times.
544784 if (i == 0) {
127 29400 nz = 1;
128 } else {
129 515384 nz = 0;
130
4/4
✓ Branch 0 taken 9701188 times.
✓ Branch 1 taken 197436 times.
✓ Branch 2 taken 9383240 times.
✓ Branch 3 taken 317948 times.
9898624 while (FFABS(i) < 0x40000000) {
131 9383240 i *= 2;
132 9383240 nz++;
133 }
134 515384 nz = 32-nz;
135 }
136
137 544784 round = 1U << (nz-1);
138 544784 mant = (int)((accu + round) >> nz);
139 544784 mant = (mant + 0x40LL)>>7;
140 544784 mant *= 64;
141 544784 expo = nz + 15;
142 544784 return av_int2sf(mant, 30 - expo);
143 }
144
145 204294 static av_always_inline void autocorrelate(const int x[40][2], SoftFloat phi[3][2][2], int lag)
146 {
147 int i;
148 int64_t real_sum, imag_sum;
149 204294 int64_t accu_re = 0, accu_im = 0;
150
151
2/2
✓ Branch 0 taken 136196 times.
✓ Branch 1 taken 68098 times.
204294 if (lag) {
152
2/2
✓ Branch 0 taken 5039252 times.
✓ Branch 1 taken 136196 times.
5175448 for (i = 1; i < 38; i++) {
153 5039252 accu_re += (uint64_t)x[i][0] * x[i+lag][0];
154 5039252 accu_re += (uint64_t)x[i][1] * x[i+lag][1];
155 5039252 accu_im += (uint64_t)x[i][0] * x[i+lag][1];
156 5039252 accu_im -= (uint64_t)x[i][1] * x[i+lag][0];
157 }
158
159 136196 real_sum = accu_re;
160 136196 imag_sum = accu_im;
161
162 136196 accu_re += (uint64_t)x[ 0][0] * x[lag][0];
163 136196 accu_re += (uint64_t)x[ 0][1] * x[lag][1];
164 136196 accu_im += (uint64_t)x[ 0][0] * x[lag][1];
165 136196 accu_im -= (uint64_t)x[ 0][1] * x[lag][0];
166
167 136196 phi[2-lag][1][0] = autocorr_calc(accu_re);
168 136196 phi[2-lag][1][1] = autocorr_calc(accu_im);
169
170
2/2
✓ Branch 0 taken 68098 times.
✓ Branch 1 taken 68098 times.
136196 if (lag == 1) {
171 68098 accu_re = real_sum;
172 68098 accu_im = imag_sum;
173 68098 accu_re += (uint64_t)x[38][0] * x[39][0];
174 68098 accu_re += (uint64_t)x[38][1] * x[39][1];
175 68098 accu_im += (uint64_t)x[38][0] * x[39][1];
176 68098 accu_im -= (uint64_t)x[38][1] * x[39][0];
177
178 68098 phi[0][0][0] = autocorr_calc(accu_re);
179 68098 phi[0][0][1] = autocorr_calc(accu_im);
180 }
181 } else {
182
2/2
✓ Branch 0 taken 2519626 times.
✓ Branch 1 taken 68098 times.
2587724 for (i = 1; i < 38; i++) {
183 2519626 accu_re += (uint64_t)x[i][0] * x[i][0];
184 2519626 accu_re += (uint64_t)x[i][1] * x[i][1];
185 }
186 68098 real_sum = accu_re;
187 68098 accu_re += (uint64_t)x[ 0][0] * x[ 0][0];
188 68098 accu_re += (uint64_t)x[ 0][1] * x[ 0][1];
189
190 68098 phi[2][1][0] = autocorr_calc(accu_re);
191
192 68098 accu_re = real_sum;
193 68098 accu_re += (uint64_t)x[38][0] * x[38][0];
194 68098 accu_re += (uint64_t)x[38][1] * x[38][1];
195
196 68098 phi[1][0][0] = autocorr_calc(accu_re);
197 }
198 204294 }
199
200 68098 static void sbr_autocorrelate_c(const int x[40][2], SoftFloat phi[3][2][2])
201 {
202 68098 autocorrelate(x, phi, 0);
203 68098 autocorrelate(x, phi, 1);
204 68098 autocorrelate(x, phi, 2);
205 68098 }
206
207 84737 static void sbr_hf_gen_c(int (*X_high)[2], const int (*X_low)[2],
208 const int alpha0[2], const int alpha1[2],
209 int bw, int start, int end)
210 {
211 int alpha[4];
212 int i;
213 int64_t accu;
214
215 84737 accu = (int64_t)alpha0[0] * bw;
216 84737 alpha[2] = (int)((accu + 0x40000000) >> 31);
217 84737 accu = (int64_t)alpha0[1] * bw;
218 84737 alpha[3] = (int)((accu + 0x40000000) >> 31);
219 84737 accu = (int64_t)bw * bw;
220 84737 bw = (int)((accu + 0x40000000) >> 31);
221 84737 accu = (int64_t)alpha1[0] * bw;
222 84737 alpha[0] = (int)((accu + 0x40000000) >> 31);
223 84737 accu = (int64_t)alpha1[1] * bw;
224 84737 alpha[1] = (int)((accu + 0x40000000) >> 31);
225
226
2/2
✓ Branch 0 taken 2711584 times.
✓ Branch 1 taken 84737 times.
2796321 for (i = start; i < end; i++) {
227 2711584 accu = (int64_t)X_low[i][0] * 0x20000000;
228 2711584 accu += (int64_t)X_low[i - 2][0] * alpha[0];
229 2711584 accu -= (int64_t)X_low[i - 2][1] * alpha[1];
230 2711584 accu += (int64_t)X_low[i - 1][0] * alpha[2];
231 2711584 accu -= (int64_t)X_low[i - 1][1] * alpha[3];
232 2711584 X_high[i][0] = (int)((accu + 0x10000000) >> 29);
233
234 2711584 accu = (int64_t)X_low[i][1] * 0x20000000;
235 2711584 accu += (int64_t)X_low[i - 2][1] * alpha[0];
236 2711584 accu += (int64_t)X_low[i - 2][0] * alpha[1];
237 2711584 accu += (int64_t)X_low[i - 1][1] * alpha[2];
238 2711584 accu += (int64_t)X_low[i - 1][0] * alpha[3];
239 2711584 X_high[i][1] = (int)((accu + 0x10000000) >> 29);
240 }
241 84737 }
242
243 121184 static void sbr_hf_g_filt_c(int (*Y)[2], const int (*X_high)[40][2],
244 const SoftFloat *g_filt, int m_max, intptr_t ixh)
245 {
246 int m;
247 int64_t accu;
248
249
2/2
✓ Branch 0 taken 2711584 times.
✓ Branch 1 taken 121184 times.
2832768 for (m = 0; m < m_max; m++) {
250
1/2
✓ Branch 0 taken 2711584 times.
✗ Branch 1 not taken.
2711584 if (22 - g_filt[m].exp < 61) {
251 2711584 int64_t r = 1LL << (22-g_filt[m].exp);
252 2711584 accu = (int64_t)X_high[m][ixh][0] * ((g_filt[m].mant + 0x40)>>7);
253 2711584 Y[m][0] = (int)((accu + r) >> (23-g_filt[m].exp));
254
255 2711584 accu = (int64_t)X_high[m][ixh][1] * ((g_filt[m].mant + 0x40)>>7);
256 2711584 Y[m][1] = (int)((accu + r) >> (23-g_filt[m].exp));
257 }
258 }
259 121184 }
260
261 119686 static av_always_inline int sbr_hf_apply_noise(int (*Y)[2],
262 const SoftFloat *s_m,
263 const SoftFloat *q_filt,
264 int noise,
265 int phi_sign0,
266 int phi_sign1,
267 int m_max)
268 {
269 int m;
270
271
2/2
✓ Branch 0 taken 2675780 times.
✓ Branch 1 taken 119686 times.
2795466 for (m = 0; m < m_max; m++) {
272 2675780 unsigned y0 = Y[m][0];
273 2675780 unsigned y1 = Y[m][1];
274 2675780 noise = (noise + 1) & 0x1ff;
275
2/2
✓ Branch 0 taken 25746 times.
✓ Branch 1 taken 2650034 times.
2675780 if (s_m[m].mant) {
276 int shift, round;
277
278 25746 shift = 22 - s_m[m].exp;
279
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 25746 times.
25746 if (shift < 1) {
280 av_log(NULL, AV_LOG_ERROR, "Overflow in sbr_hf_apply_noise, shift=%d\n", shift);
281 return AVERROR(ERANGE);
282
1/2
✓ Branch 0 taken 25746 times.
✗ Branch 1 not taken.
25746 } else if (shift < 30) {
283 25746 round = 1 << (shift-1);
284 25746 y0 += (s_m[m].mant * phi_sign0 + round) >> shift;
285 25746 y1 += (s_m[m].mant * phi_sign1 + round) >> shift;
286 }
287 } else {
288 int shift, round, tmp;
289 int64_t accu;
290
291 2650034 shift = 22 - q_filt[m].exp;
292
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2650034 times.
2650034 if (shift < 1) {
293 av_log(NULL, AV_LOG_ERROR, "Overflow in sbr_hf_apply_noise, shift=%d\n", shift);
294 return AVERROR(ERANGE);
295
1/2
✓ Branch 0 taken 2650034 times.
✗ Branch 1 not taken.
2650034 } else if (shift < 30) {
296 2650034 round = 1 << (shift-1);
297
298 2650034 accu = (int64_t)q_filt[m].mant * ff_sbr_noise_table_fixed[noise][0];
299 2650034 tmp = (int)((accu + 0x40000000) >> 31);
300 2650034 y0 += (tmp + round) >> shift;
301
302 2650034 accu = (int64_t)q_filt[m].mant * ff_sbr_noise_table_fixed[noise][1];
303 2650034 tmp = (int)((accu + 0x40000000) >> 31);
304 2650034 y1 += (tmp + round) >> shift;
305 }
306 }
307 2675780 Y[m][0] = y0;
308 2675780 Y[m][1] = y1;
309 2675780 phi_sign1 = -phi_sign1;
310 }
311 119686 return 0;
312 }
313
314 #include "sbrdsp_template.c"
315