comparison dsp/onsets/PeakPicking.cpp @ 483:fdaa63607c15

Untabify, indent, tidy
author Chris Cannam <cannam@all-day-breakfast.com>
date Fri, 31 May 2019 11:54:32 +0100
parents c5e1b25d5177
children af5b7ef02aa7
comparison
equal deleted inserted replaced
482:cbe668c7d724 483:fdaa63607c15
47 { 47 {
48 m_DFLength = Config.length ; 48 m_DFLength = Config.length ;
49 Qfilta = Config.QuadThresh.a ; 49 Qfilta = Config.QuadThresh.a ;
50 Qfiltb = Config.QuadThresh.b ; 50 Qfiltb = Config.QuadThresh.b ;
51 Qfiltc = Config.QuadThresh.c ; 51 Qfiltc = Config.QuadThresh.c ;
52 52
53 m_DFProcessingParams.length = m_DFLength; 53 m_DFProcessingParams.length = m_DFLength;
54 m_DFProcessingParams.LPOrd = Config.LPOrd; 54 m_DFProcessingParams.LPOrd = Config.LPOrd;
55 m_DFProcessingParams.LPACoeffs = Config.LPACoeffs; 55 m_DFProcessingParams.LPACoeffs = Config.LPACoeffs;
56 m_DFProcessingParams.LPBCoeffs = Config.LPBCoeffs; 56 m_DFProcessingParams.LPBCoeffs = Config.LPBCoeffs;
57 m_DFProcessingParams.winPre = Config.WinT.pre; 57 m_DFProcessingParams.winPre = Config.WinT.pre;
75 75
76 void PeakPicking::process( double* src, unsigned int len, vector<int> &onsets ) 76 void PeakPicking::process( double* src, unsigned int len, vector<int> &onsets )
77 { 77 {
78 if (len < 4) return; 78 if (len < 4) return;
79 79
80 vector <double> m_maxima; 80 vector <double> m_maxima;
81 81
82 // Signal conditioning 82 // Signal conditioning
83 m_DFSmoothing->process( src, m_workBuffer ); 83 m_DFSmoothing->process( src, m_workBuffer );
84 84
85 for( unsigned int u = 0; u < len; u++) 85 for( unsigned int u = 0; u < len; u++) {
86 { 86 m_maxima.push_back( m_workBuffer[ u ] );
87 m_maxima.push_back( m_workBuffer[ u ] );
88 } 87 }
89 88
90 quadEval( m_maxima, onsets ); 89 quadEval( m_maxima, onsets );
91 90
92 for( int b = 0; b < (int)m_maxima.size(); b++) 91 for( int b = 0; b < (int)m_maxima.size(); b++) {
93 { 92 src[ b ] = m_maxima[ b ];
94 src[ b ] = m_maxima[ b ];
95 } 93 }
96 } 94 }
97 95
98 int PeakPicking::quadEval( vector<double> &src, vector<int> &idx ) 96 int PeakPicking::quadEval( vector<double> &src, vector<int> &idx )
99 { 97 {
100 unsigned int maxLength; 98 unsigned int maxLength;
101 99
102 vector <int> m_maxIndex; 100 vector <int> m_maxIndex;
103 vector <int> m_onsetPosition; 101 vector <int> m_onsetPosition;
104 102
105 vector <double> m_maxFit; 103 vector <double> m_maxFit;
106 vector <double> m_poly; 104 vector <double> m_poly;
107 vector <double> m_err; 105 vector <double> m_err;
108 106
109 m_poly.push_back(0); 107 m_poly.push_back(0);
110 m_poly.push_back(0); 108 m_poly.push_back(0);
111 m_poly.push_back(0); 109 m_poly.push_back(0);
112 110
113 for( int t = -2; t < 3; t++) 111 for( int t = -2; t < 3; t++) {
114 { 112 m_err.push_back( (double)t );
115 m_err.push_back( (double)t );
116 } 113 }
117 for( unsigned int i = 2; i < src.size() - 2; i++) 114
118 { 115 for( unsigned int i = 2; i < src.size() - 2; i++) {
119 if( (src[i] > src[i-1]) && (src[i] > src[i+1]) && (src[i] > 0) ) 116 if( (src[i] > src[i-1]) && (src[i] > src[i+1]) && (src[i] > 0) ) {
120 {
121 // m_maxIndex.push_back( i + 1 );
122 m_maxIndex.push_back(i); 117 m_maxIndex.push_back(i);
123 } 118 }
124 } 119 }
125 120
126 maxLength = m_maxIndex.size(); 121 maxLength = m_maxIndex.size();
127 122
128 double selMax = 0; 123 double selMax = 0;
129 124
130 for( unsigned int j = 0; j < maxLength ; j++) 125 for( unsigned int j = 0; j < maxLength ; j++) {
131 { 126 for (int k = -2; k <= 2; ++k) {
132 for (int k = -2; k <= 2; ++k) 127 selMax = src[ m_maxIndex[j] + k ] ;
133 { 128 m_maxFit.push_back(selMax);
134 selMax = src[ m_maxIndex[j] + k ] ; 129 }
135 m_maxFit.push_back(selMax);
136 }
137 130
138 TPolyFit::PolyFit2(m_err, m_maxFit, m_poly); 131 TPolyFit::PolyFit2(m_err, m_maxFit, m_poly);
139 132
140 double f = m_poly[0]; 133 double f = m_poly[0];
141 double h = m_poly[2]; 134 double h = m_poly[2];
142 135
143 if (h < -Qfilta || f > Qfiltc) 136 if (h < -Qfilta || f > Qfiltc) {
144 { 137 idx.push_back(m_maxIndex[j]);
145 idx.push_back(m_maxIndex[j]); 138 }
146 } 139
147 140 m_maxFit.clear();
148 m_maxFit.clear();
149 } 141 }
150 142
151 return 1; 143 return 1;
152 } 144 }