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";
138 desc.defaultValue = (int)PitchYinFFT;
139 desc.isQuantized = true;
140 desc.quantizeStep = 1;
141 desc.valueNames.push_back("YIN Frequency Estimator");
142 desc.valueNames.push_back("Spectral Comb");
143 desc.valueNames.push_back("Schmitt");
144 desc.valueNames.push_back("Fast Harmonic Comb");
145 desc.valueNames.push_back("YIN with FFT");
146 list.push_back(desc);
148 desc = ParameterDescriptor();
149 desc.identifier = "minfreq";
150 desc.name = "Minimum Fundamental Frequency";
152 desc.maxValue = m_inputSampleRate/2;
153 desc.defaultValue = aubio_miditofreq(32);
155 desc.isQuantized = false;
156 list.push_back(desc);
158 desc = ParameterDescriptor();
159 desc.identifier = "maxfreq";
160 desc.name = "Maximum Fundamental Frequency";
162 desc.maxValue = m_inputSampleRate/2;
163 desc.defaultValue = aubio_miditofreq(95);
165 desc.isQuantized = false;
166 list.push_back(desc);
168 desc = ParameterDescriptor();
169 desc.identifier = "wraprange";
170 desc.name = "Fold Higher or Lower Frequencies into Range";
173 desc.defaultValue = 0;
174 desc.isQuantized = true;
175 desc.quantizeStep = 1;
176 list.push_back(desc);
178 desc = ParameterDescriptor();
179 desc.identifier = "silencethreshold";
180 desc.name = "Silence Threshold";
181 desc.minValue = -120;
183 desc.defaultValue = -90;
185 desc.isQuantized = false;
186 list.push_back(desc);
192 Pitch::getParameter(std::string param) const
194 if (param == "pitchtype") {
196 } else if (param == "minfreq") {
198 } else if (param == "maxfreq") {
200 } else if (param == "wraprange") {
201 return m_wrapRange ? 1.0 : 0.0;
202 } else if (param == "silencethreshold") {
210 Pitch::setParameter(std::string param, float value)
212 if (param == "pitchtype") {
213 switch (lrintf(value)) {
214 case 0: m_pitchtype = PitchYin; break;
215 case 1: m_pitchtype = PitchMComb; break;
216 case 2: m_pitchtype = PitchSchmitt; break;
217 case 3: m_pitchtype = PitchFComb; break;
218 case 4: m_pitchtype = PitchYinFFT; break;
220 } else if (param == "minfreq") {
222 } else if (param == "maxfreq") {
224 } else if (param == "wraprange") {
225 m_wrapRange = (value > 0.5);
226 } else if (param == "silencethreshold") {
232 Pitch::getOutputDescriptors() const
237 d.identifier = "frequency";
238 d.name = "Fundamental Frequency";
240 d.hasFixedBinCount = true;
242 d.hasKnownExtents = false;
243 d.isQuantized = false;
244 d.sampleType = OutputDescriptor::VariableSampleRate;
246 if (m_stepSize != 0) {
247 d.sampleRate = m_inputSampleRate / m_stepSize;
255 Pitch::process(const float *const *inputBuffers,
256 Vamp::RealTime timestamp)
258 FeatureSet returnFeatures;
260 if (m_stepSize == 0) {
261 std::cerr << "Pitch::process: Pitch plugin not initialised" << std::endl;
262 return returnFeatures;
265 for (size_t i = 0; i < m_stepSize; ++i) {
266 fvec_set_sample(m_ibuf, inputBuffers[0][i], i);
269 aubio_pitch_do(m_pitchdet, m_ibuf, m_obuf);
271 float freq = m_obuf->data[0];
273 bool silent = aubio_silence_detection(m_ibuf, m_silence);
275 // std::cerr << "(silent)" << std::endl;
276 return returnFeatures;
280 while (freq > 0 && freq < m_minfreq) {
283 while (freq > m_maxfreq) {
288 if (freq < m_minfreq || freq > m_maxfreq) {
289 return returnFeatures;
293 feature.hasTimestamp = true;
294 feature.timestamp = timestamp;
295 feature.values.push_back(freq);
297 returnFeatures[0].push_back(feature);
298 return returnFeatures;
302 Pitch::getRemainingFeatures()