Debian Codegraph @

libs/Music/SPWindow.h

raw
1 // Copyright 2007 "Gilles Degottex"
2
3 // This file is part of "Music"
4
5 // "Music" is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU Lesser General Public License as published by
7 // the Free Software Foundation; either version 2.1 of the License, or
8 // (at your option) any later version.
9 //
10 // "Music" is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
19
20 #ifndef _SPWindow_h_
21 #define _SPWindow_h_
22
23 #include <vector>
24 #include <CppAddons/CAMath.h>
25
26 namespace Music
27 {
28 std::vector<double> hann(int n);
29 std::vector<double> hamming(int n);
30
31 inline double win_sinc(double x, double f)
32 {
33 if(x==0.5) return 1.0;
34 double s = Math::sinc((x-0.5)*f);
35 return s*s;
36 }
37
38 struct Win_Sinc
39 {
40 double m_f;
41
42 Win_Sinc(double f) : m_f(f) {}
43
44 double operator()(double x) {return win_sinc(x, m_f);}
45 };
46
47 //! usefull gauss fonction
48 /*!
49 * \param x \f$\approx\in [0,1]\f$
50 * \param f width factor
51 */
52 inline double win_gauss(double x, double f)
53 {
54 return Math::gauss((x-0.5)*f);
55 }
56
57 //! object fonction of \ref win_gauss
58 struct Win_Gauss
59 {
60 double m_g;
61
62 Win_Gauss(double g) : m_g(g) {}
63
64 double operator()(double x) {return win_gauss(x, m_g);}
65 };
66
67 //! compute integrale of fn \f$\in [0,1]\f$
68 /*! with a Simpson algorithm
69 */
70 template<typename Fn>
71 inline double Usefull(Fn fn, double simpsonStep=0.001)
72 {
73 return Math::Simpson(0.0, 1.0, fn, simpsonStep);
74 }
75 }
76
77 #endif // _SPWindow_h_