Mercurial > hg > constant-q-cpp
comparison vamp/CQVamp.cpp @ 58:daf7c92058da
Put spectrogram the "right" way up, add bin labels
author | Chris Cannam <c.cannam@qmul.ac.uk> |
---|---|
date | Thu, 30 Jan 2014 12:12:16 +0000 |
parents | e2b7f7462618 |
children | 27007f8302f4 |
comparison
equal
deleted
inserted
replaced
57:65575499e4b9 | 58:daf7c92058da |
---|---|
3 #include "CQVamp.h" | 3 #include "CQVamp.h" |
4 | 4 |
5 #include "cpp-qm-dsp/ConstantQ.h" | 5 #include "cpp-qm-dsp/ConstantQ.h" |
6 | 6 |
7 #include "base/Pitch.h" | 7 #include "base/Pitch.h" |
8 | |
9 #include <algorithm> | |
10 #include <cstdio> | |
8 | 11 |
9 using std::string; | 12 using std::string; |
10 using std::vector; | 13 using std::vector; |
11 using std::cerr; | 14 using std::cerr; |
12 using std::endl; | 15 using std::endl; |
68 | 71 |
69 CQVamp::ParameterList | 72 CQVamp::ParameterList |
70 CQVamp::getParameterDescriptors() const | 73 CQVamp::getParameterDescriptors() const |
71 { | 74 { |
72 ParameterList list; | 75 ParameterList list; |
73 /* | 76 |
74 ParameterDescriptor desc; | |
75 desc.identifier = "minfreq"; | |
76 desc.name = "Minimum Frequency"; | |
77 desc.unit = "Hz"; | |
78 desc.description = "Hint for the lowest frequency to be included in the constant-Q transform. The actual frequency range will be an integral number of octaves ending at the highest frequency specified"; | |
79 desc.minValue = 10; | |
80 desc.maxValue = m_inputSampleRate/2; | |
81 desc.defaultValue = 46; | |
82 desc.isQuantized = false; | |
83 list.push_back(desc); | |
84 | |
85 desc.identifier = "maxfreq"; | |
86 desc.name = "Maximum Frequency"; | |
87 desc.unit = "Hz"; | |
88 desc.description = "Highest frequency to be included in the constant-Q transform"; | |
89 desc.minValue = 10; | |
90 desc.maxValue = m_inputSampleRate/2; | |
91 desc.defaultValue = m_inputSampleRate/2; | |
92 desc.isQuantized = false; | |
93 list.push_back(desc); | |
94 */ | |
95 ParameterDescriptor desc; | 77 ParameterDescriptor desc; |
96 desc.identifier = "minpitch"; | 78 desc.identifier = "minpitch"; |
97 desc.name = "Minimum Pitch"; | 79 desc.name = "Minimum Pitch"; |
98 desc.unit = "MIDI units"; | 80 desc.unit = "MIDI units"; |
99 desc.description = "MIDI pitch corresponding to the lowest frequency to be included in the constant-Q transform"; | 81 desc.description = "MIDI pitch corresponding to the lowest frequency to be included in the constant-Q transform"; |
149 return m_maxMIDIPitch; | 131 return m_maxMIDIPitch; |
150 } | 132 } |
151 if (param == "tuning") { | 133 if (param == "tuning") { |
152 return m_tuningFrequency; | 134 return m_tuningFrequency; |
153 } | 135 } |
154 /* | |
155 if (param == "minfreq") { | |
156 return m_minFrequency; | |
157 } | |
158 if (param == "maxfreq") { | |
159 return m_maxFrequency; | |
160 } | |
161 */ | |
162 if (param == "bpo") { | 136 if (param == "bpo") { |
163 return m_bpo; | 137 return m_bpo; |
164 } | 138 } |
165 std::cerr << "WARNING: CQVamp::getParameter: unknown parameter \"" | 139 std::cerr << "WARNING: CQVamp::getParameter: unknown parameter \"" |
166 << param << "\"" << std::endl; | 140 << param << "\"" << std::endl; |
174 m_minMIDIPitch = lrintf(value); | 148 m_minMIDIPitch = lrintf(value); |
175 } else if (param == "maxpitch") { | 149 } else if (param == "maxpitch") { |
176 m_maxMIDIPitch = lrintf(value); | 150 m_maxMIDIPitch = lrintf(value); |
177 } else if (param == "tuning") { | 151 } else if (param == "tuning") { |
178 m_tuningFrequency = value; | 152 m_tuningFrequency = value; |
179 /* if (param == "minfreq") { | |
180 m_minFrequency = value; | |
181 } else if (param == "maxfreq") { | |
182 m_maxFrequency = value; | |
183 */ | |
184 } else if (param == "bpo") { | 153 } else if (param == "bpo") { |
185 m_bpo = lrintf(value); | 154 m_bpo = lrintf(value); |
186 } else { | 155 } else { |
187 std::cerr << "WARNING: CQVamp::setParameter: unknown parameter \"" | 156 std::cerr << "WARNING: CQVamp::setParameter: unknown parameter \"" |
188 << param << "\"" << std::endl; | 157 << param << "\"" << std::endl; |
249 d.name = "Constant-Q Spectrogram"; | 218 d.name = "Constant-Q Spectrogram"; |
250 d.unit = ""; | 219 d.unit = ""; |
251 d.description = "Output of constant-Q transform, as a single vector per process block"; | 220 d.description = "Output of constant-Q transform, as a single vector per process block"; |
252 d.hasFixedBinCount = true; | 221 d.hasFixedBinCount = true; |
253 d.binCount = (m_cq ? m_cq->getTotalBins() : (9 * 24)); | 222 d.binCount = (m_cq ? m_cq->getTotalBins() : (9 * 24)); |
223 | |
224 if (m_cq) { | |
225 char name[20]; | |
226 for (int i = 0; i < d.binCount; ++i) { | |
227 float freq = m_cq->getBinFrequency(i); | |
228 sprintf(name, "%.1f Hz", freq); | |
229 d.binNames.push_back(name); | |
230 } | |
231 } | |
232 | |
254 d.hasKnownExtents = false; | 233 d.hasKnownExtents = false; |
255 d.isQuantized = false; | 234 d.isQuantized = false; |
256 d.sampleType = OutputDescriptor::FixedSampleRate; | 235 d.sampleType = OutputDescriptor::FixedSampleRate; |
257 d.sampleRate = m_inputSampleRate / (m_cq ? m_cq->getColumnHop() : 256); | 236 d.sampleRate = m_inputSampleRate / (m_cq ? m_cq->getColumnHop() : 256); |
258 list.push_back(d); | 237 list.push_back(d); |
306 if (j < (int)m_prevFeature.size()) { | 285 if (j < (int)m_prevFeature.size()) { |
307 column[j] = m_prevFeature[j]; | 286 column[j] = m_prevFeature[j]; |
308 } | 287 } |
309 } | 288 } |
310 | 289 |
290 // put low frequencies at the start | |
291 std::reverse(column.begin(), column.end()); | |
292 | |
311 m_prevFeature = column; | 293 m_prevFeature = column; |
312 | 294 |
313 Feature feature; | 295 Feature feature; |
314 feature.hasTimestamp = true; | 296 feature.hasTimestamp = true; |
315 feature.timestamp = m_startTime + Vamp::RealTime::frame2RealTime | 297 feature.timestamp = m_startTime + Vamp::RealTime::frame2RealTime |