diff vamp/CQChromaVamp.cpp @ 113:26217edee359

Adjust frequency extents so as to place semitones in the middle of their spaces (if >1 bin per semitone)
author Chris Cannam <c.cannam@qmul.ac.uk>
date Wed, 14 May 2014 15:58:22 +0100
parents a45b51ea00a2
children 2375457f2876
line wrap: on
line diff
--- a/vamp/CQChromaVamp.cpp	Wed May 14 14:59:45 2014 +0100
+++ b/vamp/CQChromaVamp.cpp	Wed May 14 15:58:22 2014 +0100
@@ -43,8 +43,8 @@
 using std::cerr;
 using std::endl;
 
-static const int defaultLowestOctave = 1;
-static const int defaultOctaveCount = 8;
+static const int defaultLowestOctave = 0;
+static const int defaultOctaveCount = 7;
 static const int defaultBPO = 36;
 static const float defaultTuningFrequency = 440.f;
 
@@ -208,15 +208,23 @@
     m_blockSize = blockSize;
 
     int highestOctave = m_lowestOctave + m_octaveCount - 1;
-    int highestMIDIPitch = (1 + highestOctave) * 12 + 11;
 
-    m_maxFrequency = Pitch::getFrequencyForPitch
-        (highestMIDIPitch, 0, m_tuningFrequency);
-    m_minFrequency = m_maxFrequency / pow(2, m_octaveCount + 1) *
-        pow(2, 1.0 / m_bpo);
+    int midiPitchLimit = (1 + highestOctave) * 12 + 12; // C just beyond top
+    double midiPitchLimitFreq = 
+        Pitch::getFrequencyForPitch(midiPitchLimit, 0, m_tuningFrequency);
+
+    // Max frequency is frequency of the MIDI pitch just beyond the
+    // top octave range (midiPitchLimit) minus one bin, then minus
+    // floor(bins per semitone / 2)
+    int bps = m_bpo / 12;
+    m_maxFrequency = midiPitchLimitFreq / pow(2, (1.0 + floor(bps/2)) / m_bpo);
+
+    // Min frequency is frequency of midiPitchLimit lowered by the
+    // appropriate number of octaves.
+    m_minFrequency = midiPitchLimitFreq / pow(2, m_octaveCount + 1);
 
     cerr << "lowest octave: " << m_lowestOctave << ", highest octave: "
-         << highestOctave << ", highest midi pitch: " << highestMIDIPitch
+         << highestOctave << ", limit midi pitch: " << midiPitchLimit
          << ", min freq " << m_minFrequency << ", max freq " << m_maxFrequency
          << endl;