changeset 44:dcfae9ef87de

Make fine tuning optional; wire up forgotten max range option!
author Chris Cannam
date Thu, 13 Jun 2019 11:32:01 +0100
parents 2ef9c5d744ab
children 0fec1c76c92b
files src/TuningDifference.cpp src/TuningDifference.h
diffstat 2 files changed, 30 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/TuningDifference.cpp	Thu May 16 15:56:07 2019 +0100
+++ b/src/TuningDifference.cpp	Thu Jun 13 11:32:01 2019 +0100
@@ -38,6 +38,7 @@
 
 static float defaultMaxDuration = 0.f;
 static int defaultMaxSemis = 4;
+static bool defaultFineTuning = true;
 
 TuningDifference::TuningDifference(float inputSampleRate) :
     Plugin(inputSampleRate),
@@ -46,7 +47,8 @@
     m_blockSize(0),
     m_frameCount(0),
     m_maxDuration(defaultMaxDuration),
-    m_maxSemis(defaultMaxSemis)
+    m_maxSemis(defaultMaxSemis),
+    m_fineTuning(defaultFineTuning)
 {
 }
 
@@ -84,7 +86,7 @@
 {
     // Increment this each time you release a version that behaves
     // differently from the previous one
-    return 1;
+    return 2;
 }
 
 string
@@ -136,7 +138,7 @@
 
     desc.identifier = "maxduration";
     desc.name = "Maximum duration to analyse";
-    desc.description = "The maximum duration (in seconds) to consider from either input file. Zero means there is no limit.";
+    desc.description = "The maximum duration (in seconds) to consider from either input file, always taken from the start of the input. Zero means there is no limit.";
     desc.minValue = 0;
     desc.maxValue = 3600;
     desc.defaultValue = defaultMaxDuration;
@@ -154,6 +156,17 @@
     desc.quantizeStep = 1;
     desc.unit = "semitones";
     list.push_back(desc);
+    
+    desc.identifier = "finetuning";
+    desc.name = "Fine tuning";
+    desc.description = "Use a fine tuning stage to increase nominal resolution from 20 cents to 1 cent.";
+    desc.minValue = 0;
+    desc.maxValue = 1;
+    desc.defaultValue = (defaultFineTuning ? 1.f : 0.f);
+    desc.isQuantized = true;
+    desc.quantizeStep = 1;
+    desc.unit = "";
+    list.push_back(desc);
 
     return list;
 }
@@ -163,6 +176,10 @@
 {
     if (id == "maxduration") {
         return m_maxDuration;
+    } else if (id == "maxrange") {
+        return float(m_maxSemis);
+    } else if (id == "finetuning") {
+        return m_fineTuning ? 1.f : 0.f;
     }
     return 0;
 }
@@ -172,6 +189,10 @@
 {
     if (id == "maxduration") {
         m_maxDuration = value;
+    } else if (id == "maxrange") {
+        m_maxSemis = int(roundf(value));
+    } else if (id == "finetuning") {
+        m_fineTuning = (value > 0.5f);
     }
 }
 
@@ -443,6 +464,11 @@
     int bestCents = coarseCents;
     double bestHz = frequencyForCentsAbove440(coarseCents);
 
+    if (!m_fineTuning) {
+        cerr << "fine tuning disabled, returning coarse Hz " << bestHz << " and cents " << bestCents << " in lieu of fine ones" << endl;
+        return pair<int, double>(bestCents, bestHz);
+    }
+    
     cerr << "corresponding coarse Hz " << bestHz << " scores " << coarseScore << endl;
     cerr << "searchDistance = " << searchDistance << endl;
     
--- a/src/TuningDifference.h	Thu May 16 15:56:07 2019 +0100
+++ b/src/TuningDifference.h	Thu Jun 13 11:32:01 2019 +0100
@@ -72,6 +72,7 @@
     int m_frameCount;
     float m_maxDuration;
     int m_maxSemis;
+    bool m_fineTuning;
 
     Chromagram::Parameters paramsForTuningFrequency(double hz) const;
     TFeature computeFeatureFromTotals(const TFeature &totals) const;