summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorDaniel Schürmann <daschuer@mixxx.org>2019-05-10 01:28:59 +0200
committerDaniel Schürmann <daschuer@mixxx.org>2019-05-11 01:44:56 +0200
commit5c8bac70447bb0c2f341a07510851f85bdab4620 (patch)
tree6aaa8f4ff0feb9ee1bf6ba203caeb7d793b41a05 /lib
parent4a922b7984dc5b34ce10fd5c547b50eb1168d636 (diff)
Fix key rounding code, returning max + 1.
Originally the chords and the chroma data have 3 bins per key and center at 1. This means the first correlation matches at 0. To compensate this the chroma data is shifted on step more. This way we have C wihout wrap around at 0, 1 and 2 and can use integer math to get the final key value. This was tested with a B minor chord and a 440 Hz (A) and 523,25 Hz (C) sinus.
Diffstat (limited to 'lib')
-rw-r--r--lib/qm-dsp/dsp/keydetection/GetKeyMode.cpp17
-rw-r--r--lib/qm-dsp/key_rounding.patch26
2 files changed, 35 insertions, 8 deletions
diff --git a/lib/qm-dsp/dsp/keydetection/GetKeyMode.cpp b/lib/qm-dsp/dsp/keydetection/GetKeyMode.cpp
index cf3580e80e..55a13331b9 100644
--- a/lib/qm-dsp/dsp/keydetection/GetKeyMode.cpp
+++ b/lib/qm-dsp/dsp/keydetection/GetKeyMode.cpp
@@ -177,12 +177,11 @@ int GetKeyMode::process(double *PCMData)
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 @@ int GetKeyMode::process(double *PCMData)
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;
diff --git a/lib/qm-dsp/key_rounding.patch b/lib/qm-dsp/key_rounding.patch
new file mode 100644
index 0000000000..7f8cfd7540
--- /dev/null
+++ b/lib/qm-dsp/key_rounding.patch
@@ -0,0 +1,26 @@
+diff --git a/lib/qm-dsp/dsp/keydetection/GetKeyMode.cpp b/lib/qm-dsp/dsp/keydetection/GetKeyMode.cpp
+index cf3580e..bf72b21 100644
+--- a/lib/qm-dsp/dsp/keydetection/GetKeyMode.cpp
++++ b/lib/qm-dsp/dsp/keydetection/GetKeyMode.cpp
+@@ -182,7 +182,7 @@ int GetKeyMode::process(double *PCMData)
+ // 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);
++ MathUtilities::circShift( m_ChrPointer, m_BPO, 2);
+ /*
+ std::cout << "raw chroma: ";
+ for (int ii = 0; ii < m_BPO; ++ii) {
+@@ -266,8 +266,10 @@ int GetKeyMode::process(double *PCMData)
+ 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;
+