changeset 159:cdbee79699b0 refactors

Introduce reference frequency param to feature extractor
author Chris Cannam
date Thu, 29 Jan 2015 17:02:48 +0000
parents d6c1556fadd0
children 581b1118ec28
files src/FeatureExtractor.cpp src/FeatureExtractor.h
diffstat 2 files changed, 10 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/FeatureExtractor.cpp	Thu Jan 29 10:55:24 2015 +0000
+++ b/src/FeatureExtractor.cpp	Thu Jan 29 17:02:48 2015 +0000
@@ -70,12 +70,11 @@
 void
 FeatureExtractor::makeStandardFrequencyMap()
 {
+    double refFreq = m_params.referenceFrequency;
     double binWidth = m_params.sampleRate / m_params.fftSize;
     int crossoverBin = (int)(2 / (pow(2, 1/12.0) - 1));
-    int crossoverMidi = lrint(log(crossoverBin*binWidth/440.0)/
+    int crossoverMidi = lrint(log(crossoverBin * binWidth / refFreq)/
                               log(2.0) * 12 + 69);
-
-    // freq = 440 * Math.pow(2, (midi-69)/12.0) / binWidth;
     
     int i = 0;
     while (i <= crossoverBin) {
@@ -84,7 +83,7 @@
     }
 
     while (i <= m_params.fftSize/2) {
-        double midi = log(i*binWidth/440.0) / log(2.0) * 12 + 69;
+        double midi = log(i * binWidth / refFreq) / log(2.0) * 12 + 69;
         if (midi > 127) midi = 127;
         int target = crossoverBin + lrint(midi) - crossoverMidi;
         if (target >= m_featureSize) target = m_featureSize - 1;
@@ -95,6 +94,7 @@
 void
 FeatureExtractor::makeChromaFrequencyMap()
 {
+    double refFreq = m_params.referenceFrequency;
     double binWidth = m_params.sampleRate / m_params.fftSize;
     int crossoverBin = (int)(1 / (pow(2, 1/12.0) - 1));
     int i = 0;
@@ -102,7 +102,7 @@
         m_freqMap[i++] = 0;
     }
     while (i <= m_params.fftSize/2) {
-        double midi = log(i*binWidth/440.0) / log(2.0) * 12 + 69;
+        double midi = log(i * binWidth / refFreq) / log(2.0) * 12 + 69;
         m_freqMap[i++] = (lrint(midi)) % 12 + 1;
     }
 }
--- a/src/FeatureExtractor.h	Thu Jan 29 10:55:24 2015 +0000
+++ b/src/FeatureExtractor.h	Thu Jan 29 17:02:48 2015 +0000
@@ -48,7 +48,8 @@
         Parameters(float rate_, int fftSize_) :
             sampleRate(rate_),
             useChromaFrequencyMap(false),
-            fftSize(fftSize_)
+            fftSize(fftSize_),
+            referenceFrequency(440.0)
         {}
 
         /** Sample rate of audio */
@@ -62,6 +63,9 @@
          *  in is already in the frequency domain, so this expresses
          *  the size of the frame that the caller will be providing. */
         int fftSize;
+
+        /** Frequency of concert A */
+        double referenceFrequency;
     };
 
     /**