annotate base/SincWindow.h @ 136:9c16683f58eb

...
author Chris Cannam
date Mon, 21 Oct 2013 09:24:59 +0100
parents 7669b3aa3bc9
children 0d3b3c66652b
rev   line source
Chris@126 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@126 2
Chris@126 3 /*
Chris@126 4 QM DSP library
Chris@126 5 Centre for Digital Music, Queen Mary, University of London.
Chris@126 6
Chris@126 7 This program is free software; you can redistribute it and/or
Chris@126 8 modify it under the terms of the GNU General Public License as
Chris@126 9 published by the Free Software Foundation; either version 2 of the
Chris@126 10 License, or (at your option) any later version. See the file
Chris@126 11 COPYING included with this distribution for more information.
Chris@126 12 */
Chris@126 13
Chris@126 14 #ifndef SINC_WINDOW_H
Chris@126 15 #define SINC_WINDOW_H
Chris@126 16
Chris@126 17 #include <vector>
Chris@126 18
Chris@126 19 class SincWindow
Chris@126 20 {
Chris@126 21 public:
Chris@126 22 /**
Chris@126 23 * Construct a windower of the given length, containing the values
Chris@126 24 * of sinc(x) with x=0 in the middle, i.e. at sample (length-1)/2
Chris@126 25 * for odd or (length/2)+1 for even length, such that the distance
Chris@126 26 * from -pi to pi (the nearest zero crossings either side of the
Chris@126 27 * peak) is p samples.
Chris@126 28 */
Chris@126 29 SincWindow(int length, double p) : m_length(length), m_p(p) { init(); }
Chris@126 30
Chris@126 31 int getLength() const {
Chris@126 32 return m_length;
Chris@126 33 }
Chris@126 34
Chris@126 35 const double *getWindow() const {
Chris@126 36 return m_window.data();
Chris@126 37 }
Chris@126 38
Chris@126 39 void cut(double *src) const {
Chris@126 40 cut(src, src);
Chris@126 41 }
Chris@126 42
Chris@126 43 void cut(const double *src, double *dst) const {
Chris@126 44 for (int i = 0; i < m_length; ++i) {
Chris@126 45 dst[i] = src[i] * m_window[i];
Chris@126 46 }
Chris@126 47 }
Chris@126 48
Chris@126 49 private:
Chris@126 50 int m_length;
Chris@126 51 double m_p;
Chris@126 52 std::vector<double> m_window;
Chris@126 53
Chris@126 54 void init();
Chris@126 55 };
Chris@126 56
Chris@126 57 #endif