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