comparison dsp/tonal/ChangeDetectionFunction.cpp @ 488:7992d0923626

Use M_PI
author Chris Cannam <cannam@all-day-breakfast.com>
date Fri, 31 May 2019 16:48:29 +0100
parents cbe668c7d724
children
comparison
equal deleted inserted replaced
487:5998ee1042d3 488:7992d0923626
12 License, or (at your option) any later version. See the file 12 License, or (at your option) any later version. See the file
13 COPYING included with this distribution for more information. 13 COPYING included with this distribution for more information.
14 */ 14 */
15 15
16 #include "ChangeDetectionFunction.h" 16 #include "ChangeDetectionFunction.h"
17
18 #ifndef PI
19 #define PI (3.14159265358979232846)
20 #endif
21 17
22 ChangeDetectionFunction::ChangeDetectionFunction(ChangeDFConfig config) : 18 ChangeDetectionFunction::ChangeDetectionFunction(ChangeDFConfig config) :
23 m_dFilterSigma(0.0), m_iFilterWidth(0) 19 m_dFilterSigma(0.0), m_iFilterWidth(0)
24 { 20 {
25 setFilterWidth(config.smoothingWidth); 21 setFilterWidth(config.smoothingWidth);
36 // it is assumed that the gaussian is 0 outside of +/- FWHM 32 // it is assumed that the gaussian is 0 outside of +/- FWHM
37 // => filter width = 2*FWHM = 2*2.3548*sigma 33 // => filter width = 2*FWHM = 2*2.3548*sigma
38 m_dFilterSigma = double(m_iFilterWidth) / double(2*2.3548); 34 m_dFilterSigma = double(m_iFilterWidth) / double(2*2.3548);
39 m_vaGaussian.resize(m_iFilterWidth); 35 m_vaGaussian.resize(m_iFilterWidth);
40 36
41 double dScale = 1.0 / (m_dFilterSigma*sqrt(2*PI)); 37 double dScale = 1.0 / (m_dFilterSigma*sqrt(2*M_PI));
42 38
43 for (int x = -(m_iFilterWidth-1)/2; x <= (m_iFilterWidth-1)/2; x++) { 39 for (int x = -(m_iFilterWidth-1)/2; x <= (m_iFilterWidth-1)/2; x++) {
44 double w = dScale * std::exp ( -(x*x)/(2*m_dFilterSigma*m_dFilterSigma) ); 40 double w = dScale * std::exp ( -(x*x)/(2*m_dFilterSigma*m_dFilterSigma) );
45 m_vaGaussian[x + (m_iFilterWidth-1)/2] = w; 41 m_vaGaussian[x + (m_iFilterWidth-1)/2] = w;
46 } 42 }