annotate base/KaiserWindow.cpp @ 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 0523dbfda035
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 #include "KaiserWindow.h"
Chris@124 15
Chris@124 16 #include "maths/MathUtilities.h"
Chris@124 17
Chris@124 18 KaiserWindow::Parameters
Chris@124 19 KaiserWindow::parametersForTransitionWidth(double attenuation,
Chris@124 20 double transition)
Chris@124 21 {
Chris@124 22 Parameters p;
Chris@124 23 p.length = 1 + (attenuation > 21.0 ?
Chris@124 24 ceil((attenuation - 7.95) / (2.285 * transition)) :
Chris@124 25 ceil(5.79 / transition));
Chris@124 26 p.beta = (attenuation > 50.0 ?
Chris@124 27 0.1102 * (attenuation - 8.7) :
Chris@124 28 attenuation > 21.0 ?
Chris@124 29 0.5842 * pow(attenuation - 21.0, 0.4) + 0.07886 * (attenuation - 21.0) :
Chris@124 30 0);
Chris@124 31 return p;
Chris@124 32 }
Chris@124 33
Chris@124 34 static double besselTerm(double x, int i)
Chris@124 35 {
Chris@124 36 if (i == 0) {
Chris@124 37 return 1;
Chris@124 38 } else {
Chris@124 39 double f = MathUtilities::factorial(i);
Chris@124 40 return pow(x/2, i*2) / (f*f);
Chris@124 41 }
Chris@124 42 }
Chris@124 43
Chris@124 44 static double bessel0(double x)
Chris@124 45 {
Chris@124 46 double b = 0.0;
Chris@124 47 for (int i = 0; i < 20; ++i) {
Chris@124 48 b += besselTerm(x, i);
Chris@124 49 }
Chris@124 50 return b;
Chris@124 51 }
Chris@124 52
Chris@124 53 void
Chris@124 54 KaiserWindow::init()
Chris@124 55 {
Chris@124 56 double denominator = bessel0(m_beta);
Chris@132 57 bool even = (m_length % 2 == 0);
Chris@132 58 for (int i = 0; i < (even ? m_length/2 : (m_length+1)/2); ++i) {
Chris@124 59 double k = double(2*i) / double(m_length-1) - 1.0;
Chris@124 60 m_window.push_back(bessel0(m_beta * sqrt(1.0 - k*k)) / denominator);
Chris@124 61 }
Chris@132 62 for (int i = 0; i < (even ? m_length/2 : (m_length-1)/2); ++i) {
Chris@132 63 m_window.push_back(m_window[int(m_length/2) - i - 1]);
Chris@132 64 }
Chris@124 65 }