Mercurial > hg > match-vamp
changeset 183:24ddab06aace re-minimise
Toward allowing types to be small again. Doesn't currently build
author | Chris Cannam |
---|---|
date | Thu, 19 Feb 2015 17:17:20 +0000 |
parents | a67663dc698d |
children | 6c12db195986 |
files | Makefile.linux src/DistanceMetric.cpp src/DistanceMetric.h src/FeatureExtractor.cpp src/FeatureExtractor.h src/Finder.cpp src/MatchFeatureFeeder.cpp src/MatchFeatureFeeder.h src/MatchPipeline.cpp src/MatchPipeline.h src/Matcher.cpp src/Types.h |
diffstat | 12 files changed, 59 insertions(+), 53 deletions(-) [+] |
line wrap: on
line diff
--- a/Makefile.linux Thu Feb 19 16:57:19 2015 +0000 +++ b/Makefile.linux Thu Feb 19 17:17:20 2015 +0000 @@ -1,6 +1,6 @@ -CXXFLAGS += -fPIC -ffast-math -O3 -Wall -Werror -Wconversion -#CXXFLAGS += -fPIC -g -Wall -Werror -Wconversion -DPERFORM_ERROR_CHECKS=1 +CXXFLAGS += -fPIC -ffast-math -O3 -Wall -Werror -Wconversion -std=c++11 +#CXXFLAGS += -fPIC -g -Wall -Werror -Wconversion -DPERFORM_ERROR_CHECKS=1 -std=c++11 LDFLAGS += -Wl,-Bstatic -lvamp-sdk -Wl,-Bdynamic PLUGIN_LDFLAGS += -shared -Wl,-Bsymbolic -Wl,-z,defs -lpthread -Wl,--version-script=vamp-plugin.map
--- a/src/DistanceMetric.cpp Thu Feb 19 16:57:19 2015 +0000 +++ b/src/DistanceMetric.cpp Thu Feb 19 17:17:20 2015 +0000 @@ -33,9 +33,9 @@ #endif } -double -DistanceMetric::calcDistance(const vector<double> &f1, - const vector<double> &f2) +distance_t +DistanceMetric::calcDistance(const feature_t &f1, + const feature_t &f2) { double d = 0; double sum = 0;
--- a/src/DistanceMetric.h Thu Feb 19 16:57:19 2015 +0000 +++ b/src/DistanceMetric.h Thu Feb 19 17:17:20 2015 +0000 @@ -17,7 +17,7 @@ #ifndef DISTANCE_METRIC_H #define DISTANCE_METRIC_H -#include <vector> +#include "Types.h" class DistanceMetric { @@ -87,8 +87,8 @@ * @param f2 one of the vectors involved in the distance calculation * @return the distance */ - double calcDistance(const std::vector<double> &f1, - const std::vector<double> &f2); + distance_t calcDistance(const feature_t &f1, + const feature_t &f2); private: Parameters m_params;
--- a/src/FeatureExtractor.cpp Thu Feb 19 16:57:19 2015 +0000 +++ b/src/FeatureExtractor.cpp Thu Feb 19 17:17:20 2015 +0000 @@ -154,7 +154,7 @@ } } -vector<double> +feature_t FeatureExtractor::process(const vector<double> &real, const vector<double> &imag) { vector<double> mags(m_params.fftSize/2 + 1, 0.0); @@ -166,7 +166,7 @@ return processMags(mags); } -vector<double> +feature_t FeatureExtractor::process(const float *cframe) { vector<double> mags(m_params.fftSize/2 + 1, 0.0); @@ -178,10 +178,10 @@ return processMags(mags); } -vector<double> +feature_t FeatureExtractor::processMags(const vector<double> &mags) { - vector<double> frame(m_featureSize, 0.0); + feature_t frame(m_featureSize, 0.0); if (!m_params.useChromaFrequencyMap && (m_params.referenceFrequency != 440.)) {
--- a/src/FeatureExtractor.h Thu Feb 19 16:57:19 2015 +0000 +++ b/src/FeatureExtractor.h Thu Feb 19 17:17:20 2015 +0000 @@ -17,7 +17,7 @@ #ifndef FEATURE_EXTRACTOR_H #define FEATURE_EXTRACTOR_H -#include <vector> +#include "Types.h" /** * Convert frequency-domain audio frames into features suitable for @@ -106,8 +106,8 @@ * part-logarithmic array, unless useChromaFrequencyMap is true in * which case they are mapped into chroma bins. */ - std::vector<double> process(const std::vector<double> &real, - const std::vector<double> &imag); + feature_t process(const std::vector<double> &real, + const std::vector<double> &imag); /** * Process one frequency-domain audio frame, provided as a single @@ -118,7 +118,7 @@ * part-logarithmic array, unless useChromaFrequencyMap is true in * which case they are mapped into chroma bins. */ - std::vector<double> process(const float *carray); + std::feature_t process(const float *carray); protected: /** Make either standard or chroma map, depending on m_params */ @@ -154,7 +154,7 @@ */ std::vector<int> m_freqMap; - std::vector<double> processMags(const std::vector<double> &mags); + feature_t processMags(const std::vector<double> &mags); std::vector<double> scaleMags(const std::vector<double> &mags); /** The size of a returned feature. */
--- a/src/Finder.cpp Thu Feb 19 16:57:19 2015 +0000 +++ b/src/Finder.cpp Thu Feb 19 17:17:20 2015 +0000 @@ -190,7 +190,8 @@ pathcost_t min = -1; if ((c > prevRowStart) && (c <= prevRowStop)) { // diagonal from (r-1,c-1) - min = m_m->getPathCost(r-1, c-1) + newStep * diagonalWeight; + min = m_m->getPathCost(r-1, c-1) + + distance_t(newStep * diagonalWeight); dir = AdvanceBoth; } if ((c >= prevRowStart) && (c < prevRowStop)) { @@ -253,16 +254,16 @@ for (int c = rowStart; c < rowStop; c++) { distance_t newStep = m_m->getDistance(r, c); - pathcost_t updateTo = -1.0; + pathcost_t updateTo = InvalidPathCost; advance_t dir = AdvanceNone; if (r > r1) { // not first row pathcost_t min = -1; if ((c > prevRowStart) && (c <= prevRowStop)) { // diagonal from (r-1,c-1) - min = m_m->getPathCost(r-1, c-1) + newStep * diagonalWeight; + min = m_m->getPathCost(r-1, c-1) + distance_t(newStep * diagonalWeight); err.prevCost = m_m->getPathCost(r-1, c-1); - err.distance = newStep * diagonalWeight; + err.distance = distance_t(newStep * diagonalWeight); dir = AdvanceBoth; } if ((c >= prevRowStart) && (c < prevRowStop)) {
--- a/src/MatchFeatureFeeder.cpp Thu Feb 19 16:57:19 2015 +0000 +++ b/src/MatchFeatureFeeder.cpp Thu Feb 19 17:17:20 2015 +0000 @@ -30,7 +30,7 @@ } void -MatchFeatureFeeder::feed(vector<double> f1, vector<double> f2) +MatchFeatureFeeder::feed(feature_t f1, feature_t f2) { // We maintain two FIFO queues of feature vectors, one per input // stream. When the match-feeder function is entered, it knows @@ -58,7 +58,7 @@ return 0; } int bestRow = 0; - double bestCost = 0; + pathcost_t bestCost = 0; if (!m_finder.getBestColCost(m_pm2->getFrameCount()-1, bestRow, bestCost)) { return -1; } else {
--- a/src/MatchFeatureFeeder.h Thu Feb 19 16:57:19 2015 +0000 +++ b/src/MatchFeatureFeeder.h Thu Feb 19 17:17:20 2015 +0000 @@ -41,7 +41,7 @@ * feature vector as normal for the input that is still going on, * and an empty vector for the one that has ended. */ - void feed(std::vector<double> f1, std::vector<double> f2); + void feed(feature_t f1, feature_t f2); /** * Get the best estimate for the frame in the reference (f1) @@ -78,8 +78,8 @@ Finder m_finder; // I own this, and it refers to m_pm1 - std::queue<std::vector<double> > m_q1; - std::queue<std::vector<double> > m_q2; + std::queue<feature_t> m_q1; + std::queue<feature_t> m_q2; vector<int> m_fpx; vector<int> m_fpy;
--- a/src/MatchPipeline.cpp Thu Feb 19 16:57:19 2015 +0000 +++ b/src/MatchPipeline.cpp Thu Feb 19 17:17:20 2015 +0000 @@ -55,7 +55,7 @@ } void -MatchPipeline::feedFeatures(const vector<double> &f1, const vector<double> &f2) +MatchPipeline::feedFeatures(const feature_t &f1, const feature_t &f2) { m_f1 = f1; m_f2 = f2; @@ -74,7 +74,7 @@ } void -MatchPipeline::feedConditionedFeatures(const vector<double> &c1, const vector<double> &c2) +MatchPipeline::feedConditionedFeatures(const feature_t &c1, const feature_t &c2) { m_c1 = c1; m_c2 = c2; @@ -103,21 +103,21 @@ } void -MatchPipeline::extractFeatures(vector<double> &f1, vector<double> &f2) +MatchPipeline::extractFeatures(feature_t &f1, feature_t &f2) { f1 = m_f1; f2 = m_f2; } void -MatchPipeline::extractConditionedFeatures(vector<double> &c1, vector<double> &c2) +MatchPipeline::extractConditionedFeatures(feature_t &c1, feature_t &c2) { c1 = m_c1; c2 = m_c2; } bool -MatchPipeline::aboveThreshold(const vector<double> &f) +MatchPipeline::aboveThreshold(const feature_t &f) { // This threshold is used only to determine when either of the // input streams has ended -- the last frame for a stream is
--- a/src/MatchPipeline.h Thu Feb 19 16:57:19 2015 +0000 +++ b/src/MatchPipeline.h Thu Feb 19 17:17:20 2015 +0000 @@ -68,7 +68,7 @@ * be passed in to FeatureConditioner and then on to the rest of * the pipeline. */ - void feedFeatures(const vector<double> &f1, const vector<double> &f2); + void feedFeatures(const feature_t &f1, const feature_t &f2); /** * Feed in data at the third pipeline stage. The vectors represent @@ -76,7 +76,7 @@ * will be passed to MatchFeatureFeeder for feeding to the two * matchers. */ - void feedConditionedFeatures(const vector<double> &f1, const vector<double> &f2); + void feedConditionedFeatures(const feature_t &f1, const feature_t &f2); /** * If a frame was just fed in at the first or second pipeline @@ -84,12 +84,12 @@ * if you provided frequency-domain audio, extractFeatures will * give you back the FeatureExtractor's features. */ - void extractFeatures(vector<double> &f1, vector<double> &f2); + void extractFeatures(feature_t &f1, feature_t &f2); /** * Retrieve the conditioned features from the third pipeline stage. */ - void extractConditionedFeatures(vector<double> &f1, vector<double> &f2); + void extractConditionedFeatures(feature_t &f1, feature_t &f2); /** * Indicate that both inputs have come to an end. @@ -130,11 +130,11 @@ int m_lastFrameIn1; int m_lastFrameIn2; int m_frameNo; - vector<double> m_f1; - vector<double> m_f2; - vector<double> m_c1; - vector<double> m_c2; - bool aboveThreshold(const vector<double> &f); + feature_t m_f1; + feature_t m_f2; + feature_t m_c1; + feature_t m_c2; + bool aboveThreshold(const feature_t &f); FeatureExtractor::Parameters paramsWithFreq(FeatureExtractor::Parameters, double); };
--- a/src/Matcher.cpp Thu Feb 19 16:57:19 2015 +0000 +++ b/src/Matcher.cpp Thu Feb 19 17:17:20 2015 +0000 @@ -150,7 +150,7 @@ throw "Distance not available"; } distance_t dist = m_distance[i][j - m_first[i]]; - if (dist < 0) { + if (dist == InvalidDistance) { cerr << "ERROR: Matcher::getDistance(" << i << ", " << j << "): " << "Location is in range, but distance (" << dist << ") is invalid or has not been set" << endl; @@ -233,8 +233,8 @@ Matcher::size() { int distSize = (m_params.maxRunCount + 1) * m_blockSize; - m_bestPathCost.resize(m_distXSize, pathcostvec_t(distSize, -1)); - m_distance.resize(m_distXSize, distancevec_t(distSize, -1)); + m_bestPathCost.resize(m_distXSize, pathcostvec_t(distSize, InvalidPathCost)); + m_distance.resize(m_distXSize, distancevec_t(distSize, InvalidDistance)); m_advance.resize(m_distXSize, advancevec_t(distSize, AdvanceNone)); m_first.resize(m_distXSize, 0); m_last.resize(m_distXSize, 0); @@ -270,10 +270,10 @@ // Same for bestPathCost. distancevec_t dOld(m_distance[m_frameCount - m_blockSize]); - distancevec_t dNew(len, -1.f); + distancevec_t dNew(len, InvalidDistance); pathcostvec_t bpcOld(m_bestPathCost[m_frameCount - m_blockSize]); - pathcostvec_t bpcNew(len, -1.0); + pathcostvec_t bpcNew(len, InvalidPathCost); advancevec_t adOld(m_advance[m_frameCount - m_blockSize]); advancevec_t adNew(len, AdvanceNone); @@ -307,7 +307,7 @@ (m_features[frameIndex], m_otherMatcher->m_features[index % m_blockSize]); - distance_t diagDistance = distance * m_params.diagonalWeight; + distance_t diagDistance = distance_t(distance * m_params.diagonalWeight); if ((m_frameCount == 0) && (index == 0)) { // first element @@ -410,7 +410,7 @@ { distance_t weighted = distance; if (dir == AdvanceBoth) { - weighted *= m_params.diagonalWeight; + weighted = distance_t(weighted * m_params.diagonalWeight); } if (m_firstPM) { @@ -430,8 +430,8 @@ // pauses in either direction, and arbitrary lengths at // end, it is better than a segmentation fault. cerr << "Emergency resize: " << idx << " -> " << idx * 2 << endl; - m_otherMatcher->m_bestPathCost[j].resize(idx * 2, -1); - m_otherMatcher->m_distance[j].resize(idx * 2, -1); + m_otherMatcher->m_bestPathCost[j].resize(idx * 2, InvalidPathCost); + m_otherMatcher->m_distance[j].resize(idx * 2, InvalidDistance); m_otherMatcher->m_advance[j].resize(idx * 2, AdvanceNone); }
--- a/src/Types.h Thu Feb 19 16:57:19 2015 +0000 +++ b/src/Types.h Thu Feb 19 17:17:20 2015 +0000 @@ -17,9 +17,10 @@ #define MATCH_TYPES_H #include <vector> +#include <cstdint> /// A single value in a feature vector -typedef double featurebin_t; +typedef float featurebin_t; /// A feature vector typedef std::vector<featurebin_t> feature_t; @@ -28,7 +29,9 @@ typedef std::vector<feature_t> featureseq_t; /// The distance between two feature vectors -typedef float distance_t; +typedef uint8_t distance_t; + +const int InvalidDistance = 0xff; /// A distance vector typedef std::vector<distance_t> distancevec_t; @@ -37,7 +40,9 @@ typedef std::vector<distancevec_t> distancemat_t; /// The integrated distance (path cost) from the origin to a given point -typedef double pathcost_t; +typedef uint32_t pathcost_t; + +const int InvalidPathCost = 0xdeadbeef; /// A vector of path costs typedef std::vector<pathcost_t> pathcostvec_t; @@ -46,7 +51,7 @@ typedef std::vector<pathcostvec_t> pathcostmat_t; /// A direction advance instruction or state -enum advance_t { +enum advance_t : uint8_t { AdvanceNone, AdvanceBoth, AdvanceThis,