FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/sbrdsp.c
Date: 2026-07-18 19:31:15
Exec Total Coverage
Lines: 99 99 100.0%
Functions: 9 9 100.0%
Branches: 20 20 100.0%

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
23 #define USE_FIXED 0
24
25 #include "aac.h"
26 #include "libavutil/attributes.h"
27 #include "libavutil/intfloat.h"
28 #include "sbrdsp.h"
29
30 257463 static float sbr_sum_square_c(float (*x)[2], int n)
31 {
32 257463 float sum0 = 0.0f, sum1 = 0.0f;
33 int i;
34
35
2/2
✓ Branch 0 taken 2825328 times.
✓ Branch 1 taken 257463 times.
3082791 for (i = 0; i < n; i += 2)
36 {
37 2825328 sum0 += x[i + 0][0] * x[i + 0][0];
38 2825328 sum1 += x[i + 0][1] * x[i + 0][1];
39 2825328 sum0 += x[i + 1][0] * x[i + 1][0];
40 2825328 sum1 += x[i + 1][1] * x[i + 1][1];
41 }
42
43 257463 return sum0 + sum1;
44 }
45
46 361540 static void sbr_neg_odd_64_c(float *x)
47 {
48 361540 union av_intfloat32 *xi = (union av_intfloat32*) x;
49 int i;
50
2/2
✓ Branch 0 taken 5784640 times.
✓ Branch 1 taken 361540 times.
6146180 for (i = 1; i < 64; i += 4) {
51 5784640 xi[i + 0].i ^= 1U << 31;
52 5784640 xi[i + 2].i ^= 1U << 31;
53 }
54 361540 }
55
56 369636 static void sbr_qmf_pre_shuffle_c(float *z)
57 {
58 369636 union av_intfloat32 *zi = (union av_intfloat32*) z;
59 int k;
60 369636 zi[64].i = zi[0].i;
61 369636 zi[65].i = zi[1].i;
62
2/2
✓ Branch 0 taken 5544540 times.
✓ Branch 1 taken 369636 times.
5914176 for (k = 1; k < 31; k += 2) {
63 5544540 zi[64 + 2 * k + 0].i = zi[64 - k].i ^ (1U << 31);
64 5544540 zi[64 + 2 * k + 1].i = zi[ k + 1].i;
65 5544540 zi[64 + 2 * k + 2].i = zi[63 - k].i ^ (1U << 31);
66 5544540 zi[64 + 2 * k + 3].i = zi[ k + 2].i;
67 }
68
69 369636 zi[64 + 2 * 31 + 0].i = zi[64 - 31].i ^ (1U << 31);
70 369636 zi[64 + 2 * 31 + 1].i = zi[31 + 1].i;
71 369636 }
72
73 369636 static void sbr_qmf_post_shuffle_c(float W[32][2], const float *z)
74 {
75 369636 const union av_intfloat32 *zi = (const union av_intfloat32*) z;
76 369636 union av_intfloat32 *Wi = (union av_intfloat32*) W;
77 int k;
78
2/2
✓ Branch 0 taken 5914176 times.
✓ Branch 1 taken 369636 times.
6283812 for (k = 0; k < 32; k += 2) {
79 5914176 Wi[2 * k + 0].i = zi[63 - k].i ^ (1U << 31);
80 5914176 Wi[2 * k + 1].i = zi[ k + 0].i;
81 5914176 Wi[2 * k + 2].i = zi[62 - k].i ^ (1U << 31);
82 5914176 Wi[2 * k + 3].i = zi[ k + 1].i;
83 }
84 369636 }
85
86 73604 static void sbr_qmf_deint_neg_c(float *v, const float *src)
87 {
88 73604 const union av_intfloat32 *si = (const union av_intfloat32*)src;
89 73604 union av_intfloat32 *vi = (union av_intfloat32*)v;
90 int i;
91
2/2
✓ Branch 0 taken 2355328 times.
✓ Branch 1 taken 73604 times.
2428932 for (i = 0; i < 32; i++) {
92 2355328 vi[ i].i = si[63 - 2 * i ].i;
93 2355328 vi[63 - i].i = si[63 - 2 * i - 1].i ^ (1U << 31);
94 }
95 73604 }
96
97 #if 0
98 /* This code is slower because it multiplies memory accesses.
99 * It is left for educational purposes and because it may offer
100 * a better reference for writing arch-specific DSP functions. */
101 static av_always_inline void autocorrelate(const float x[40][2],
102 float phi[3][2][2], int lag)
103 {
104 int i;
105 float real_sum = 0.0f;
106 float imag_sum = 0.0f;
107 if (lag) {
108 for (i = 1; i < 38; i++) {
109 real_sum += x[i][0] * x[i+lag][0] + x[i][1] * x[i+lag][1];
110 imag_sum += x[i][0] * x[i+lag][1] - x[i][1] * x[i+lag][0];
111 }
112 phi[2-lag][1][0] = real_sum + x[ 0][0] * x[lag][0] + x[ 0][1] * x[lag][1];
113 phi[2-lag][1][1] = imag_sum + x[ 0][0] * x[lag][1] - x[ 0][1] * x[lag][0];
114 if (lag == 1) {
115 phi[0][0][0] = real_sum + x[38][0] * x[39][0] + x[38][1] * x[39][1];
116 phi[0][0][1] = imag_sum + x[38][0] * x[39][1] - x[38][1] * x[39][0];
117 }
118 } else {
119 for (i = 1; i < 38; i++) {
120 real_sum += x[i][0] * x[i][0] + x[i][1] * x[i][1];
121 }
122 phi[2][1][0] = real_sum + x[ 0][0] * x[ 0][0] + x[ 0][1] * x[ 0][1];
123 phi[1][0][0] = real_sum + x[38][0] * x[38][0] + x[38][1] * x[38][1];
124 }
125 }
126
127 static void sbr_autocorrelate_c(const float x[40][2], float phi[3][2][2])
128 {
129 autocorrelate(x, phi, 0);
130 autocorrelate(x, phi, 1);
131 autocorrelate(x, phi, 2);
132 }
133 #else
134 128160 static void sbr_autocorrelate_c(const float x[40][2], float phi[3][2][2])
135 {
136 128160 float real_sum2 = x[0][0] * x[2][0] + x[0][1] * x[2][1];
137 128160 float imag_sum2 = x[0][0] * x[2][1] - x[0][1] * x[2][0];
138 128160 float real_sum1 = 0.0f, imag_sum1 = 0.0f, real_sum0 = 0.0f;
139 int i;
140
2/2
✓ Branch 0 taken 4741920 times.
✓ Branch 1 taken 128160 times.
4870080 for (i = 1; i < 38; i++) {
141 4741920 real_sum0 += x[i][0] * x[i ][0] + x[i][1] * x[i ][1];
142 4741920 real_sum1 += x[i][0] * x[i + 1][0] + x[i][1] * x[i + 1][1];
143 4741920 imag_sum1 += x[i][0] * x[i + 1][1] - x[i][1] * x[i + 1][0];
144 4741920 real_sum2 += x[i][0] * x[i + 2][0] + x[i][1] * x[i + 2][1];
145 4741920 imag_sum2 += x[i][0] * x[i + 2][1] - x[i][1] * x[i + 2][0];
146 }
147 128160 phi[2 - 2][1][0] = real_sum2;
148 128160 phi[2 - 2][1][1] = imag_sum2;
149 128160 phi[2 ][1][0] = real_sum0 + x[ 0][0] * x[ 0][0] + x[ 0][1] * x[ 0][1];
150 128160 phi[1 ][0][0] = real_sum0 + x[38][0] * x[38][0] + x[38][1] * x[38][1];
151 128160 phi[2 - 1][1][0] = real_sum1 + x[ 0][0] * x[ 1][0] + x[ 0][1] * x[ 1][1];
152 128160 phi[2 - 1][1][1] = imag_sum1 + x[ 0][0] * x[ 1][1] - x[ 0][1] * x[ 1][0];
153 128160 phi[0 ][0][0] = real_sum1 + x[38][0] * x[39][0] + x[38][1] * x[39][1];
154 128160 phi[0 ][0][1] = imag_sum1 + x[38][0] * x[39][1] - x[38][1] * x[39][0];
155 128160 }
156 #endif
157
158 176675 static void sbr_hf_gen_c(float (*X_high)[2], const float (*X_low)[2],
159 const float alpha0[2], const float alpha1[2],
160 float bw, int start, int end)
161 {
162 float alpha[4];
163 int i;
164
165 176675 alpha[0] = alpha1[0] * bw * bw;
166 176675 alpha[1] = alpha1[1] * bw * bw;
167 176675 alpha[2] = alpha0[0] * bw;
168 176675 alpha[3] = alpha0[1] * bw;
169
170
2/2
✓ Branch 0 taken 5661536 times.
✓ Branch 1 taken 176675 times.
5838211 for (i = start; i < end; i++) {
171 5661536 X_high[i][0] =
172 5661536 X_low[i - 2][0] * alpha[0] -
173 5661536 X_low[i - 2][1] * alpha[1] +
174 5661536 X_low[i - 1][0] * alpha[2] -
175 5661536 X_low[i - 1][1] * alpha[3] +
176 5661536 X_low[i][0];
177 5661536 X_high[i][1] =
178 5661536 X_low[i - 2][1] * alpha[0] +
179 5661536 X_low[i - 2][0] * alpha[1] +
180 5661536 X_low[i - 1][1] * alpha[2] +
181 5661536 X_low[i - 1][0] * alpha[3] +
182 5661536 X_low[i][1];
183 }
184 176675 }
185
186 216740 static void sbr_hf_g_filt_c(float (*Y)[2], const float (*X_high)[40][2],
187 const float *g_filt, int m_max, intptr_t ixh)
188 {
189 int m;
190
191
2/2
✓ Branch 0 taken 5650144 times.
✓ Branch 1 taken 216740 times.
5866884 for (m = 0; m < m_max; m++) {
192 5650144 Y[m][0] = X_high[m][ixh][0] * g_filt[m];
193 5650144 Y[m][1] = X_high[m][ixh][1] * g_filt[m];
194 }
195 216740 }
196
197 214486 static av_always_inline void sbr_hf_apply_noise(float (*Y)[2],
198 const float *s_m,
199 const float *q_filt,
200 int noise,
201 float phi_sign0,
202 float phi_sign1,
203 int m_max)
204 {
205 int m;
206
207
2/2
✓ Branch 0 taken 5594464 times.
✓ Branch 1 taken 214486 times.
5808950 for (m = 0; m < m_max; m++) {
208 5594464 float y0 = Y[m][0];
209 5594464 float y1 = Y[m][1];
210 5594464 noise = (noise + 1) & 0x1ff;
211
2/2
✓ Branch 0 taken 38558 times.
✓ Branch 1 taken 5555906 times.
5594464 if (s_m[m]) {
212 38558 y0 += s_m[m] * phi_sign0;
213 38558 y1 += s_m[m] * phi_sign1;
214 } else {
215 5555906 y0 += q_filt[m] * ff_sbr_noise_table[noise][0];
216 5555906 y1 += q_filt[m] * ff_sbr_noise_table[noise][1];
217 }
218 5594464 Y[m][0] = y0;
219 5594464 Y[m][1] = y1;
220 5594464 phi_sign1 = -phi_sign1;
221 }
222 214486 }
223
224 #include "sbrdsp_template.c"
225