LCOV - code coverage report
Current view: top level - libavfilter - window_func.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 0 129 0.0 %
Date: 2017-12-16 01:21:47 Functions: 0 1 0.0 %

          Line data    Source code
       1             : /*
       2             :  * Copyright (c) 2015 Paul B Mahol
       3             :  *
       4             :  * This file is part of FFmpeg.
       5             :  *
       6             :  * FFmpeg is free software; you can redistribute it and/or
       7             :  * modify it under the terms of the GNU Lesser General Public
       8             :  * License as published by the Free Software Foundation; either
       9             :  * version 2.1 of the License, or (at your option) any later version.
      10             :  *
      11             :  * FFmpeg is distributed in the hope that it will be useful,
      12             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      13             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      14             :  * Lesser General Public License for more details.
      15             :  *
      16             :  * You should have received a copy of the GNU Lesser General Public
      17             :  * License along with FFmpeg; if not, write to the Free Software
      18             :  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
      19             :  */
      20             : 
      21             : 
      22             : #ifndef AVFILTER_WINDOW_FUNC_H
      23             : #define AVFILTER_WINDOW_FUNC_H
      24             : 
      25             : #include <math.h>
      26             : #include "libavutil/avassert.h"
      27             : 
      28             : enum WindowFunc     { WFUNC_RECT, WFUNC_HANNING, WFUNC_HAMMING, WFUNC_BLACKMAN,
      29             :                       WFUNC_BARTLETT, WFUNC_WELCH, WFUNC_FLATTOP,
      30             :                       WFUNC_BHARRIS, WFUNC_BNUTTALL, WFUNC_SINE, WFUNC_NUTTALL,
      31             :                       WFUNC_BHANN, WFUNC_LANCZOS, WFUNC_GAUSS, WFUNC_TUKEY,
      32             :                       WFUNC_DOLPH, WFUNC_CAUCHY, WFUNC_PARZEN, WFUNC_POISSON,
      33             :                       NB_WFUNC };
      34             : 
      35           0 : static inline void generate_window_func(float *lut, int N, int win_func,
      36             :                                         float *overlap)
      37             : {
      38             :     int n;
      39             : 
      40           0 :     switch (win_func) {
      41           0 :     case WFUNC_RECT:
      42           0 :         for (n = 0; n < N; n++)
      43           0 :             lut[n] = 1.;
      44           0 :         *overlap = 0.;
      45           0 :         break;
      46           0 :     case WFUNC_BARTLETT:
      47           0 :         for (n = 0; n < N; n++)
      48           0 :             lut[n] = 1.-fabs((n-(N-1)/2.)/((N-1)/2.));
      49           0 :         *overlap = 0.5;
      50           0 :         break;
      51           0 :     case WFUNC_HANNING:
      52           0 :         for (n = 0; n < N; n++)
      53           0 :             lut[n] = .5*(1-cos(2*M_PI*n/(N-1)));
      54           0 :         *overlap = 0.5;
      55           0 :         break;
      56           0 :     case WFUNC_HAMMING:
      57           0 :         for (n = 0; n < N; n++)
      58           0 :             lut[n] = .54-.46*cos(2*M_PI*n/(N-1));
      59           0 :         *overlap = 0.5;
      60           0 :         break;
      61           0 :     case WFUNC_BLACKMAN:
      62           0 :         for (n = 0; n < N; n++)
      63           0 :             lut[n] = .42659-.49656*cos(2*M_PI*n/(N-1))+.076849*cos(4*M_PI*n/(N-1));
      64           0 :         *overlap = 0.661;
      65           0 :         break;
      66           0 :     case WFUNC_WELCH:
      67           0 :         for (n = 0; n < N; n++)
      68           0 :             lut[n] = 1.-(n-(N-1)/2.)/((N-1)/2.)*(n-(N-1)/2.)/((N-1)/2.);
      69           0 :         *overlap = 0.293;
      70           0 :         break;
      71           0 :     case WFUNC_FLATTOP:
      72           0 :         for (n = 0; n < N; n++)
      73           0 :             lut[n] = 1.-1.985844164102*cos( 2*M_PI*n/(N-1))+1.791176438506*cos( 4*M_PI*n/(N-1))-
      74           0 :             1.282075284005*cos( 6*M_PI*n/(N-1))+0.667777530266*cos( 8*M_PI*n/(N-1))-
      75           0 :             0.240160796576*cos(10*M_PI*n/(N-1))+0.056656381764*cos(12*M_PI*n/(N-1))-
      76           0 :             0.008134974479*cos(14*M_PI*n/(N-1))+0.000624544650*cos(16*M_PI*n/(N-1))-
      77           0 :             0.000019808998*cos(18*M_PI*n/(N-1))+0.000000132974*cos(20*M_PI*n/(N-1));
      78           0 :         *overlap = 0.841;
      79           0 :         break;
      80           0 :     case WFUNC_BHARRIS:
      81           0 :         for (n = 0; n < N; n++)
      82           0 :             lut[n] = 0.35875-0.48829*cos(2*M_PI*n/(N-1))+0.14128*cos(4*M_PI*n/(N-1))-0.01168*cos(6*M_PI*n/(N-1));
      83           0 :         *overlap = 0.661;
      84           0 :         break;
      85           0 :     case WFUNC_BNUTTALL:
      86           0 :         for (n = 0; n < N; n++)
      87           0 :             lut[n] = 0.3635819-0.4891775*cos(2*M_PI*n/(N-1))+0.1365995*cos(4*M_PI*n/(N-1))-0.0106411*cos(6*M_PI*n/(N-1));
      88           0 :         *overlap = 0.661;
      89           0 :         break;
      90           0 :     case WFUNC_BHANN:
      91           0 :         for (n = 0; n < N; n++)
      92           0 :             lut[n] = 0.62-0.48*fabs(n/(double)(N-1)-.5)-0.38*cos(2*M_PI*n/(N-1));
      93           0 :         *overlap = 0.5;
      94           0 :         break;
      95           0 :     case WFUNC_SINE:
      96           0 :         for (n = 0; n < N; n++)
      97           0 :             lut[n] = sin(M_PI*n/(N-1));
      98           0 :         *overlap = 0.75;
      99           0 :         break;
     100           0 :     case WFUNC_NUTTALL:
     101           0 :         for (n = 0; n < N; n++)
     102           0 :             lut[n] = 0.355768-0.487396*cos(2*M_PI*n/(N-1))+0.144232*cos(4*M_PI*n/(N-1))-0.012604*cos(6*M_PI*n/(N-1));
     103           0 :         *overlap = 0.663;
     104           0 :         break;
     105           0 :     case WFUNC_LANCZOS:
     106             :         #define SINC(x) (!(x)) ? 1 : sin(M_PI * (x))/(M_PI * (x));
     107           0 :         for (n = 0; n < N; n++)
     108           0 :             lut[n] = SINC((2.*n)/(N-1)-1);
     109           0 :         *overlap = 0.75;
     110           0 :         break;
     111           0 :     case WFUNC_GAUSS:
     112             :         #define SQR(x) ((x)*(x))
     113           0 :         for (n = 0; n < N; n++)
     114           0 :             lut[n] = exp(-0.5 * SQR((n-(N-1)/2)/(0.4*(N-1)/2.f)));
     115           0 :         *overlap = 0.75;
     116           0 :         break;
     117           0 :     case WFUNC_TUKEY:
     118           0 :         for (n = 0; n < N; n++) {
     119           0 :             float M = (N-1)/2.;
     120             : 
     121           0 :             if (FFABS(n - M) >= 0.3 * M) {
     122           0 :                 lut[n] = 0.5 * (1 + cos((M_PI*(FFABS(n - M) - 0.3 * M))/((1 - 0.3) * M)));
     123             :             } else {
     124           0 :                 lut[n] = 1;
     125             :             }
     126             :         }
     127           0 :         *overlap = 0.33;
     128           0 :         break;
     129           0 :     case WFUNC_DOLPH: {
     130           0 :         double b = cosh(7.6009022095419887 / (N-1)), sum, t, c, norm = 0;
     131             :         int j;
     132           0 :         for (c = 1 - 1 / (b*b), n = (N-1) / 2; n >= 0; --n) {
     133           0 :             for (sum = !n, b = t = j = 1; j <= n && sum != t; b *= (n-j) * (1./j), ++j)
     134           0 :                 t = sum, sum += (b *= c * (N - n - j) * (1./j));
     135           0 :             sum /= (N - 1 - n), sum /= (norm = norm ? norm : sum);
     136           0 :             lut[n] = sum;
     137           0 :             lut[N - 1 - n] = sum;
     138             :         }
     139           0 :         *overlap = 0.5;}
     140           0 :         break;
     141           0 :     case WFUNC_CAUCHY:
     142           0 :         for (n = 0; n < N; n++) {
     143           0 :             double x = 2 * ((n / (double)(N - 1)) - .5);
     144             : 
     145           0 :             if (x <= -.5 || x >= .5) {
     146           0 :                 lut[n] = 0;
     147             :             } else {
     148           0 :                 lut[n] = FFMIN(1, fabs(1/(1+4*16*x*x)));
     149             :             }
     150             :         }
     151           0 :         *overlap = 0.75;
     152           0 :         break;
     153           0 :     case WFUNC_PARZEN:
     154           0 :         for (n = 0; n < N; n++) {
     155           0 :             double x = 2 * ((n / (double)(N - 1)) - .5);
     156             : 
     157           0 :             if (x > 0.25 && x <= 0.5) {
     158           0 :                 lut[n] = -2 * powf(-1 + 2 * x, 3);
     159           0 :             } else if (x >= -.5 && x < -.25) {
     160           0 :                 lut[n] = 2 * powf(1 + 2 * x, 3);
     161           0 :             } else if (x >= -.25 && x < 0) {
     162           0 :                 lut[n] = 1 - 24 * x * x - 48 * x * x * x;
     163           0 :             } else if (x >= 0 && x <= .25) {
     164           0 :                 lut[n] = 1 - 24 * x * x + 48 * x * x * x;
     165             :             } else {
     166           0 :                 lut[n] = 0;
     167             :             }
     168             :         }
     169           0 :         *overlap = 0.75;
     170           0 :         break;
     171           0 :     case WFUNC_POISSON:
     172           0 :         for (n = 0; n < N; n++) {
     173           0 :             double x = 2 * ((n / (double)(N - 1)) - .5);
     174             : 
     175           0 :             if (x >= 0 && x <= .5) {
     176           0 :                 lut[n] = exp(-6*x);
     177           0 :             } else if (x < 0 && x >= -.5) {
     178           0 :                 lut[n] = exp(6*x);
     179             :             } else {
     180           0 :                 lut[n] = 0;
     181             :             }
     182             :         }
     183           0 :         *overlap = 0.75;
     184           0 :         break;
     185           0 :     default:
     186           0 :         av_assert0(0);
     187             :     }
     188           0 : }
     189             : 
     190             : #endif /* AVFILTER_WINDOW_FUNC_H */

Generated by: LCOV version 1.13