FFmpeg
kbdwin.c
Go to the documentation of this file.
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 {
27  int i;
28  double sum = 0.0, tmp;
29  double scale = 0.0;
30  double temp[FF_KBD_WINDOW_MAX / 2 + 1];
31  double alpha2 = 4 * (alpha * M_PI / n) * (alpha * M_PI / n);
32 
34 
35  for (i = 0; i <= n / 2; i++) {
36  tmp = i * (n - i) * alpha2;
37  temp[i] = av_bessel_i0(sqrt(tmp));
38  scale += temp[i] * (1 + (i && i<n/2));
39  }
40  scale = 1.0/(scale + 1);
41 
42  for (i = 0; i <= n / 2; i++) {
43  sum += temp[i];
44  if (float_window) float_window[i] = sqrt(sum * scale);
45  else int_window[i] = lrint(2147483647 * sqrt(sum * scale));
46  }
47  for (; i < n; i++) {
48  sum += temp[n - i];
49  if (float_window) float_window[i] = sqrt(sum * scale);
50  else int_window[i] = lrint(2147483647 * sqrt(sum * scale));
51  }
52 }
53 
54 av_cold void ff_kbd_window_init(float *window, float alpha, int n)
55 {
57 }
58 
60 {
62 }
libm.h
FF_KBD_WINDOW_MAX
#define FF_KBD_WINDOW_MAX
Maximum window size for ff_kbd_window_init.
Definition: kbdwin.h:27
ff_kbd_window_init_fixed
av_cold void ff_kbd_window_init_fixed(int32_t *window, float alpha, int n)
Definition: kbdwin.c:59
av_bessel_i0
double av_bessel_i0(double x)
0th order modified bessel function of the first kind.
Definition: mathematics.c:257
tmp
static uint8_t tmp[11]
Definition: aes_ctr.c:28
mathematics.h
window
static SDL_Window * window
Definition: ffplay.c:361
avassert.h
lrint
#define lrint
Definition: tablegen.h:53
av_cold
#define av_cold
Definition: attributes.h:90
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:40
kbdwin.h
NULL
#define NULL
Definition: coverity.c:32
attributes.h
M_PI
#define M_PI
Definition: mathematics.h:67
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
ff_kbd_window_init
av_cold void ff_kbd_window_init(float *window, float alpha, int n)
Generate a Kaiser-Bessel Derived Window.
Definition: kbdwin.c:54
temp
else temp
Definition: vf_mcdeint.c:263
kbd_window_init
static av_cold void kbd_window_init(float *float_window, int *int_window, float alpha, int n)
Definition: kbdwin.c:25
scale
static void scale(int *out, const int *in, const int w, const int h, const int shift)
Definition: intra.c:291
alpha
static const int16_t alpha[]
Definition: ilbcdata.h:55
int32_t
int32_t
Definition: audioconvert.c:56