Mercurial > hg > match-vamp
changeset 184:6c12db195986 re-minimise
Some fixes (still does not yet build)
author | Chris Cannam |
---|---|
date | Thu, 26 Feb 2015 09:55:28 +0000 |
parents | 24ddab06aace |
children | a17b22abd551 |
files | src/DistanceMetric.cpp src/DistanceMetric.h src/FeatureExtractor.cpp src/FeatureExtractor.h |
diffstat | 4 files changed, 53 insertions(+), 17 deletions(-) [+] |
line wrap: on
line diff
--- a/src/DistanceMetric.cpp Thu Feb 19 17:17:20 2015 +0000 +++ b/src/DistanceMetric.cpp Thu Feb 26 09:55:28 2015 +0000 @@ -61,8 +61,7 @@ } if (d > 1.0) d = 1.0; - return d; // normalisation param ignored - + return scaleIntoRange(d); // normalisation param ignored } if (m_params.metric == Manhattan) { @@ -86,7 +85,7 @@ } if (sum == 0) { - return 0; + return scaleIntoRange(0); } double distance = 0; @@ -114,6 +113,15 @@ distance = d; } - return distance; + return scaleIntoRange(distance); } +distance_t +DistanceMetric::scaleIntoRange(double distance) +{ + if (sizeof(distance_t) == sizeof(distance)) { + return distance_t(distance); + } else { + return distance_t(m_params.scale * distance); + } +}
--- a/src/DistanceMetric.h Thu Feb 19 17:17:20 2015 +0000 +++ b/src/DistanceMetric.h Thu Feb 26 09:55:28 2015 +0000 @@ -68,12 +68,14 @@ Parameters() : metric(Manhattan), norm(NormaliseDistanceToLogSum), - noise(AddNoise) + noise(AddNoise), + scale(90.) {} Metric metric; DistanceNormalisation norm; NoiseAddition noise; + double scale; }; DistanceMetric(Parameters params); @@ -92,6 +94,7 @@ private: Parameters m_params; + distance_t scaleIntoRange(double distance); }; #endif
--- a/src/FeatureExtractor.cpp Thu Feb 19 17:17:20 2015 +0000 +++ b/src/FeatureExtractor.cpp Thu Feb 26 09:55:28 2015 +0000 @@ -157,7 +157,19 @@ feature_t FeatureExtractor::process(const vector<double> &real, const vector<double> &imag) { - vector<double> mags(m_params.fftSize/2 + 1, 0.0); + vector<float> mags(m_params.fftSize/2 + 1, 0.0); + + for (int i = 0; i <= m_params.fftSize/2; i++) { + mags[i] = float(real[i] * real[i] + imag[i] * imag[i]); + } + + return processMags(mags); +} + +feature_t +FeatureExtractor::process(const vector<float> &real, const vector<float> &imag) +{ + vector<float> mags(m_params.fftSize/2 + 1, 0.0); for (int i = 0; i <= m_params.fftSize/2; i++) { mags[i] = real[i] * real[i] + imag[i] * imag[i]; @@ -169,7 +181,7 @@ feature_t FeatureExtractor::process(const float *cframe) { - vector<double> mags(m_params.fftSize/2 + 1, 0.0); + vector<float> mags(m_params.fftSize/2 + 1, 0.0); for (int i = 0; i <= m_params.fftSize/2; i++) { mags[i] = cframe[i*2] * cframe[i*2] + cframe[i*2+1] * cframe[i*2+1]; @@ -179,7 +191,7 @@ } feature_t -FeatureExtractor::processMags(const vector<double> &mags) +FeatureExtractor::processMags(const vector<float> &mags) { feature_t frame(m_featureSize, 0.0); @@ -187,7 +199,7 @@ (m_params.referenceFrequency != 440.)) { // See comment in makeStandardFrequencyMap above - vector<double> scaled = scaleMags(mags); + vector<float> scaled = scaleMags(mags); for (int i = 0; i <= m_params.fftSize/2; i++) { int index = m_freqMap[i]; @@ -208,8 +220,8 @@ return frame; } -vector<double> -FeatureExtractor::scaleMags(const vector<double> &mags) +vector<float> +FeatureExtractor::scaleMags(const vector<float> &mags) { // Scale the pitch content in the given magnitude spectrum to // accommodate a difference in tuning frequency (between the 440Hz @@ -219,11 +231,11 @@ if (m_params.useChromaFrequencyMap) return mags; - double ratio = 440. / m_params.referenceFrequency; + double ratio = 440.f / m_params.referenceFrequency; int n = static_cast<int>(mags.size()); - vector<double> scaled(n, 0.0); + vector<float> scaled(n, 0.0); for (int target = 0; target < n; ++target) { @@ -243,7 +255,7 @@ value += higherProp * mags[higher]; } - scaled[target] = value; + scaled[target] = float(value); } return scaled;
--- a/src/FeatureExtractor.h Thu Feb 19 17:17:20 2015 +0000 +++ b/src/FeatureExtractor.h Thu Feb 26 09:55:28 2015 +0000 @@ -110,6 +110,19 @@ const std::vector<double> &imag); /** + * Process one frequency-domain audio frame (provided as real & + * imaginary components from the FFT output). Return a feature + * vector of size given by getFeatureSize(). Input vectors must + * have at least params.fftSize/2+1 elements each. + * + * Operates by mapping the frequency bins into a part-linear + * part-logarithmic array, unless useChromaFrequencyMap is true in + * which case they are mapped into chroma bins. + */ + feature_t process(const std::vector<float> &real, + const std::vector<float> &imag); + + /** * Process one frequency-domain audio frame, provided as a single * array of alternating real and imaginary components. Input array * must have at least 2 * (params.fftSize/2 + 1) elements. @@ -118,7 +131,7 @@ * part-logarithmic array, unless useChromaFrequencyMap is true in * which case they are mapped into chroma bins. */ - std::feature_t process(const float *carray); + feature_t process(const float *carray); protected: /** Make either standard or chroma map, depending on m_params */ @@ -154,8 +167,8 @@ */ std::vector<int> m_freqMap; - feature_t processMags(const std::vector<double> &mags); - std::vector<double> scaleMags(const std::vector<double> &mags); + feature_t processMags(const std::vector<float> &mags); + std::vector<float> scaleMags(const std::vector<float> &mags); /** The size of a returned feature. */ int m_featureSize;