Mercurial > hg > constant-q-cpp
diff vamp/CQVamp.cpp @ 110:fdd32f995b0d
First cut at a chromagram plugin as well
author | Chris Cannam <c.cannam@qmul.ac.uk> |
---|---|
date | Wed, 14 May 2014 14:04:34 +0100 |
parents | f5325762ff6d |
children | 2375457f2876 |
line wrap: on
line diff
--- a/vamp/CQVamp.cpp Wed May 14 12:49:10 2014 +0100 +++ b/vamp/CQVamp.cpp Wed May 14 14:04:34 2014 +0100 @@ -191,7 +191,7 @@ desc.description = "Number of constant-Q transform bins per octave"; desc.minValue = 2; desc.maxValue = 480; - desc.defaultValue = 60; + desc.defaultValue = defaultBPO; desc.isQuantized = true; desc.quantizeStep = 1; list.push_back(desc); @@ -302,7 +302,6 @@ (m_inputSampleRate, m_minFrequency, m_maxFrequency, m_bpo, m_interpolation); } - m_prevFeature.clear(); m_haveStartTime = false; m_columnCount = 0; } @@ -329,23 +328,11 @@ const char *n = names[i % 12]; int oct = i / 12 - 1; char buf[20]; - sprintf(buf, "%s%d", n, oct); + sprintf(buf, "%d %s%d", i, n, oct); return buf; } -float -CQVamp::noteFrequency(int note) const -{ - return m_tuningFrequency * pow(2.0, (note - 69) / 12.0); -} - -int -CQVamp::noteNumber(float freq) const -{ - return int(round(57.0 + (12.0 * log(freq / (m_tuningFrequency / 2.0)) / log(2.0)))); -} - CQVamp::OutputList CQVamp::getOutputDescriptors() const { @@ -364,9 +351,11 @@ for (int i = 0; i < (int)d.binCount; ++i) { float freq = m_cq->getBinFrequency(i); sprintf(name, "%.1f Hz", freq); - if (fabs(noteFrequency(noteNumber(freq)) - freq) < 0.01) { - d.binNames.push_back(name + std::string(": ") + - noteName(noteNumber(freq))); + int note = Pitch::getPitchForFrequency(freq, 0, m_tuningFrequency); + float nearestFreq = + Pitch::getFrequencyForPitch(note, 0, m_tuningFrequency); + if (fabs(freq - nearestFreq) < 0.01) { + d.binNames.push_back(name + std::string(" ") + noteName(note)); } else { d.binNames.push_back(name); } @@ -431,8 +420,6 @@ // put low frequencies at the start std::reverse(column.begin(), column.end()); - m_prevFeature = column; - Feature feature; feature.hasTimestamp = true; feature.timestamp = m_startTime + Vamp::RealTime::frame2RealTime