comparison dsp/keydetection/GetKeyMode.cpp @ 298:255e431ae3d4

* Key detector: when returning key strengths, use the peak value of the three underlying chromagram correlations (from 36-bin chromagram) corresponding to each key, instead of the mean. Rationale: This is the same method as used when returning the key value, and it's nice to have the same results in both returned value and plot. The peak performed better than the sum with a simple test set of triads, so it seems reasonable to change the plot to match the key output rather than the other way around. * FFT: kiss_fftr returns only the non-conjugate bins, synthesise the rest rather than leaving them (perhaps dangerously) undefined. Fixes an uninitialised data error in chromagram that could cause garbage results from key detector. * Constant Q: remove precalculated values again, I reckon they're not proving such a good tradeoff.
author Chris Cannam <c.cannam@qmul.ac.uk>
date Fri, 05 Jun 2009 15:12:39 +0000
parents 5e125f030287
children 715f779d0b4f
comparison
equal deleted inserted replaced
297:b74f91bd5c7d 298:255e431ae3d4
172 // Move bins such that the centre of the base note is in the 172 // Move bins such that the centre of the base note is in the
173 // middle of its three bins : 173 // middle of its three bins :
174 // Added 21.11.07 by Chris Sutton based on debugging with Katy 174 // Added 21.11.07 by Chris Sutton based on debugging with Katy
175 // Noland + comparison with Matlab equivalent. 175 // Noland + comparison with Matlab equivalent.
176 MathUtilities::circShift( m_ChrPointer, m_BPO, 1); 176 MathUtilities::circShift( m_ChrPointer, m_BPO, 1);
177
178 /* 177 /*
179 std::cout << "raw chroma: "; 178 std::cout << "raw chroma: ";
180 for (int ii = 0; ii < m_BPO; ++ii) { 179 for (int ii = 0; ii < m_BPO; ++ii) {
181 std::cout << m_ChrPointer[ii] << " "; 180 if (ii % (m_BPO/12) == 0) std::cout << "\n";
182 } 181 std::cout << m_ChrPointer[ii] << " ";
183 std::cout << std::endl; 182 }
183 std::cout << std::endl;
184 */ 184 */
185 // populate hpcp values; 185 // populate hpcp values;
186 int cbidx; 186 int cbidx;
187 for( j = 0; j < m_BPO; j++ ) 187 for( j = 0; j < m_BPO; j++ )
188 { 188 {
230 m_keyStrengths[k] = 0; 230 m_keyStrengths[k] = 0;
231 } 231 }
232 232
233 for( k = 0; k < m_BPO*2; k++ ) 233 for( k = 0; k < m_BPO*2; k++ )
234 { 234 {
235 m_keyStrengths[k/(m_BPO/12)] += m_Keys[k]; 235 int idx = k / (m_BPO/12);
236 int rem = k % (m_BPO/12);
237 if (rem == 0 || m_Keys[k] > m_keyStrengths[idx]) {
238 m_keyStrengths[idx] = m_Keys[k];
239 }
240
241 // m_keyStrengths[k/(m_BPO/12)] += m_Keys[k];
236 } 242 }
237 243
238 /* 244 /*
239 std::cout << "raw keys: "; 245 std::cout << "raw keys: ";
240 for (int ii = 0; ii < 2*m_BPO; ++ii) { 246 for (int ii = 0; ii < 2*m_BPO; ++ii) {
241 std::cout << m_Keys[ii] << " "; 247 if (ii % (m_BPO/12) == 0) std::cout << "\n";
248 std::cout << m_Keys[ii] << " ";
249 }
250 std::cout << std::endl;
251
252 std::cout << "key strengths: ";
253 for (int ii = 0; ii < 24; ++ii) {
254 if (ii % 6 == 0) std::cout << "\n";
255 std::cout << m_keyStrengths[ii] << " ";
242 } 256 }
243 std::cout << std::endl; 257 std::cout << std::endl;
244 */ 258 */
245 double dummy; 259 double dummy;
246 // '1 +' because we number keys 1-24, not 0-23. 260 // '1 +' because we number keys 1-24, not 0-23.
247 key = 1 + (int)ceil( (double)MathUtilities::getMax( m_Keys, 2* m_BPO, &dummy )/3 ); 261 key = 1 + (int)ceil( (double)MathUtilities::getMax( m_Keys, 2* m_BPO, &dummy )/3 );
248 262
249 // std::cout << "key pre-sorting: " << key << std::endl; 263 // std::cout << "key pre-sorting: " << key << std::endl;
250 264
251 265
252 //Median filtering 266 //Median filtering
253 267
254 // track Median buffer initial filling 268 // track Median buffer initial filling
283 std::cout << std::endl; 297 std::cout << std::endl;
284 */ 298 */
285 int sortlength = m_MedianBufferFilling; 299 int sortlength = m_MedianBufferFilling;
286 int midpoint = (int)ceil((double)sortlength/2); 300 int midpoint = (int)ceil((double)sortlength/2);
287 301
302 // std::cout << "midpoint = " << midpoint << endl;
303
288 if( midpoint <= 0 ) 304 if( midpoint <= 0 )
289 midpoint = 1; 305 midpoint = 1;
290 306
291 key = m_SortedBuffer[midpoint-1]; 307 key = m_SortedBuffer[midpoint-1];
308
309 // std::cout << "returning key = " << key << endl;
292 310
293 return key; 311 return key;
294 } 312 }
295 313
296 314