Mercurial > hg > qm-dsp
comparison base/SincWindow.cpp @ 126:7669b3aa3bc9
Add sinc
author | Chris Cannam |
---|---|
date | Thu, 10 Oct 2013 17:53:41 +0100 |
parents | |
children | fdaa63607c15 |
comparison
equal
deleted
inserted
replaced
125:5351b5e9ad9f | 126:7669b3aa3bc9 |
---|---|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ | |
2 | |
3 /* | |
4 QM DSP library | |
5 Centre for Digital Music, Queen Mary, University of London. | |
6 | |
7 This program is free software; you can redistribute it and/or | |
8 modify it under the terms of the GNU General Public License as | |
9 published by the Free Software Foundation; either version 2 of the | |
10 License, or (at your option) any later version. See the file | |
11 COPYING included with this distribution for more information. | |
12 */ | |
13 | |
14 #include "SincWindow.h" | |
15 | |
16 #include <cmath> | |
17 | |
18 void | |
19 SincWindow::init() | |
20 { | |
21 if (m_length < 1) { | |
22 return; | |
23 } else if (m_length < 2) { | |
24 m_window.push_back(1); | |
25 return; | |
26 } else { | |
27 | |
28 int n0 = (m_length % 2 == 0 ? m_length/2 : (m_length - 1)/2); | |
29 int n1 = (m_length % 2 == 0 ? m_length/2 : (m_length + 1)/2); | |
30 double m = 2 * M_PI / m_p; | |
31 | |
32 for (int i = 0; i < n0; ++i) { | |
33 double x = ((m_length / 2) - i) * m; | |
34 m_window.push_back(sin(x) / x); | |
35 } | |
36 | |
37 m_window.push_back(1.0); | |
38 | |
39 for (int i = 1; i < n1; ++i) { | |
40 double x = i * m; | |
41 m_window.push_back(sin(x) / x); | |
42 } | |
43 } | |
44 } | |
45 |