Mercurial > hg > constant-q-cpp
comparison vamp/CQVamp.cpp @ 55:2a21b4506d7f
Use MIDI pitch values, as in QM Vamp Plugins implementation
author | Chris Cannam <c.cannam@qmul.ac.uk> |
---|---|
date | Thu, 28 Nov 2013 17:03:57 +0000 |
parents | a25abb7a21c0 |
children | e2b7f7462618 |
comparison
equal
deleted
inserted
replaced
54:2e0d1300a065 | 55:2a21b4506d7f |
---|---|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ | 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ |
2 | 2 |
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 | |
7 #include "qm-dsp/base/Pitch.h" | |
6 | 8 |
7 using std::string; | 9 using std::string; |
8 using std::vector; | 10 using std::vector; |
9 using std::cerr; | 11 using std::cerr; |
10 using std::endl; | 12 using std::endl; |
11 | 13 |
12 CQVamp::CQVamp(float inputSampleRate) : | 14 CQVamp::CQVamp(float inputSampleRate) : |
13 Vamp::Plugin(inputSampleRate), | 15 Vamp::Plugin(inputSampleRate), |
16 m_minMIDIPitch(36), | |
17 m_maxMIDIPitch(84), | |
18 m_tuningFrequency(440), | |
19 m_bpo(24), | |
14 m_cq(0), | 20 m_cq(0), |
15 m_maxFrequency(inputSampleRate/2), | 21 m_maxFrequency(inputSampleRate/2), |
16 m_minFrequency(46), | 22 m_minFrequency(46), |
17 m_bpo(24), | |
18 m_haveStartTime(false), | 23 m_haveStartTime(false), |
19 m_columnCount(0) | 24 m_columnCount(0) |
20 { | 25 { |
21 } | 26 } |
22 | 27 |
63 | 68 |
64 CQVamp::ParameterList | 69 CQVamp::ParameterList |
65 CQVamp::getParameterDescriptors() const | 70 CQVamp::getParameterDescriptors() const |
66 { | 71 { |
67 ParameterList list; | 72 ParameterList list; |
68 | 73 /* |
69 ParameterDescriptor desc; | 74 ParameterDescriptor desc; |
70 desc.identifier = "minfreq"; | 75 desc.identifier = "minfreq"; |
71 desc.name = "Minimum Frequency"; | 76 desc.name = "Minimum Frequency"; |
72 desc.unit = "Hz"; | 77 desc.unit = "Hz"; |
73 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"; | 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"; |
82 desc.unit = "Hz"; | 87 desc.unit = "Hz"; |
83 desc.description = "Highest frequency to be included in the constant-Q transform"; | 88 desc.description = "Highest frequency to be included in the constant-Q transform"; |
84 desc.minValue = 10; | 89 desc.minValue = 10; |
85 desc.maxValue = m_inputSampleRate/2; | 90 desc.maxValue = m_inputSampleRate/2; |
86 desc.defaultValue = m_inputSampleRate/2; | 91 desc.defaultValue = m_inputSampleRate/2; |
92 desc.isQuantized = false; | |
93 list.push_back(desc); | |
94 */ | |
95 ParameterDescriptor desc; | |
96 desc.identifier = "minpitch"; | |
97 desc.name = "Minimum Pitch"; | |
98 desc.unit = "MIDI units"; | |
99 desc.description = "MIDI pitch corresponding to the lowest frequency to be included in the constant-Q transform"; | |
100 desc.minValue = 0; | |
101 desc.maxValue = 127; | |
102 desc.defaultValue = 36; | |
103 desc.isQuantized = true; | |
104 desc.quantizeStep = 1; | |
105 list.push_back(desc); | |
106 | |
107 desc.identifier = "maxpitch"; | |
108 desc.name = "Maximum Pitch"; | |
109 desc.unit = "MIDI units"; | |
110 desc.description = "MIDI pitch corresponding to the highest frequency to be included in the constant-Q transform"; | |
111 desc.minValue = 0; | |
112 desc.maxValue = 127; | |
113 desc.defaultValue = 84; | |
114 desc.isQuantized = true; | |
115 desc.quantizeStep = 1; | |
116 list.push_back(desc); | |
117 | |
118 desc.identifier = "tuning"; | |
119 desc.name = "Tuning Frequency"; | |
120 desc.unit = "Hz"; | |
121 desc.description = "Frequency of concert A"; | |
122 desc.minValue = 360; | |
123 desc.maxValue = 500; | |
124 desc.defaultValue = 440; | |
87 desc.isQuantized = false; | 125 desc.isQuantized = false; |
88 list.push_back(desc); | 126 list.push_back(desc); |
89 | 127 |
90 desc.identifier = "bpo"; | 128 desc.identifier = "bpo"; |
91 desc.name = "Bins per Octave"; | 129 desc.name = "Bins per Octave"; |
102 } | 140 } |
103 | 141 |
104 float | 142 float |
105 CQVamp::getParameter(std::string param) const | 143 CQVamp::getParameter(std::string param) const |
106 { | 144 { |
145 if (param == "minpitch") { | |
146 return m_minMIDIPitch; | |
147 } | |
148 if (param == "maxpitch") { | |
149 return m_maxMIDIPitch; | |
150 } | |
151 if (param == "tuning") { | |
152 return m_tuningFrequency; | |
153 } | |
154 /* | |
107 if (param == "minfreq") { | 155 if (param == "minfreq") { |
108 return m_minFrequency; | 156 return m_minFrequency; |
109 } | 157 } |
110 if (param == "maxfreq") { | 158 if (param == "maxfreq") { |
111 return m_maxFrequency; | 159 return m_maxFrequency; |
112 } | 160 } |
161 */ | |
113 if (param == "bpo") { | 162 if (param == "bpo") { |
114 return m_bpo; | 163 return m_bpo; |
115 } | 164 } |
116 std::cerr << "WARNING: CQVamp::getParameter: unknown parameter \"" | 165 std::cerr << "WARNING: CQVamp::getParameter: unknown parameter \"" |
117 << param << "\"" << std::endl; | 166 << param << "\"" << std::endl; |
119 } | 168 } |
120 | 169 |
121 void | 170 void |
122 CQVamp::setParameter(std::string param, float value) | 171 CQVamp::setParameter(std::string param, float value) |
123 { | 172 { |
124 if (param == "minfreq") { | 173 if (param == "minpitch") { |
174 m_minMIDIPitch = lrintf(value); | |
175 } else if (param == "maxpitch") { | |
176 m_maxMIDIPitch = lrintf(value); | |
177 } else if (param == "tuning") { | |
178 m_tuningFrequency = value; | |
179 /* if (param == "minfreq") { | |
125 m_minFrequency = value; | 180 m_minFrequency = value; |
126 } else if (param == "maxfreq") { | 181 } else if (param == "maxfreq") { |
127 m_maxFrequency = value; | 182 m_maxFrequency = value; |
128 } else if (param == "bpo") { | 183 */ |
184 } else if (param == "bpo") { | |
129 m_bpo = lrintf(value); | 185 m_bpo = lrintf(value); |
130 } else { | 186 } else { |
131 std::cerr << "WARNING: CQVamp::setParameter: unknown parameter \"" | 187 std::cerr << "WARNING: CQVamp::setParameter: unknown parameter \"" |
132 << param << "\"" << std::endl; | 188 << param << "\"" << std::endl; |
133 } | 189 } |
144 if (channels < getMinChannelCount() || | 200 if (channels < getMinChannelCount() || |
145 channels > getMaxChannelCount()) return false; | 201 channels > getMaxChannelCount()) return false; |
146 | 202 |
147 m_stepSize = stepSize; | 203 m_stepSize = stepSize; |
148 m_blockSize = blockSize; | 204 m_blockSize = blockSize; |
205 | |
206 m_minFrequency = Pitch::getFrequencyForPitch | |
207 (m_minMIDIPitch, 0, m_tuningFrequency); | |
208 m_maxFrequency = Pitch::getFrequencyForPitch | |
209 (m_maxMIDIPitch, 0, m_tuningFrequency); | |
149 | 210 |
150 m_cq = new ConstantQ | 211 m_cq = new ConstantQ |
151 (m_inputSampleRate, m_minFrequency, m_maxFrequency, m_bpo); | 212 (m_inputSampleRate, m_minFrequency, m_maxFrequency, m_bpo); |
152 | 213 |
153 return true; | 214 return true; |
255 (m_columnCount * m_cq->getColumnHop() - m_cq->getLatency(), | 316 (m_columnCount * m_cq->getColumnHop() - m_cq->getLatency(), |
256 m_inputSampleRate); | 317 m_inputSampleRate); |
257 feature.values = column; | 318 feature.values = column; |
258 feature.label = ""; | 319 feature.label = ""; |
259 | 320 |
260 cerr << "timestamp = " << feature.timestamp << " (latency = " << m_cq->getLatency() << ", sample rate " << m_inputSampleRate << ")" << endl; | 321 // cerr << "timestamp = " << feature.timestamp << " (latency = " << m_cq->getLatency() << ", sample rate " << m_inputSampleRate << ")" << endl; |
261 | 322 |
262 if (feature.timestamp >= m_startTime) { | 323 if (feature.timestamp >= m_startTime) { |
263 returnFeatures[0].push_back(feature); | 324 returnFeatures[0].push_back(feature); |
264 } | 325 } |
265 | 326 |