comparison 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
comparison
equal deleted inserted replaced
112:a45b51ea00a2 113:26217edee359
41 using std::string; 41 using std::string;
42 using std::vector; 42 using std::vector;
43 using std::cerr; 43 using std::cerr;
44 using std::endl; 44 using std::endl;
45 45
46 static const int defaultLowestOctave = 1; 46 static const int defaultLowestOctave = 0;
47 static const int defaultOctaveCount = 8; 47 static const int defaultOctaveCount = 7;
48 static const int defaultBPO = 36; 48 static const int defaultBPO = 36;
49 static const float defaultTuningFrequency = 440.f; 49 static const float defaultTuningFrequency = 440.f;
50 50
51 CQChromaVamp::CQChromaVamp(float inputSampleRate) : 51 CQChromaVamp::CQChromaVamp(float inputSampleRate) :
52 Vamp::Plugin(inputSampleRate), 52 Vamp::Plugin(inputSampleRate),
206 206
207 m_stepSize = stepSize; 207 m_stepSize = stepSize;
208 m_blockSize = blockSize; 208 m_blockSize = blockSize;
209 209
210 int highestOctave = m_lowestOctave + m_octaveCount - 1; 210 int highestOctave = m_lowestOctave + m_octaveCount - 1;
211 int highestMIDIPitch = (1 + highestOctave) * 12 + 11; 211
212 212 int midiPitchLimit = (1 + highestOctave) * 12 + 12; // C just beyond top
213 m_maxFrequency = Pitch::getFrequencyForPitch 213 double midiPitchLimitFreq =
214 (highestMIDIPitch, 0, m_tuningFrequency); 214 Pitch::getFrequencyForPitch(midiPitchLimit, 0, m_tuningFrequency);
215 m_minFrequency = m_maxFrequency / pow(2, m_octaveCount + 1) * 215
216 pow(2, 1.0 / m_bpo); 216 // Max frequency is frequency of the MIDI pitch just beyond the
217 // top octave range (midiPitchLimit) minus one bin, then minus
218 // floor(bins per semitone / 2)
219 int bps = m_bpo / 12;
220 m_maxFrequency = midiPitchLimitFreq / pow(2, (1.0 + floor(bps/2)) / m_bpo);
221
222 // Min frequency is frequency of midiPitchLimit lowered by the
223 // appropriate number of octaves.
224 m_minFrequency = midiPitchLimitFreq / pow(2, m_octaveCount + 1);
217 225
218 cerr << "lowest octave: " << m_lowestOctave << ", highest octave: " 226 cerr << "lowest octave: " << m_lowestOctave << ", highest octave: "
219 << highestOctave << ", highest midi pitch: " << highestMIDIPitch 227 << highestOctave << ", limit midi pitch: " << midiPitchLimit
220 << ", min freq " << m_minFrequency << ", max freq " << m_maxFrequency 228 << ", min freq " << m_minFrequency << ", max freq " << m_maxFrequency
221 << endl; 229 << endl;
222 230
223 m_cq = new CQSpectrogram 231 m_cq = new CQSpectrogram
224 (m_inputSampleRate, m_minFrequency, m_maxFrequency, m_bpo, 232 (m_inputSampleRate, m_minFrequency, m_maxFrequency, m_bpo,