annotate base/KaiserWindow.h @ 515:08bcc06c38ec tip master

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