Libav 0.7.1
libavcodec/kbdwin.c
Go to the documentation of this file.
00001 /*
00002  * This file is part of Libav.
00003  *
00004  * Libav is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU Lesser General Public
00006  * License as published by the Free Software Foundation; either
00007  * version 2.1 of the License, or (at your option) any later version.
00008  *
00009  * Libav is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * Lesser General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU Lesser General Public
00015  * License along with Libav; if not, write to the Free Software
00016  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00017  */
00018 
00019 #include <assert.h>
00020 #include <libavutil/mathematics.h>
00021 #include "libavutil/attributes.h"
00022 #include "kbdwin.h"
00023 
00024 #define BESSEL_I0_ITER 50 // default: 50 iterations of Bessel I0 approximation
00025 
00026 av_cold void ff_kbd_window_init(float *window, float alpha, int n)
00027 {
00028    int i, j;
00029    double sum = 0.0, bessel, tmp;
00030    double local_window[FF_KBD_WINDOW_MAX];
00031    double alpha2 = (alpha * M_PI / n) * (alpha * M_PI / n);
00032 
00033    assert(n <= FF_KBD_WINDOW_MAX);
00034 
00035    for (i = 0; i < n; i++) {
00036        tmp = i * (n - i) * alpha2;
00037        bessel = 1.0;
00038        for (j = BESSEL_I0_ITER; j > 0; j--)
00039            bessel = bessel * tmp / (j * j) + 1;
00040        sum += bessel;
00041        local_window[i] = sum;
00042    }
00043 
00044    sum++;
00045    for (i = 0; i < n; i++)
00046        window[i] = sqrt(local_window[i] / sum);
00047 }
00048