summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorDaniel Schürmann <daschuer@mixxx.org>2019-05-15 00:27:35 +0200
committerDaniel Schürmann <daschuer@mixxx.org>2019-05-15 00:27:35 +0200
commitf3a28e306ed0b1fb7bb8fe05c317b3f8f35352ff (patch)
tree29b5444afa3ccaab92559da9de42fe70b5a7fef7 /lib
parent3174fb0ff567b938b9bc94deb8c92bf1cd2470bf (diff)
Updated patch against Upstream
Diffstat (limited to 'lib')
-rw-r--r--lib/qm-dsp/key_rounding.patch281
1 files changed, 250 insertions, 31 deletions
diff --git a/lib/qm-dsp/key_rounding.patch b/lib/qm-dsp/key_rounding.patch
index dd1442e8d3..c07e2d5f41 100644
--- a/lib/qm-dsp/key_rounding.patch
+++ b/lib/qm-dsp/key_rounding.patch
@@ -1,34 +1,253 @@
+diff --git a/lib/qm-dsp/dsp/chromagram/Chromagram.cpp b/lib/qm-dsp/dsp/chromagram/Chromagram.cpp
+index a8597a5..3e83367 100644
+--- a/lib/qm-dsp/dsp/chromagram/Chromagram.cpp
++++ b/lib/qm-dsp/dsp/chromagram/Chromagram.cpp
+@@ -33,8 +33,8 @@ int Chromagram::initialise( ChromaConfig Config )
+ m_BPO = Config.BPO; // bins per octave
+ m_normalise = Config.normalise; // if frame normalisation is required
+
+- // No. of constant Q bins
+- m_uK = ( unsigned int ) ceil( m_BPO * log(m_FMax/m_FMin)/log(2.0));
++ // No. of constant Q bins, extended to a full cotave
++ m_uK = m_BPO * (unsigned int)ceil(log(m_FMax/m_FMin)/log(2.0));
+
+ // Create array for chroma result
+ m_chromadata = new double[ m_BPO ];
+@@ -44,7 +44,7 @@ int Chromagram::initialise( ChromaConfig Config )
+
+ // Populate CQ config structure with parameters
+ // inherited from the Chroma config
+- ConstantQConfig.FS = Config.FS;
++ ConstantQConfig.FS = Config.FS;
+ ConstantQConfig.min = m_FMin;
+ ConstantQConfig.max = m_FMax;
+ ConstantQConfig.BPO = m_BPO;
+@@ -134,7 +134,7 @@ double* Chromagram::process( const double *data )
+ m_windowbuf = new double[m_frameSize];
+ }
+
+- for (int i = 0; i < m_frameSize; ++i) {
++ for (unsigned int i = 0; i < m_frameSize; ++i) {
+ m_windowbuf[i] = data[i];
+ }
+ m_window->cut(m_windowbuf);
+@@ -155,20 +155,18 @@ double* Chromagram::process( const double *real, const double *imag )
+ // initialise chromadata to 0
+ for (unsigned i = 0; i < m_BPO; i++) m_chromadata[i] = 0;
+
+- double cmax = 0.0;
+- double cval = 0;
+ // Calculate ConstantQ frame
+ m_ConstantQ->process( real, imag, m_CQRe, m_CQIm );
+
+ // add each octave of cq data into Chromagram
+- const unsigned octaves = (int)floor(double( m_uK/m_BPO))-1;
+- for (unsigned octave = 0; octave <= octaves; octave++)
++ const unsigned octaves = m_uK / m_BPO;
++ for (unsigned octave = 0; octave < octaves; octave++)
+ {
+- unsigned firstBin = octave*m_BPO;
+- for (unsigned i = 0; i < m_BPO; i++)
+- {
+- m_chromadata[i] += kabs( m_CQRe[ firstBin + i ], m_CQIm[ firstBin + i ]);
+- }
++ unsigned firstBin = octave * m_BPO;
++ for (unsigned i = 0; i < m_BPO; i++)
++ {
++ m_chromadata[i] += kabs( m_CQRe[ firstBin + i ], m_CQIm[ firstBin + i ]);
++ }
+ }
+
+ MathUtilities::normalise(m_chromadata, m_BPO, m_normalise);
+diff --git a/lib/qm-dsp/dsp/chromagram/Chromagram.h b/lib/qm-dsp/dsp/chromagram/Chromagram.h
+index bd928f5..b2ad72e 100644
+--- a/lib/qm-dsp/dsp/chromagram/Chromagram.h
++++ b/lib/qm-dsp/dsp/chromagram/Chromagram.h
+@@ -21,7 +21,7 @@
+ #include "ConstantQ.h"
+
+ struct ChromaConfig{
+- unsigned int FS;
++ double FS;
+ double min;
+ double max;
+ unsigned int BPO;
+diff --git a/lib/qm-dsp/dsp/chromagram/ConstantQ.cpp b/lib/qm-dsp/dsp/chromagram/ConstantQ.cpp
+index b764235..aab4848 100644
+--- a/lib/qm-dsp/dsp/chromagram/ConstantQ.cpp
++++ b/lib/qm-dsp/dsp/chromagram/ConstantQ.cpp
+@@ -125,14 +125,18 @@ void ConstantQ::sparsekernel()
+ hammingWindowIm[u] = 0;
+ }
+
+- // Computing a hamming window
+- const unsigned hammingLength = (int) ceil( m_dQ * m_FS / ( m_FMin * pow(2,((double)(k))/(double)m_BPO)));
++ const double samplesPerCycle =
++ m_FS / (m_FMin * pow(2, (double)k / (double)m_BPO));
++
++ // Computing a hamming window
++ const unsigned hammingLength = (int) ceil(
++ m_dQ * samplesPerCycle);
+
+ unsigned origin = m_FFTLength/2 - hammingLength/2;
+
+ for (unsigned i=0; i<hammingLength; i++)
+ {
+- const double angle = 2*PI*m_dQ*i/hammingLength;
++ const double angle = 2*PI*i/samplesPerCycle;
+ const double real = cos(angle);
+ const double imag = sin(angle);
+ const double absol = hamming(hammingLength, i)/hammingLength;
+@@ -140,6 +144,10 @@ void ConstantQ::sparsekernel()
+ hammingWindowIm[ origin + i ] = absol*imag;
+ }
+
++ /* This code splits the hanning widow and moves it to the beginning
++ and the end, creating an epty gap in the middle.
++ Is disables, because it results in wrong results,
++ when tested with sin waves centered on a bin frequency.
+ for (unsigned i = 0; i < m_FFTLength/2; ++i) {
+ double temp = hammingWindowRe[i];
+ hammingWindowRe[i] = hammingWindowRe[i + m_FFTLength/2];
+@@ -148,6 +156,7 @@ void ConstantQ::sparsekernel()
+ hammingWindowIm[i] = hammingWindowIm[i + m_FFTLength/2];
+ hammingWindowIm[i + m_FFTLength/2] = temp;
+ }
++ */
+
+ //do fft of hammingWindow
+ m_FFT.process( 0, hammingWindowRe, hammingWindowIm, transfHammingWindowRe, transfHammingWindowIm );
+@@ -292,8 +301,10 @@ void ConstantQ::initialise( CQConfig Config )
+ m_BPO = Config.BPO; // bins per octave
+ m_CQThresh = Config.CQThresh;// ConstantQ threshold for kernel generation
+
+- m_dQ = 1/(pow(2,(1/(double)m_BPO))-1); // Work out Q value for Filter bank
+- m_uK = (unsigned int) ceil(m_BPO * log(m_FMax/m_FMin)/log(2.0)); // No. of constant Q bins
++ // Work out Q value for Filter bank
++ m_dQ = 1/(pow(2,(1/(double)m_BPO))-1);
++ // No. of constant Q bins, extended to a full cotave
++ m_uK = m_BPO * (unsigned int)ceil(log(m_FMax/m_FMin)/log(2.0));
+
+ // std::cerr << "ConstantQ::initialise: rate = " << m_FS << ", fmin = " << m_FMin << ", fmax = " << m_FMax << ", bpo = " << m_BPO << ", K = " << m_uK << ", Q = " << m_dQ << std::endl;
+
+diff --git a/lib/qm-dsp/dsp/chromagram/ConstantQ.h b/lib/qm-dsp/dsp/chromagram/ConstantQ.h
+index c06f60a..bd666dd 100644
+--- a/lib/qm-dsp/dsp/chromagram/ConstantQ.h
++++ b/lib/qm-dsp/dsp/chromagram/ConstantQ.h
+@@ -21,7 +21,7 @@
+ #include "maths/MathUtilities.h"
+
+ struct CQConfig{
+- unsigned int FS; // samplerate
++ double FS; // samplerate
+ double min; // minimum frequency
+ double max; // maximum frequency
+ unsigned int BPO; // bins per octave
+@@ -58,7 +58,7 @@ private:
+ void deInitialise();
+
+ double* m_CQdata;
+- unsigned int m_FS;
++ double m_FS;
+ double m_FMin;
+ double m_FMax;
+ double m_dQ;
diff --git a/lib/qm-dsp/dsp/keydetection/GetKeyMode.cpp b/lib/qm-dsp/dsp/keydetection/GetKeyMode.cpp
-index 55a1333..cf3580e 100644
+index cf3580e..7407c43 100644
--- a/lib/qm-dsp/dsp/keydetection/GetKeyMode.cpp
+++ b/lib/qm-dsp/dsp/keydetection/GetKeyMode.cpp
-@@ -177,11 +177,12 @@ int GetKeyMode::process(double *PCMData)
-
- m_ChrPointer = m_Chroma->process( m_DecimatedBuffer );
-
-- // 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);
-+
-+ // 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);
- /*
- std::cout << "raw chroma: ";
- for (int ii = 0; ii < m_BPO; ++ii) {
-@@ -265,10 +266,8 @@ int GetKeyMode::process(double *PCMData)
- std::cout << std::endl;
- */
- double dummy;
-- // 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;
-+ // '1 +' because we number keys 1-24, not 0-23.
-+ key = 1 + (int)ceil( (double)MathUtilities::getMax( m_Keys, 2* m_BPO, &dummy )/3 );
-
- // std::cout << "key pre-sorting: " << key << std::endl;
+@@ -60,13 +60,13 @@ GetKeyMode::GetKeyMode( int sampleRate, float tuningFrequency,
+
+ // Chromagram configuration parameters
+ m_ChromaConfig.normalise = MathUtilities::NormaliseUnitMax;
+- m_ChromaConfig.FS = lrint(sampleRate/(double)m_DecimationFactor);
+- if (m_ChromaConfig.FS < 1) m_ChromaConfig.FS = 1;
++ m_ChromaConfig.FS = sampleRate/(double)m_DecimationFactor;
+
+- // Set C (= MIDI #12) as our base :
++ // Set C3 (= MIDI #48) as our base:
+ // This implies that key = 1 => Cmaj, key = 12 => Bmaj, key = 13 => Cmin, etc.
+ m_ChromaConfig.min = Pitch::getFrequencyForPitch
+ (48, 0, tuningFrequency);
++ // C7 (= MIDI #96) is the exclusive maximum key:
+ m_ChromaConfig.max = Pitch::getFrequencyForPitch
+ (96, 0, tuningFrequency);
+
+@@ -177,15 +177,14 @@ 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) {
++ for (unsigned int ii = 0; ii < m_BPO; ++ii) {
+ if (ii % (m_BPO/12) == 0) std::cout << "\n";
+ std::cout << m_ChrPointer[ii] << " ";
+ }
+@@ -266,9 +265,13 @@ 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.
++ int maxBin = MathUtilities::getMax( m_Keys, 2* m_BPO, &dummy );
++ key = maxBin / 3 + 1;
+
++// std::cout << "fractional key pre-sorting: " << (maxBin + 2) / 3.0 << std::endl;
+ // 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 0000000..dd1442e
+--- /dev/null
++++ b/lib/qm-dsp/key_rounding.patch
+@@ -0,0 +1,34 @@
++diff --git a/lib/qm-dsp/dsp/keydetection/GetKeyMode.cpp b/lib/qm-dsp/dsp/keydetection/GetKeyMode.cpp
++index 55a1333..cf3580e 100644
++--- a/lib/qm-dsp/dsp/keydetection/GetKeyMode.cpp
+++++ b/lib/qm-dsp/dsp/keydetection/GetKeyMode.cpp
++@@ -177,11 +177,12 @@ int GetKeyMode::process(double *PCMData)
++
++ m_ChrPointer = m_Chroma->process( m_DecimatedBuffer );
++
++- // 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);
+++
+++ // 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);
++ /*
++ std::cout << "raw chroma: ";
++ for (int ii = 0; ii < m_BPO; ++ii) {
++@@ -265,10 +266,8 @@ int GetKeyMode::process(double *PCMData)
++ std::cout << std::endl;
++ */
++ double dummy;
++- // 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;
+++ // '1 +' because we number keys 1-24, not 0-23.
+++ key = 1 + (int)ceil( (double)MathUtilities::getMax( m_Keys, 2* m_BPO, &dummy )/3 );
++
++ // std::cout << "key pre-sorting: " << key << std::endl;