comparison dsp/signalconditioning/DFProcess.cpp @ 483:fdaa63607c15

Untabify, indent, tidy
author Chris Cannam <cannam@all-day-breakfast.com>
date Fri, 31 May 2019 11:54:32 +0100
parents 7461bf03194e
children b1f72e469ec8
comparison
equal deleted inserted replaced
482:cbe668c7d724 483:fdaa63607c15
33 ////////////////////////////////////////////////////////////////////// 33 //////////////////////////////////////////////////////////////////////
34 34
35 DFProcess::DFProcess( DFProcConfig Config ) 35 DFProcess::DFProcess( DFProcConfig Config )
36 { 36 {
37 filtSrc = NULL; 37 filtSrc = NULL;
38 filtDst = NULL; 38 filtDst = NULL;
39 m_filtScratchIn = NULL; 39 m_filtScratchIn = NULL;
40 m_filtScratchOut = NULL; 40 m_filtScratchOut = NULL;
41 41
42 m_FFOrd = 0; 42 m_FFOrd = 0;
43 43
60 60
61 filtSrc = new double[ m_length ]; 61 filtSrc = new double[ m_length ];
62 filtDst = new double[ m_length ]; 62 filtDst = new double[ m_length ];
63 63
64 Filter::Parameters params; 64 Filter::Parameters params;
65 params.a = std::vector<double>(Config.LPACoeffs, Config.LPACoeffs + Config.LPOrd + 1); 65 params.a = std::vector<double>
66 params.b = std::vector<double>(Config.LPBCoeffs, Config.LPBCoeffs + Config.LPOrd + 1); 66 (Config.LPACoeffs, Config.LPACoeffs + Config.LPOrd + 1);
67 params.b = std::vector<double>
68 (Config.LPBCoeffs, Config.LPBCoeffs + Config.LPOrd + 1);
67 69
68 m_FiltFilt = new FiltFilt(params); 70 m_FiltFilt = new FiltFilt(params);
69 71
70 //add delta threshold 72 //add delta threshold
71 m_delta = Config.delta; 73 m_delta = Config.delta;
72 } 74 }
73 75
74 void DFProcess::deInitialise() 76 void DFProcess::deInitialise()
75 { 77 {
76 delete [] filtSrc; 78 delete [] filtSrc;
77
78 delete [] filtDst; 79 delete [] filtDst;
79
80 delete [] m_filtScratchIn; 80 delete [] m_filtScratchIn;
81
82 delete [] m_filtScratchOut; 81 delete [] m_filtScratchOut;
83
84 delete m_FiltFilt; 82 delete m_FiltFilt;
85 } 83 }
86 84
87 void DFProcess::process(double *src, double* dst) 85 void DFProcess::process(double *src, double* dst)
88 { 86 {
106 double* y = new double[ m_winPost + m_winPre + 1]; 104 double* y = new double[ m_winPost + m_winPre + 1];
107 memset( y, 0, sizeof( double ) * ( m_winPost + m_winPre + 1) ); 105 memset( y, 0, sizeof( double ) * ( m_winPost + m_winPre + 1) );
108 106
109 double* scratch = new double[ m_length ]; 107 double* scratch = new double[ m_length ];
110 108
111 for( i = 0; i < m_winPre; i++) 109 for( i = 0; i < m_winPre; i++) {
112 { 110
113 if (index >= m_length) break; 111 if (index >= m_length) {
112 break;
113 }
114 114
115 k = i + m_winPost + 1; 115 k = i + m_winPost + 1;
116 116
117 for( j = 0; j < k; j++) 117 for( j = 0; j < k; j++) {
118 { 118 y[ j ] = src[ j ];
119 y[ j ] = src[ j ]; 119 }
120 } 120 scratch[ index ] = MathUtilities::median( y, k );
121 scratch[ index ] = MathUtilities::median( y, k ); 121 index++;
122 index++;
123 } 122 }
124 123
125 for( i = 0; i + m_winPost + m_winPre < m_length; i ++) 124 for( i = 0; i + m_winPost + m_winPre < m_length; i ++) {
126 { 125
127 if (index >= m_length) break; 126 if (index >= m_length) {
127 break;
128 }
129
130 l = 0;
131 for( j = i; j < ( i + m_winPost + m_winPre + 1); j++) {
132 y[ l ] = src[ j ];
133 l++;
134 }
128 135
129 136 scratch[index] = MathUtilities::median( y, (m_winPost + m_winPre + 1 ));
130 l = 0; 137 index++;
131 for( j = i; j < ( i + m_winPost + m_winPre + 1); j++)
132 {
133 y[ l ] = src[ j ];
134 l++;
135 }
136
137 scratch[ index++ ] = MathUtilities::median( y, (m_winPost + m_winPre + 1 ));
138 } 138 }
139 139
140 for( i = std::max( m_length - m_winPost, 1); i < m_length; i++) 140 for( i = std::max( m_length - m_winPost, 1); i < m_length; i++) {
141 { 141
142 if (index >= m_length) break; 142 if (index >= m_length) {
143 break;
144 }
143 145
144 k = std::max( i - m_winPre, 1); 146 k = std::max( i - m_winPre, 1);
145 147
146 l = 0; 148 l = 0;
147 for( j = k; j < m_length; j++) 149 for( j = k; j < m_length; j++) {
148 { 150 y[ l ] = src[ j ];
149 y[ l ] = src[ j ]; 151 l++;
150 152 }
151 l++; 153
152 } 154 scratch[index] = MathUtilities::median( y, l);
153 155 index++;
154 scratch[ index++ ] = MathUtilities::median( y, l);
155 } 156 }
156 157
157 158 for( i = 0; i < m_length; i++ ) {
158 for( i = 0; i < m_length; i++ ) 159 //add a delta threshold used as an offset when computing the smoothed detection function
159 { 160 //(helps to discard noise when detecting peaks)
160 //add a delta threshold used as an offset when computing the smoothed detection function 161 val = src[ i ] - scratch[ i ] - m_delta;
161 //(helps to discard noise when detecting peaks) 162
162 val = src[ i ] - scratch[ i ] - m_delta; 163 if( m_isMedianPositive ) {
163 164 if( val > 0 ) {
164 if( m_isMedianPositive ) 165 dst[ i ] = val;
165 { 166 } else {
166 if( val > 0 ) 167 dst[ i ] = 0;
167 { 168 }
168 dst[ i ] = val; 169 } else {
169 } 170 dst[ i ] = val;
170 else 171 }
171 {
172 dst[ i ] = 0;
173 }
174 }
175 else
176 {
177 dst[ i ] = val;
178 }
179 } 172 }
180 173
181 delete [] y; 174 delete [] y;
182 delete [] scratch; 175 delete [] scratch;
183 } 176 }
184 177
185 178
191 184
192 MathUtilities::getFrameMinMax( src, m_length, &DFMin, &DFmax ); 185 MathUtilities::getFrameMinMax( src, m_length, &DFMin, &DFmax );
193 186
194 MathUtilities::getAlphaNorm( src, m_length, m_alphaNormParam, &DFAlphaNorm ); 187 MathUtilities::getAlphaNorm( src, m_length, m_alphaNormParam, &DFAlphaNorm );
195 188
196 for (int i = 0; i < m_length; i++) 189 for (int i = 0; i < m_length; i++) {
197 { 190 dst[ i ] = ( src[ i ] - DFMin ) / DFAlphaNorm;
198 dst[ i ] = ( src[ i ] - DFMin ) / DFAlphaNorm;
199 } 191 }
200 } 192 }