changeset 180:d1bc89794cd4 tuning-rescale

Build with -Wconversion
author Chris Cannam
date Thu, 19 Feb 2015 16:14:33 +0000
parents 9ab52cb6baa3
children 8e7f96432570
files Makefile.linux src/DistanceMetric.cpp src/FeatureConditioner.cpp src/FeatureExtractor.cpp src/Finder.cpp src/MatchVampPlugin.cpp src/Matcher.cpp test/TestFeatureExtractor.cpp
diffstat 8 files changed, 43 insertions(+), 42 deletions(-) [+]
line wrap: on
line diff
--- a/Makefile.linux	Mon Feb 16 15:38:42 2015 +0000
+++ b/Makefile.linux	Thu Feb 19 16:14:33 2015 +0000
@@ -1,6 +1,6 @@
 
-CXXFLAGS	+= -fPIC -ffast-math -O3 -Wall -Werror 
-#CXXFLAGS	+= -fPIC -g -Wall -Werror -DPERFORM_ERROR_CHECKS=1
+CXXFLAGS	+= -fPIC -ffast-math -O3 -Wall -Werror -Wconversion
+#CXXFLAGS	+= -fPIC -g -Wall -Werror -Wconversion -DPERFORM_ERROR_CHECKS=1
 
 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	Mon Feb 16 15:38:42 2015 +0000
+++ b/src/DistanceMetric.cpp	Thu Feb 19 16:14:33 2015 +0000
@@ -41,8 +41,8 @@
     double sum = 0;
     double eps = 1e-16;
 
-    int featureSize = f1.size();
-    assert(int(f2.size()) == featureSize);
+    assert(f2.size() == f1.size());
+    int featureSize = static_cast<int>(f1.size());
 
     if (m_params.metric == Cosine) {
 
--- a/src/FeatureConditioner.cpp	Mon Feb 16 15:38:42 2015 +0000
+++ b/src/FeatureConditioner.cpp	Thu Feb 19 16:14:33 2015 +0000
@@ -47,7 +47,7 @@
 	return feature;
     }
 
-    int size = feature.size();
+    int size = static_cast<int>(feature.size());
     
     vector<double> out(size, 0.0);
 
--- a/src/FeatureExtractor.cpp	Mon Feb 16 15:38:42 2015 +0000
+++ b/src/FeatureExtractor.cpp	Thu Feb 19 16:14:33 2015 +0000
@@ -88,10 +88,10 @@
     // frequency-domain audio frames before applying the map to them.
     
     double refFreq = 440.; // See above -- *not* the parameter!
-    double binWidth = m_params.sampleRate / m_params.fftSize;
+    double binWidth = double(m_params.sampleRate) / m_params.fftSize;
     int crossoverBin = (int)(2 / (pow(2, 1/12.0) - 1));
-    int crossoverMidi = lrint(log(crossoverBin * binWidth / refFreq)/
-                              log(2.0) * 12 + 69);
+    int crossoverMidi = int(log(crossoverBin * binWidth / refFreq)/
+                            log(2.0) * 12 + 69 + 0.5);
 
     int i = 0;
     while (i <= crossoverBin) {
@@ -111,7 +111,7 @@
         } else {
             double midi = log(freq / refFreq) / log(2.0) * 12 + 69;
             if (midi > 127) midi = 127;
-            int target = crossoverBin + lrint(midi) - crossoverMidi;
+            int target = crossoverBin + int(midi + 0.5) - crossoverMidi;
             if (target >= m_featureSize) target = m_featureSize - 1;
             m_freqMap[i++] = target;
         }
@@ -132,7 +132,7 @@
 FeatureExtractor::makeChromaFrequencyMap()
 {
     double refFreq = m_params.referenceFrequency;
-    double binWidth = m_params.sampleRate / m_params.fftSize;
+    double binWidth = double(m_params.sampleRate) / m_params.fftSize;
     int crossoverBin = (int)(1 / (pow(2, 1/12.0) - 1));
     int i = 0;
     while (i <= crossoverBin) {
@@ -149,7 +149,7 @@
             m_freqMap[i++] = -1;
         } else {
             double midi = log(freq / refFreq) / log(2.0) * 12 + 69;
-            m_freqMap[i++] = (lrint(midi)) % 12 + 1;
+            m_freqMap[i++] = (int(midi + 0.5)) % 12 + 1;
         }
     }
 }
@@ -221,7 +221,7 @@
 
     double ratio = 440. / m_params.referenceFrequency;
 
-    int n = mags.size();
+    int n = static_cast<int>(mags.size());
 
     vector<double> scaled(n, 0.0);
 
--- a/src/Finder.cpp	Mon Feb 16 15:38:42 2015 +0000
+++ b/src/Finder.cpp	Thu Feb 19 16:14:33 2015 +0000
@@ -509,10 +509,11 @@
     reverse(pathy.begin(), pathy.end());
 
     if (smooth) {
-        int smoothedLen = Path().smooth(pathx, pathy, pathx.size());
+        int smoothedLen = Path().smooth
+            (pathx, pathy, static_cast<int>(pathx.size()));
         return smoothedLen;
     } else {
-        return pathx.size();
+        return static_cast<int>(pathx.size());
     }
 }
 
--- a/src/MatchVampPlugin.cpp	Mon Feb 16 15:38:42 2015 +0000
+++ b/src/MatchVampPlugin.cpp	Thu Feb 19 16:14:33 2015 +0000
@@ -209,7 +209,7 @@
     desc.description = "Whether to use half-wave rectified feature-to-feature difference instead of straight spectral or chroma feature";
     desc.minValue = 0;
     desc.maxValue = 1;
-    desc.defaultValue = (int)m_defaultFcParams.order;
+    desc.defaultValue = (float)m_defaultFcParams.order;
     desc.isQuantized = true;
     desc.quantizeStep = 1;
     list.push_back(desc);
@@ -219,7 +219,7 @@
     desc.description = "Type of normalisation to use for features";
     desc.minValue = 0;
     desc.maxValue = 2;
-    desc.defaultValue = (int)m_defaultFcParams.norm;
+    desc.defaultValue = (float)m_defaultFcParams.norm;
     desc.isQuantized = true;
     desc.quantizeStep = 1;
     desc.valueNames.clear();
@@ -235,7 +235,7 @@
     desc.description = "Metric for distance calculations.";
     desc.minValue = 0;
     desc.maxValue = 2;
-    desc.defaultValue = (int)m_defaultDParams.metric;
+    desc.defaultValue = (float)m_defaultDParams.metric;
     desc.isQuantized = true;
     desc.quantizeStep = 1;
     desc.valueNames.clear();
@@ -250,7 +250,7 @@
     desc.description = "Type of normalisation to use for distance metric";
     desc.minValue = 0;
     desc.maxValue = 2;
-    desc.defaultValue = (int)m_defaultDParams.norm;
+    desc.defaultValue = (float)m_defaultDParams.norm;
     desc.isQuantized = true;
     desc.quantizeStep = 1;
     desc.valueNames.clear();
@@ -274,7 +274,7 @@
     desc.description = "Whether to mix in a small constant white noise term when calculating feature distance. This can improve alignment against sources containing cleanly synthesised audio.";
     desc.minValue = 0;
     desc.maxValue = 1;
-    desc.defaultValue = (int)m_defaultDParams.noise;
+    desc.defaultValue = (float)m_defaultDParams.noise;
     desc.isQuantized = true;
     desc.quantizeStep = 1;
     list.push_back(desc);
@@ -284,7 +284,7 @@
     desc.description = "Limit of number of frames that will be accepted from one source without a frame from the other source being accepted";
     desc.minValue = 1;
     desc.maxValue = 10;
-    desc.defaultValue = m_defaultParams.maxRunCount;
+    desc.defaultValue = (float)m_defaultParams.maxRunCount;
     desc.isQuantized = true;
     desc.quantizeStep = 1;
     list.push_back(desc);
@@ -340,15 +340,15 @@
     if (name == "serialise") {
         return m_serialise ? 1.0 : 0.0; 
     } else if (name == "framenorm") {
-        return (int)m_fcParams.norm;
+        return (float)m_fcParams.norm;
     } else if (name == "distnorm") {
-        return (int)m_dParams.norm;
+        return (float)m_dParams.norm;
     } else if (name == "usespecdiff") {
-        return (int)m_fcParams.order;
+        return (float)m_fcParams.order;
     } else if (name == "usechroma") {
         return m_feParams.useChromaFrequencyMap ? 1.0 : 0.0;
     } else if (name == "gradientlimit") {
-        return m_params.maxRunCount;
+        return (float)m_params.maxRunCount;
     } else if (name == "diagonalweight") {
         return m_params.diagonalWeight;
     } else if (name == "zonewidth") {
@@ -358,7 +358,7 @@
     } else if (name == "silencethreshold") {
         return (float)m_fcParams.silenceThreshold;
     } else if (name == "metric") {
-        return (int)m_dParams.metric;
+        return (float)m_dParams.metric;
     } else if (name == "noise") {
         return m_dParams.noise;
     } else if (name == "freq1") {
@@ -448,9 +448,9 @@
     if (stepSize > blockSize/2 ||
         blockSize != getPreferredBlockSize()) return false;
 
-    m_stepSize = stepSize;
+    m_stepSize = (int)stepSize;
     m_stepTime = float(stepSize) / m_inputSampleRate;
-    m_blockSize = blockSize;
+    m_blockSize = (int)blockSize;
 
     createMatchers();
     m_begin = true;
@@ -489,7 +489,7 @@
     desc.quantizeStep = 1;
     desc.sampleType = OutputDescriptor::VariableSampleRate;
     desc.sampleRate = outRate;
-    m_pathOutNo = list.size();
+    m_pathOutNo = int(list.size());
     list.push_back(desc);
 
     desc.identifier = "a_b";
@@ -502,7 +502,7 @@
     desc.isQuantized = false;
     desc.sampleType = OutputDescriptor::VariableSampleRate;
     desc.sampleRate = outRate;
-    m_abOutNo = list.size();
+    m_abOutNo = int(list.size());
     list.push_back(desc);
 
     desc.identifier = "b_a";
@@ -515,7 +515,7 @@
     desc.isQuantized = false;
     desc.sampleType = OutputDescriptor::VariableSampleRate;
     desc.sampleRate = outRate;
-    m_baOutNo = list.size();
+    m_baOutNo = int(list.size());
     list.push_back(desc);
 
     desc.identifier = "a_b_divergence";
@@ -528,7 +528,7 @@
     desc.isQuantized = false;
     desc.sampleType = OutputDescriptor::VariableSampleRate;
     desc.sampleRate = outRate;
-    m_abDivOutNo = list.size();
+    m_abDivOutNo = int(list.size());
     list.push_back(desc);
 
     desc.identifier = "a_b_temporatio";
@@ -541,7 +541,7 @@
     desc.isQuantized = false;
     desc.sampleType = OutputDescriptor::VariableSampleRate;
     desc.sampleRate = outRate;
-    m_abRatioOutNo = list.size();
+    m_abRatioOutNo = int(list.size());
     list.push_back(desc);
 
     int featureSize = FeatureExtractor(m_feParams).getFeatureSize();
@@ -556,7 +556,7 @@
     desc.isQuantized = false;
     desc.sampleType = OutputDescriptor::FixedSampleRate;
     desc.sampleRate = outRate;
-    m_aFeaturesOutNo = list.size();
+    m_aFeaturesOutNo = int(list.size());
     list.push_back(desc);
 
     desc.identifier = "b_features";
@@ -569,7 +569,7 @@
     desc.isQuantized = false;
     desc.sampleType = OutputDescriptor::FixedSampleRate;
     desc.sampleRate = outRate;
-    m_bFeaturesOutNo = list.size();
+    m_bFeaturesOutNo = int(list.size());
     list.push_back(desc);
 
     desc.identifier = "a_cfeatures";
@@ -582,7 +582,7 @@
     desc.isQuantized = false;
     desc.sampleType = OutputDescriptor::FixedSampleRate;
     desc.sampleRate = outRate;
-    m_caFeaturesOutNo = list.size();
+    m_caFeaturesOutNo = int(list.size());
     list.push_back(desc);
 
     desc.identifier = "b_cfeatures";
@@ -595,7 +595,7 @@
     desc.isQuantized = false;
     desc.sampleType = OutputDescriptor::FixedSampleRate;
     desc.sampleRate = outRate;
-    m_cbFeaturesOutNo = list.size();
+    m_cbFeaturesOutNo = int(list.size());
     list.push_back(desc);
 
     desc.identifier = "overall_cost";
@@ -608,7 +608,7 @@
     desc.isQuantized = false;
     desc.sampleType = OutputDescriptor::FixedSampleRate;
     desc.sampleRate = 1;
-    m_overallCostOutNo = list.size();
+    m_overallCostOutNo = int(list.size());
     list.push_back(desc);
     
     return list;
@@ -704,9 +704,9 @@
         int y = pathy[i];
 
         Vamp::RealTime xt = Vamp::RealTime::frame2RealTime
-            (x * m_stepSize, lrintf(m_inputSampleRate));
+            (x * m_stepSize, int(m_inputSampleRate + 0.5));
         Vamp::RealTime yt = Vamp::RealTime::frame2RealTime
-            (y * m_stepSize, lrintf(m_inputSampleRate));
+            (y * m_stepSize, int(m_inputSampleRate + 0.5));
 
         Feature feature;
         feature.hasTimestamp = true;
--- a/src/Matcher.cpp	Mon Feb 16 15:38:42 2015 +0000
+++ b/src/Matcher.cpp	Thu Feb 19 16:14:33 2015 +0000
@@ -43,7 +43,7 @@
     m_runCount = 0;
     m_blockSize = 0;
 
-    m_blockSize = lrint(m_params.blockTime / m_params.hopTime);
+    m_blockSize = int(m_params.blockTime / m_params.hopTime + 0.5);
 #ifdef DEBUG_MATCHER
     cerr << "Matcher: m_blockSize = " << m_blockSize << endl;
 #endif
--- a/test/TestFeatureExtractor.cpp	Mon Feb 16 15:38:42 2015 +0000
+++ b/test/TestFeatureExtractor.cpp	Thu Feb 19 16:14:33 2015 +0000
@@ -64,7 +64,7 @@
 	    int hs = sz / 2 + 1;
 	    int fsz = 13;
     
-	    FeatureExtractor::Parameters params(rate, sz);
+	    FeatureExtractor::Parameters params((float)rate, sz);
 	    params.useChromaFrequencyMap = true;
 	    FeatureExtractor fe(params);
 	    BOOST_CHECK_EQUAL(fe.getFeatureSize(), fsz);
@@ -141,7 +141,7 @@
     int hs = sz / 2 + 1;
     int fsz = 84;
     
-    FeatureExtractor::Parameters params(rate, sz);
+    FeatureExtractor::Parameters params((float)rate, sz);
     FeatureExtractor fe(params);
     BOOST_CHECK_EQUAL(fe.getFeatureSize(), fsz);