FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/kbdwin.c
Date: 2026-09-15 15:24:09
Exec Total Coverage
Lines: 25 25 100.0%
Functions: 3 3 100.0%
Branches: 15 16 93.8%

Line Branch Exec Source
1 /*
2 * This file is part of FFmpeg.
3 *
4 * FFmpeg is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * FFmpeg is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19 #include <math.h>
20
21 #include "libavutil/avassert.h"
22 #include "libavutil/mathematics.h"
23 #include "libavutil/attributes.h"
24 #include "kbdwin.h"
25
26 1666 av_cold static void kbd_window_init(float *float_window, int *int_window, float alpha, int n)
27 {
28 int i;
29 1666 double sum = 0.0, tmp;
30 1666 double scale = 0.0;
31 double temp[FF_KBD_WINDOW_MAX / 2 + 1];
32 1666 double alpha2 = 4 * (alpha * M_PI / n) * (alpha * M_PI / n);
33
34
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1666 times.
1666 av_assert0(n <= FF_KBD_WINDOW_MAX);
35
36
2/2
✓ Branch 0 taken 449838 times.
✓ Branch 1 taken 1666 times.
451504 for (i = 0; i <= n / 2; i++) {
37 449838 tmp = i * (n - i) * alpha2;
38 449838 temp[i] = av_bessel_i0(sqrt(tmp));
39
4/4
✓ Branch 0 taken 448172 times.
✓ Branch 1 taken 1666 times.
✓ Branch 2 taken 446506 times.
✓ Branch 3 taken 1666 times.
449838 scale += temp[i] * (1 + (i && i<n/2));
40 }
41 1666 scale = 1.0/(scale + 1);
42
43
2/2
✓ Branch 0 taken 449838 times.
✓ Branch 1 taken 1666 times.
451504 for (i = 0; i <= n / 2; i++) {
44 449838 sum += temp[i];
45
2/2
✓ Branch 0 taken 428863 times.
✓ Branch 1 taken 20975 times.
449838 if (float_window) float_window[i] = sqrt(sum * scale);
46 20975 else int_window[i] = lrint(2147483647 * sqrt(sum * scale));
47 }
48
2/2
✓ Branch 0 taken 446506 times.
✓ Branch 1 taken 1666 times.
448172 for (; i < n; i++) {
49 446506 sum += temp[n - i];
50
2/2
✓ Branch 0 taken 425697 times.
✓ Branch 1 taken 20809 times.
446506 if (float_window) float_window[i] = sqrt(sum * scale);
51 20809 else int_window[i] = lrint(2147483647 * sqrt(sum * scale));
52 }
53 1666 }
54
55 1583 av_cold void ff_kbd_window_init(float *window, float alpha, int n)
56 {
57 1583 kbd_window_init(window, NULL, alpha, n);
58 1583 }
59
60 83 av_cold void ff_kbd_window_init_fixed(int32_t *window, float alpha, int n)
61 {
62 83 kbd_window_init(NULL, window, alpha, n);
63 83 }
64