Coverage Report

Created: 2026-02-14 06:59

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/ffmpeg/libavcodec/kbdwin.c
Line
Count
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/libm.h"
21
#include "libavutil/mathematics.h"
22
#include "libavutil/attributes.h"
23
#include "kbdwin.h"
24
25
av_cold static void kbd_window_init(float *float_window, int *int_window, float alpha, int n)
26
568k
{
27
568k
   int i;
28
568k
   double sum = 0.0, tmp;
29
568k
   double scale = 0.0;
30
568k
   double temp[FF_KBD_WINDOW_MAX / 2 + 1];
31
568k
   double alpha2 = 4 * (alpha * M_PI / n) * (alpha * M_PI / n);
32
33
568k
   av_assert0(n <= FF_KBD_WINDOW_MAX);
34
35
73.9M
   for (i = 0; i <= n / 2; i++) {
36
73.3M
       tmp = i * (n - i) * alpha2;
37
73.3M
       temp[i] = av_bessel_i0(sqrt(tmp));
38
73.3M
       scale += temp[i] * (1 + (i && i<n/2));
39
73.3M
   }
40
568k
   scale = 1.0/(scale + 1);
41
42
73.9M
   for (i = 0; i <= n / 2; i++) {
43
73.3M
       sum += temp[i];
44
73.3M
       if (float_window) float_window[i] = sqrt(sum * scale);
45
27.6M
       else                int_window[i] = lrint(2147483647 * sqrt(sum * scale));
46
73.3M
   }
47
72.7M
   for (; i < n; i++) {
48
72.1M
       sum += temp[n - i];
49
72.1M
       if (float_window) float_window[i] = sqrt(sum * scale);
50
27.2M
       else                int_window[i] = lrint(2147483647 * sqrt(sum * scale));
51
72.1M
   }
52
568k
}
53
54
av_cold void ff_kbd_window_init(float *window, float alpha, int n)
55
353k
{
56
353k
    kbd_window_init(window, NULL, alpha, n);
57
353k
}
58
59
av_cold void ff_kbd_window_init_fixed(int32_t *window, float alpha, int n)
60
214k
{
61
    kbd_window_init(NULL, window, alpha, n);
62
214k
}