FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/kbdwin.c
Date: 2021-09-26 18:22:30
Exec Total Coverage
Lines: 20 20 100.0%
Branches: 9 10 90.0%

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 "libavutil/avassert.h"
20 #include "libavutil/mathematics.h"
21 #include "libavutil/attributes.h"
22 #include "kbdwin.h"
23
24 #define BESSEL_I0_ITER 50 // default: 50 iterations of Bessel I0 approximation
25
26 735 av_cold void ff_kbd_window_init(float *window, float alpha, int n)
27 {
28 int i, j;
29 735 double sum = 0.0, bessel, tmp;
30 double local_window[FF_KBD_WINDOW_MAX];
31 735 double alpha2 = (alpha * M_PI / n) * (alpha * M_PI / n);
32
33
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 735 times.
735 av_assert0(n <= FF_KBD_WINDOW_MAX);
34
35
2/2
✓ Branch 0 taken 386952 times.
✓ Branch 1 taken 735 times.
387687 for (i = 0; i < n; i++) {
36 386952 tmp = i * (n - i) * alpha2;
37 386952 bessel = 1.0;
38
2/2
✓ Branch 0 taken 19347600 times.
✓ Branch 1 taken 386952 times.
19734552 for (j = BESSEL_I0_ITER; j > 0; j--)
39 19347600 bessel = bessel * tmp / (j * j) + 1;
40 386952 sum += bessel;
41 386952 local_window[i] = sum;
42 }
43
44 735 sum++;
45
2/2
✓ Branch 0 taken 386952 times.
✓ Branch 1 taken 735 times.
387687 for (i = 0; i < n; i++)
46 386952 window[i] = sqrt(local_window[i] / sum);
47 735 }
48
49 36 av_cold void ff_kbd_window_init_fixed(int32_t *window, float alpha, int n)
50 {
51 int i;
52 float local_window[FF_KBD_WINDOW_MAX];
53
54 36 ff_kbd_window_init(local_window, alpha, n);
55
2/2
✓ Branch 0 taken 19456 times.
✓ Branch 1 taken 36 times.
19492 for (i = 0; i < n; i++)
56 19456 window[i] = (int)floor(2147483647.0 * local_window[i] + 0.5);
57 36 }
58