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/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 av_cold void ff_kbd_window_init(float *window, float alpha, int n)
27 {
28  int i, j;
29  double sum = 0.0, bessel, tmp;
30  double local_window[FF_KBD_WINDOW_MAX];
31  double alpha2 = (alpha * M_PI / n) * (alpha * M_PI / n);
32 
34 
35  for (i = 0; i < n; i++) {
36  tmp = i * (n - i) * alpha2;
37  bessel = 1.0;
38  for (j = BESSEL_I0_ITER; j > 0; j--)
39  bessel = bessel * tmp / (j * j) + 1;
40  sum += bessel;
41  local_window[i] = sum;
42  }
43 
44  sum++;
45  for (i = 0; i < n; i++)
46  window[i] = sqrt(local_window[i] / sum);
47 }
48 
50 {
51  int i;
52  float local_window[FF_KBD_WINDOW_MAX];
53 
54  ff_kbd_window_init(local_window, alpha, n);
55  for (i = 0; i < n; i++)
56  window[i] = (int)floor(2147483647.0 * local_window[i] + 0.5);
57 }
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:49
tmp
static uint8_t tmp[11]
Definition: aes_ctr.c:26
mathematics.h
window
static SDL_Window * window
Definition: ffplay.c:364
avassert.h
av_cold
#define av_cold
Definition: attributes.h:90
floor
static __device__ float floor(float a)
Definition: cuda_runtime.h:173
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
kbdwin.h
bessel
static double bessel(double x)
0th order modified bessel function of the first kind.
Definition: resample.c:73
attributes.h
M_PI
#define M_PI
Definition: mathematics.h:52
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:271
BESSEL_I0_ITER
#define BESSEL_I0_ITER
Definition: kbdwin.c:24
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:26
alpha
static const int16_t alpha[]
Definition: ilbcdata.h:55
int32_t
int32_t
Definition: audioconvert.c:56