annotate base/KaiserWindow.h @ 209:ccd2019190bf msvc

Some MSVC fixes, including (temporarily, probably) renaming the FFT source file to avoid getting it mixed up with the Vamp SDK one in our object dir
author Chris Cannam
date Thu, 01 Feb 2018 16:34:08 +0000
parents 0d3b3c66652b
children fdaa63607c15
rev   line source
Chris@124 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@124 2
Chris@124 3 /*
Chris@124 4 QM DSP library
Chris@124 5 Centre for Digital Music, Queen Mary, University of London.
Chris@124 6
Chris@124 7 This program is free software; you can redistribute it and/or
Chris@124 8 modify it under the terms of the GNU General Public License as
Chris@124 9 published by the Free Software Foundation; either version 2 of the
Chris@124 10 License, or (at your option) any later version. See the file
Chris@124 11 COPYING included with this distribution for more information.
Chris@124 12 */
Chris@124 13
Chris@124 14 #ifndef KAISER_WINDOW_H
Chris@124 15 #define KAISER_WINDOW_H
Chris@124 16
Chris@124 17 #include <vector>
Chris@124 18 #include <cmath>
Chris@124 19
Chris@152 20 /**
Chris@152 21 * Kaiser window: A windower whose bandwidth and sidelobe height
Chris@152 22 * (signal-noise ratio) can be specified. These parameters are traded
Chris@152 23 * off against the window length.
Chris@152 24 */
Chris@124 25 class KaiserWindow
Chris@124 26 {
Chris@124 27 public:
Chris@124 28 struct Parameters {
Chris@124 29 int length;
Chris@124 30 double beta;
Chris@124 31 };
Chris@124 32
Chris@124 33 /**
Chris@124 34 * Construct a Kaiser windower with the given length and beta
Chris@124 35 * parameter.
Chris@124 36 */
Chris@124 37 KaiserWindow(Parameters p) : m_length(p.length), m_beta(p.beta) { init(); }
Chris@124 38
Chris@124 39 /**
Chris@124 40 * Construct a Kaiser windower with the given attenuation in dB
Chris@124 41 * and transition width in samples.
Chris@124 42 */
Chris@124 43 static KaiserWindow byTransitionWidth(double attenuation,
Chris@124 44 double transition) {
Chris@124 45 return KaiserWindow
Chris@124 46 (parametersForTransitionWidth(attenuation, transition));
Chris@124 47 }
Chris@124 48
Chris@124 49 /**
Chris@124 50 * Construct a Kaiser windower with the given attenuation in dB
Chris@124 51 * and transition bandwidth in Hz for the given samplerate.
Chris@124 52 */
Chris@124 53 static KaiserWindow byBandwidth(double attenuation,
Chris@124 54 double bandwidth,
Chris@124 55 double samplerate) {
Chris@124 56 return KaiserWindow
Chris@124 57 (parametersForBandwidth(attenuation, bandwidth, samplerate));
Chris@124 58 }
Chris@124 59
Chris@124 60 /**
Chris@124 61 * Obtain the parameters necessary for a Kaiser window of the
Chris@124 62 * given attenuation in dB and transition width in samples.
Chris@124 63 */
Chris@124 64 static Parameters parametersForTransitionWidth(double attenuation,
Chris@124 65 double transition);
Chris@124 66
Chris@124 67 /**
Chris@124 68 * Obtain the parameters necessary for a Kaiser window of the
Chris@124 69 * given attenuation in dB and transition bandwidth in Hz for the
Chris@124 70 * given samplerate.
Chris@124 71 */
Chris@124 72 static Parameters parametersForBandwidth(double attenuation,
Chris@124 73 double bandwidth,
Chris@124 74 double samplerate) {
Chris@124 75 return parametersForTransitionWidth
Chris@124 76 (attenuation, (bandwidth * 2 * M_PI) / samplerate);
Chris@124 77 }
Chris@124 78
Chris@124 79 int getLength() const {
Chris@124 80 return m_length;
Chris@124 81 }
Chris@124 82
Chris@124 83 const double *getWindow() const {
Chris@124 84 return m_window.data();
Chris@124 85 }
Chris@124 86
Chris@124 87 void cut(double *src) const {
Chris@124 88 cut(src, src);
Chris@124 89 }
Chris@124 90
Chris@124 91 void cut(const double *src, double *dst) const {
Chris@124 92 for (int i = 0; i < m_length; ++i) {
Chris@124 93 dst[i] = src[i] * m_window[i];
Chris@124 94 }
Chris@124 95 }
Chris@124 96
Chris@124 97 private:
Chris@124 98 int m_length;
Chris@124 99 double m_beta;
Chris@124 100 std::vector<double> m_window;
Chris@124 101
Chris@124 102 void init();
Chris@124 103 };
Chris@124 104
Chris@124 105 #endif