Mercurial > hg > qm-dsp
diff dsp/keydetection/GetKeyMode.cpp @ 456:05378924b433
Fix a rounding issue, returning key value 25
The two bins above center B minor are treated as 25. This patch shifts also
the input chromagram by 2 to have center C on 1 like the profiles
author | Daniel Schürmann <daschuer@mixxx.org> |
---|---|
date | Sat, 11 May 2019 02:08:22 +0200 |
parents | f5b5f64835b9 |
children | 8a8cf7296e58 |
line wrap: on
line diff
--- a/dsp/keydetection/GetKeyMode.cpp Fri May 24 11:39:24 2019 +0100 +++ b/dsp/keydetection/GetKeyMode.cpp Sat May 11 02:08:22 2019 +0200 @@ -177,12 +177,11 @@ m_ChrPointer = m_Chroma->process( m_DecimatedBuffer ); - - // Move bins such that the centre of the base note is in the - // middle of its three bins : - // Added 21.11.07 by Chris Sutton based on debugging with Katy - // Noland + comparison with Matlab equivalent. - MathUtilities::circShift( m_ChrPointer, m_BPO, 1); + // The Cromagram has the center of C at bin 0, while the major + // and minor profiles have the center of C at 1. We want to have + // the correlation for C result also at 1. + // To achieve this we have to shift two times: + MathUtilities::circShift( m_ChrPointer, m_BPO, 2); /* std::cout << "raw chroma: "; for (int ii = 0; ii < m_BPO; ++ii) { @@ -266,8 +265,10 @@ std::cout << std::endl; */ double dummy; - // '1 +' because we number keys 1-24, not 0-23. - key = 1 + (int)ceil( (double)MathUtilities::getMax( m_Keys, 2* m_BPO, &dummy )/3 ); + // m_Keys[1] is C center 1 / 3 + 1 = 1 + // m_Keys[4] is D center 4 / 3 + 1 = 2 + // '+ 1' because we number keys 1-24, not 0-23. + key = MathUtilities::getMax( m_Keys, 2* m_BPO, &dummy ) / 3 + 1; // std::cout << "key pre-sorting: " << key << std::endl;