qm-dsp  1.8
SincWindow.cpp
Go to the documentation of this file.
00001 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
00002 
00003 /*
00004     QM DSP library
00005     Centre for Digital Music, Queen Mary, University of London.
00006  
00007     This program is free software; you can redistribute it and/or
00008     modify it under the terms of the GNU General Public License as
00009     published by the Free Software Foundation; either version 2 of the
00010     License, or (at your option) any later version.  See the file
00011     COPYING included with this distribution for more information.
00012 */
00013 
00014 #include "SincWindow.h"
00015 
00016 #include <cmath>
00017 
00018 void
00019 SincWindow::init()
00020 {
00021     if (m_length < 1) {
00022         return;
00023     } else if (m_length < 2) {
00024         m_window.push_back(1);
00025         return;
00026     } else {
00027 
00028         int n0 = (m_length % 2 == 0 ? m_length/2 : (m_length - 1)/2);
00029         int n1 = (m_length % 2 == 0 ? m_length/2 : (m_length + 1)/2);
00030         double m = 2 * M_PI / m_p;
00031 
00032         for (int i = 0; i < n0; ++i) {
00033             double x = ((m_length / 2) - i) * m;
00034             m_window.push_back(sin(x) / x);
00035         }
00036 
00037         m_window.push_back(1.0);
00038 
00039         for (int i = 1; i < n1; ++i) {
00040             double x = i * m;
00041             m_window.push_back(sin(x) / x);
00042         }
00043     }
00044 }
00045