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/error.h"
21 #include "libavutil/libm.h"
22 #include "libavutil/mathematics.h"
23 #include "libavutil/attributes.h"
24 #include "libavutil/mem.h"
25 #include "kbdwin.h"
26 
27 av_cold static int kbd_window_init(float *float_window, int *int_window, float alpha, int n)
28 {
29  int i;
30  double sum = 0.0, tmp;
31  double scale = 0.0;
32  double temp_small[FF_KBD_WINDOW_MAX / 2 + 1];
33  double *temp= n<=FF_KBD_WINDOW_MAX ? temp_small : av_malloc((n/2+1) * sizeof(*temp));
34  double alpha2 = 4 * (alpha * M_PI / n) * (alpha * M_PI / n);
35 
36  if (!temp)
37  return AVERROR(ENOMEM);
38 
39  for (i = 0; i <= n / 2; i++) {
40  tmp = alpha2 * i * (n - i);
41  temp[i] = av_bessel_i0(sqrt(tmp));
42  scale += temp[i] * (1 + (i && i<n/2));
43  }
44  scale = 1.0/(scale + 1);
45 
46  for (i = 0; i <= n / 2; i++) {
47  sum += temp[i];
48  if (float_window) float_window[i] = sqrt(sum * scale);
49  else int_window[i] = lrint(2147483647 * sqrt(sum * scale));
50  }
51  for (; i < n; i++) {
52  sum += temp[n - i];
53  if (float_window) float_window[i] = sqrt(sum * scale);
54  else int_window[i] = lrint(2147483647 * sqrt(sum * scale));
55  }
56  if (temp != temp_small)
57  av_free(temp);
58  return 0;
59 }
60 
61 av_cold int avpriv_kbd_window_init(float *window, float alpha, int n)
62 {
63  return kbd_window_init(window, NULL, alpha, n);
64 }
65 
67 {
68  return kbd_window_init(NULL, window, alpha, n);
69 }
avpriv_kbd_window_init
av_cold int avpriv_kbd_window_init(float *window, float alpha, int n)
Generate a Kaiser-Bessel Derived Window.
Definition: kbdwin.c:61
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
libm.h
FF_KBD_WINDOW_MAX
#define FF_KBD_WINDOW_MAX
Maximum window size for avpriv_kbd_window_init.
Definition: kbdwin.h:27
kbd_window_init
static av_cold int kbd_window_init(float *float_window, int *int_window, float alpha, int n)
Definition: kbdwin.c:27
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
av_malloc
#define av_malloc(s)
Definition: tableprint_vlc.h:30
window
static SDL_Window * window
Definition: ffplay.c:360
scale
static av_always_inline float scale(float x, float s)
Definition: vf_v360.c:1389
avassert.h
lrint
#define lrint
Definition: tablegen.h:53
av_cold
#define av_cold
Definition: attributes.h:90
kbdwin.h
NULL
#define NULL
Definition: coverity.c:32
error.h
attributes.h
M_PI
#define M_PI
Definition: mathematics.h:67
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:255
temp
else temp
Definition: vf_mcdeint.c:263
avpriv_kbd_window_init_fixed
av_cold int avpriv_kbd_window_init_fixed(int32_t *window, float alpha, int n)
Definition: kbdwin.c:66
mem.h
av_free
#define av_free(p)
Definition: tableprint_vlc.h:33
alpha
static const int16_t alpha[]
Definition: ilbcdata.h:55
int32_t
int32_t
Definition: audioconvert.c:56