Chris@126: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ Chris@126: Chris@126: /* Chris@126: QM DSP library Chris@126: Centre for Digital Music, Queen Mary, University of London. Chris@126: Chris@126: This program is free software; you can redistribute it and/or Chris@126: modify it under the terms of the GNU General Public License as Chris@126: published by the Free Software Foundation; either version 2 of the Chris@126: License, or (at your option) any later version. See the file Chris@126: COPYING included with this distribution for more information. Chris@126: */ Chris@126: Chris@126: #ifndef SINC_WINDOW_H Chris@126: #define SINC_WINDOW_H Chris@126: Chris@126: #include Chris@126: Chris@126: class SincWindow Chris@126: { Chris@126: public: Chris@126: /** Chris@126: * Construct a windower of the given length, containing the values Chris@126: * of sinc(x) with x=0 in the middle, i.e. at sample (length-1)/2 Chris@126: * for odd or (length/2)+1 for even length, such that the distance Chris@126: * from -pi to pi (the nearest zero crossings either side of the Chris@126: * peak) is p samples. Chris@126: */ Chris@126: SincWindow(int length, double p) : m_length(length), m_p(p) { init(); } Chris@126: Chris@126: int getLength() const { Chris@126: return m_length; Chris@126: } Chris@126: Chris@126: const double *getWindow() const { Chris@126: return m_window.data(); Chris@126: } Chris@126: Chris@126: void cut(double *src) const { Chris@126: cut(src, src); Chris@126: } Chris@126: Chris@126: void cut(const double *src, double *dst) const { Chris@126: for (int i = 0; i < m_length; ++i) { Chris@126: dst[i] = src[i] * m_window[i]; Chris@126: } Chris@126: } Chris@126: Chris@126: private: Chris@126: int m_length; Chris@126: double m_p; Chris@126: std::vector m_window; Chris@126: Chris@126: void init(); Chris@126: }; Chris@126: Chris@126: #endif