annotate base/SincWindow.h @ 152:0d3b3c66652b

Some docs
author Chris Cannam
date Mon, 21 Oct 2013 11:50:09 +0100
parents 7669b3aa3bc9
children fdaa63607c15
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@152 19 /**
Chris@152 20 * A window containing values of the sinc function, i.e. sin(x)/x with
Chris@152 21 * sinc(0) == 1, with x == 0 at the centre.
Chris@152 22 */
Chris@126 23 class SincWindow
Chris@126 24 {
Chris@126 25 public:
Chris@126 26 /**
Chris@126 27 * Construct a windower of the given length, containing the values
Chris@126 28 * of sinc(x) with x=0 in the middle, i.e. at sample (length-1)/2
Chris@126 29 * for odd or (length/2)+1 for even length, such that the distance
Chris@126 30 * from -pi to pi (the nearest zero crossings either side of the
Chris@126 31 * peak) is p samples.
Chris@126 32 */
Chris@126 33 SincWindow(int length, double p) : m_length(length), m_p(p) { init(); }
Chris@126 34
Chris@126 35 int getLength() const {
Chris@126 36 return m_length;
Chris@126 37 }
Chris@126 38
Chris@126 39 const double *getWindow() const {
Chris@126 40 return m_window.data();
Chris@126 41 }
Chris@126 42
Chris@126 43 void cut(double *src) const {
Chris@126 44 cut(src, src);
Chris@126 45 }
Chris@126 46
Chris@126 47 void cut(const double *src, double *dst) const {
Chris@126 48 for (int i = 0; i < m_length; ++i) {
Chris@126 49 dst[i] = src[i] * m_window[i];
Chris@126 50 }
Chris@126 51 }
Chris@126 52
Chris@126 53 private:
Chris@126 54 int m_length;
Chris@126 55 double m_p;
Chris@126 56 std::vector<double> m_window;
Chris@126 57
Chris@126 58 void init();
Chris@126 59 };
Chris@126 60
Chris@126 61 #endif