1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
4 Vamp feature extraction plugins using Paul Brossier's Aubio library.
6 Centre for Digital Music, Queen Mary, University of London.
7 This file copyright 2006 Chris Cannam.
9 This program is free software; you can redistribute it and/or
10 modify it under the terms of the GNU General Public License as
11 published by the Free Software Foundation; either version 2 of the
12 License, or (at your option) any later version. See the file
13 COPYING included with this distribution for more information.
25 Pitch::Pitch(float inputSampleRate) :
26 Plugin(inputSampleRate),
30 m_pitchtype(PitchYinFFT),
31 m_minfreq(aubio_miditofreq(32)),
32 m_maxfreq(aubio_miditofreq(95)),
42 if (m_pitchdet) del_aubio_pitch(m_pitchdet);
43 if (m_ibuf) del_fvec(m_ibuf);
44 if (m_obuf) del_fvec(m_obuf);
48 Pitch::getIdentifier() const
54 Pitch::getName() const
56 return "Aubio Pitch Detector";
60 Pitch::getDescription() const
62 return "Track estimated note pitches";
66 Pitch::getMaker() const
68 return "Paul Brossier (plugin by Chris Cannam)";
72 Pitch::getPluginVersion() const
78 Pitch::getCopyright() const
84 Pitch::initialise(size_t channels, size_t stepSize, size_t blockSize)
87 std::cerr << "Pitch::initialise: channels must be 1" << std::endl;
91 m_stepSize = stepSize;
92 m_blockSize = blockSize;
94 m_ibuf = new_fvec(stepSize);
105 if (m_pitchdet) del_aubio_pitch(m_pitchdet);
107 m_pitchdet = new_aubio_pitch
108 (const_cast<char *>(getAubioNameForPitchType(m_pitchtype)),
111 lrintf(m_inputSampleRate));
113 aubio_pitch_set_unit(m_pitchdet, const_cast<char *>("freq"));
117 Pitch::getPreferredStepSize() const
123 Pitch::getPreferredBlockSize() const
129 Pitch::getParameterDescriptors() const
133 ParameterDescriptor desc;
134 desc.identifier = "pitchtype";
135 desc.name = "Pitch Detection Function Type";
136 desc.description = "Type of pitch detection function to use";
139 desc.defaultValue = (int)PitchYinFFT;
140 desc.isQuantized = true;
141 desc.quantizeStep = 1;
142 desc.valueNames.push_back("YIN Frequency Estimator");
143 desc.valueNames.push_back("Spectral Comb");
144 desc.valueNames.push_back("Schmitt");
145 desc.valueNames.push_back("Fast Harmonic Comb");
146 desc.valueNames.push_back("YIN with FFT");
147 list.push_back(desc);
149 desc = ParameterDescriptor();
150 desc.identifier = "minfreq";
151 desc.name = "Minimum Fundamental Frequency";
152 desc.description = "Lowest frequency to look for";
154 desc.maxValue = m_inputSampleRate/2;
155 desc.defaultValue = aubio_miditofreq(32);
157 desc.isQuantized = false;
158 list.push_back(desc);
160 desc = ParameterDescriptor();
161 desc.identifier = "maxfreq";
162 desc.name = "Maximum Fundamental Frequency";
163 desc.description = "Highest frequency to look for";
165 desc.maxValue = m_inputSampleRate/2;
166 desc.defaultValue = aubio_miditofreq(95);
168 desc.isQuantized = false;
169 list.push_back(desc);
171 desc = ParameterDescriptor();
172 desc.identifier = "wraprange";
173 desc.name = "Fold Higher or Lower Frequencies into Range";
174 desc.description = "Frequencies detected outside the range will be transposed to higher or lower octaves";
177 desc.defaultValue = 0;
178 desc.isQuantized = true;
179 desc.quantizeStep = 1;
180 list.push_back(desc);
182 desc = ParameterDescriptor();
183 desc.identifier = "silencethreshold";
184 desc.name = "Silence Threshold";
185 desc.description = "Silence threshold, the higher the least detection";
186 desc.minValue = -120;
188 desc.defaultValue = -90;
190 desc.isQuantized = false;
191 list.push_back(desc);
197 Pitch::getParameter(std::string param) const
199 if (param == "pitchtype") {
201 } else if (param == "minfreq") {
203 } else if (param == "maxfreq") {
205 } else if (param == "wraprange") {
206 return m_wrapRange ? 1.0 : 0.0;
207 } else if (param == "silencethreshold") {
215 Pitch::setParameter(std::string param, float value)
217 if (param == "pitchtype") {
218 switch (lrintf(value)) {
219 case 0: m_pitchtype = PitchYin; break;
220 case 1: m_pitchtype = PitchMComb; break;
221 case 2: m_pitchtype = PitchSchmitt; break;
222 case 3: m_pitchtype = PitchFComb; break;
223 case 4: m_pitchtype = PitchYinFFT; break;
225 } else if (param == "minfreq") {
227 } else if (param == "maxfreq") {
229 } else if (param == "wraprange") {
230 m_wrapRange = (value > 0.5);
231 } else if (param == "silencethreshold") {
237 Pitch::getOutputDescriptors() const
242 d.identifier = "frequency";
243 d.name = "Fundamental Frequency";
244 d.description = "List of detected frequencies";
246 d.hasFixedBinCount = true;
248 d.hasKnownExtents = false;
249 d.isQuantized = false;
250 d.sampleType = OutputDescriptor::VariableSampleRate;
252 if (m_stepSize != 0) {
253 d.sampleRate = m_inputSampleRate / m_stepSize;
261 Pitch::process(const float *const *inputBuffers,
262 Vamp::RealTime timestamp)
264 FeatureSet returnFeatures;
266 if (m_stepSize == 0) {
267 std::cerr << "Pitch::process: Pitch plugin not initialised" << std::endl;
268 return returnFeatures;
271 for (size_t i = 0; i < m_stepSize; ++i) {
272 fvec_set_sample(m_ibuf, inputBuffers[0][i], i);
275 aubio_pitch_do(m_pitchdet, m_ibuf, m_obuf);
277 float freq = m_obuf->data[0];
279 bool silent = aubio_silence_detection(m_ibuf, m_silence);
281 // std::cerr << "(silent)" << std::endl;
282 return returnFeatures;
286 while (freq > 0 && freq < m_minfreq) {
289 while (freq > m_maxfreq) {
294 if (freq < m_minfreq || freq > m_maxfreq) {
295 return returnFeatures;
299 feature.hasTimestamp = true;
300 feature.timestamp = timestamp;
301 feature.values.push_back(freq);
303 returnFeatures[0].push_back(feature);
304 return returnFeatures;
308 Pitch::getRemainingFeatures()