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.
26 getFrequencyForMIDIPitch(int midiPitch)
28 return 440.f * powf(2.0, (float(midiPitch) - 69.0) / 12.0);
31 Pitch::Pitch(float inputSampleRate) :
32 Plugin(inputSampleRate),
35 m_pitchtype(PitchYinFFT),
36 m_minfreq(getFrequencyForMIDIPitch(32)),
37 m_maxfreq(getFrequencyForMIDIPitch(95)),
48 if (m_pitchdet) del_aubio_pitch(m_pitchdet);
49 if (m_ibuf) del_fvec(m_ibuf);
53 Pitch::getIdentifier() const
59 Pitch::getName() const
61 return "Aubio Pitch Detector";
65 Pitch::getDescription() const
67 return "Track estimated note pitches";
71 Pitch::getMaker() const
73 return "Paul Brossier (plugin by Chris Cannam)";
77 Pitch::getPluginVersion() const
83 Pitch::getCopyright() const
89 Pitch::initialise(size_t channels, size_t stepSize, size_t blockSize)
91 m_channelCount = channels;
92 m_stepSize = stepSize;
93 m_blockSize = blockSize;
95 m_ibuf = new_fvec(stepSize, channels);
97 m_pitchdet = new_aubio_pitchdetection(blockSize,
100 lrintf(m_inputSampleRate),
113 Pitch::getPreferredStepSize() const
119 Pitch::getPreferredBlockSize() const
125 Pitch::getParameterDescriptors() const
129 ParameterDescriptor desc;
130 desc.identifier = "pitchtype";
131 desc.name = "Pitch Detection Function Type";
134 desc.defaultValue = (int)aubio_pitch_yinfft;
135 desc.isQuantized = true;
136 desc.quantizeStep = 1;
137 desc.valueNames.push_back("YIN Frequency Estimator");
138 desc.valueNames.push_back("Spectral Comb");
139 desc.valueNames.push_back("Schmitt");
140 desc.valueNames.push_back("Fast Harmonic Comb");
141 desc.valueNames.push_back("YIN with FFT");
142 list.push_back(desc);
144 desc = ParameterDescriptor();
145 desc.identifier = "minfreq";
146 desc.name = "Minimum Fundamental Frequency";
148 desc.maxValue = m_inputSampleRate/2;
149 desc.defaultValue = getFrequencyForMIDIPitch(32);
151 desc.isQuantized = false;
152 list.push_back(desc);
154 desc = ParameterDescriptor();
155 desc.identifier = "maxfreq";
156 desc.name = "Maximum Fundamental Frequency";
158 desc.maxValue = m_inputSampleRate/2;
159 desc.defaultValue = getFrequencyForMIDIPitch(95);
161 desc.isQuantized = false;
162 list.push_back(desc);
164 desc = ParameterDescriptor();
165 desc.identifier = "wraprange";
166 desc.name = "Fold Higher or Lower Frequencies into Range";
169 desc.defaultValue = 0;
170 desc.isQuantized = true;
171 desc.quantizeStep = 1;
172 list.push_back(desc);
174 desc = ParameterDescriptor();
175 desc.identifier = "silencethreshold";
176 desc.name = "Silence Threshold";
177 desc.minValue = -120;
179 desc.defaultValue = -90;
181 desc.isQuantized = false;
182 list.push_back(desc);
188 Pitch::getParameter(std::string param) const
190 if (param == "pitchtype") {
192 } else if (param == "minfreq") {
194 } else if (param == "maxfreq") {
196 } else if (param == "wraprange") {
197 return m_wrapRange ? 1.0 : 0.0;
198 } else if (param == "silencethreshold") {
206 Pitch::setParameter(std::string param, float value)
208 if (param == "pitchtype") {
209 switch (lrintf(value)) {
210 case 0: m_pitchtype = aubio_pitch_yin; break;
211 case 1: m_pitchtype = aubio_pitch_mcomb; break;
212 case 2: m_pitchtype = aubio_pitch_schmitt; break;
213 case 3: m_pitchtype = aubio_pitch_fcomb; break;
214 case 4: m_pitchtype = aubio_pitch_yinfft; break;
216 } else if (param == "minfreq") {
218 } else if (param == "maxfreq") {
220 } else if (param == "wraprange") {
221 m_wrapRange = (value > 0.5);
222 } else if (param == "silencethreshold") {
228 Pitch::getOutputDescriptors() const
233 d.identifier = "frequency";
234 d.name = "Fundamental Frequency";
236 d.hasFixedBinCount = true;
238 d.hasKnownExtents = false;
239 d.isQuantized = false;
240 d.sampleType = OutputDescriptor::VariableSampleRate;
242 if (m_stepSize != 0) {
243 d.sampleRate = m_inputSampleRate / m_stepSize;
251 Pitch::process(const float *const *inputBuffers,
252 Vamp::RealTime timestamp)
254 FeatureSet returnFeatures;
256 if (m_stepSize == 0) {
257 std::cerr << "Pitch::process: Pitch plugin not initialised" << std::endl;
258 return returnFeatures;
261 for (size_t i = 0; i < m_stepSize; ++i) {
262 for (size_t j = 0; j < m_channelCount; ++j) {
263 fvec_write_sample(m_ibuf, inputBuffers[j][i], j, i);
267 float freq = aubio_pitchdetection(m_pitchdet, m_ibuf);
269 bool silent = aubio_silence_detection(m_ibuf, m_silence);
271 // std::cerr << "(silent)" << std::endl;
272 return returnFeatures;
276 while (freq > 0 && freq < m_minfreq) {
279 while (freq > m_maxfreq) {
284 if (freq < m_minfreq || freq > m_maxfreq) {
285 return returnFeatures;
289 feature.hasTimestamp = true;
290 feature.timestamp = timestamp;
291 feature.values.push_back(freq);
293 returnFeatures[0].push_back(feature);
294 return returnFeatures;
298 Pitch::getRemainingFeatures()