Debian Codegraph @

libs/Music/SPWindow.cpp

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 #include "SPWindow.h"
21 using namespace std;
22
23 vector<double> Music::hann(int n)
24 {
25 vector<double> win(n);
26
27 for(size_t n=0; n<win.size(); n++)
28 win[n] = (1-cos(2*Math::Pi*n/(win.size()-1))) / (win.size()-1);
29
30 return win;
31 }
32
33 vector<double> Music::hamming(int n)
34 {
35 vector<double> win(n);
36
37 double s = 0.0;
38 for(size_t n=0; n<win.size(); n++)
39 {
40 win[n] = (0.54-0.46*cos(2*Math::Pi*n/(win.size()-1)));
41 s += win[n];
42 }
43 for(size_t n=0; n<win.size(); n++)
44 win[n] /= s;
45
46 return win;
47 }