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(aubio_pitch_yinfft),
36 m_pitchmode(aubio_pitchm_freq),
37 m_minfreq(getFrequencyForMIDIPitch(32)),
38 m_maxfreq(getFrequencyForMIDIPitch(95)),
49 if (m_pitchdet) del_aubio_pitchdetection(m_pitchdet);
50 if (m_ibuf) del_fvec(m_ibuf);
54 Pitch::getIdentifier() const
60 Pitch::getName() const
62 return "Aubio Pitch Detector";
66 Pitch::getDescription() const
68 return "Track estimated note pitches";
72 Pitch::getMaker() const
74 return "Paul Brossier (plugin by Chris Cannam)";
78 Pitch::getPluginVersion() const
84 Pitch::getCopyright() const
90 Pitch::initialise(size_t channels, size_t stepSize, size_t blockSize)
92 m_channelCount = channels;
93 m_stepSize = stepSize;
94 m_blockSize = blockSize;
96 m_ibuf = new_fvec(stepSize, channels);
98 m_pitchdet = new_aubio_pitchdetection(blockSize,
101 lrintf(m_inputSampleRate),
114 Pitch::getPreferredStepSize() const
120 Pitch::getPreferredBlockSize() const
126 Pitch::getParameterDescriptors() const
130 ParameterDescriptor desc;
131 desc.identifier = "pitchtype";
132 desc.name = "Pitch Detection Function Type";
135 desc.defaultValue = (int)aubio_pitch_yinfft;
136 desc.isQuantized = true;
137 desc.quantizeStep = 1;
138 desc.valueNames.push_back("YIN Frequency Estimator");
139 desc.valueNames.push_back("Spectral Comb");
140 desc.valueNames.push_back("Schmitt");
141 desc.valueNames.push_back("Fast Harmonic Comb");
142 desc.valueNames.push_back("YIN with FFT");
143 list.push_back(desc);
145 desc = ParameterDescriptor();
146 desc.identifier = "minfreq";
147 desc.name = "Minimum Fundamental Frequency";
149 desc.maxValue = m_inputSampleRate/2;
150 desc.defaultValue = getFrequencyForMIDIPitch(32);
152 desc.isQuantized = false;
153 list.push_back(desc);
155 desc = ParameterDescriptor();
156 desc.identifier = "maxfreq";
157 desc.name = "Maximum Fundamental Frequency";
159 desc.maxValue = m_inputSampleRate/2;
160 desc.defaultValue = getFrequencyForMIDIPitch(95);
162 desc.isQuantized = false;
163 list.push_back(desc);
165 desc = ParameterDescriptor();
166 desc.identifier = "wraprange";
167 desc.name = "Fold Higher or Lower Frequencies into Range";
170 desc.defaultValue = 0;
171 desc.isQuantized = true;
172 desc.quantizeStep = 1;
173 list.push_back(desc);
175 desc = ParameterDescriptor();
176 desc.identifier = "silencethreshold";
177 desc.name = "Silence Threshold";
178 desc.minValue = -120;
180 desc.defaultValue = -90;
182 desc.isQuantized = false;
183 list.push_back(desc);
189 Pitch::getParameter(std::string param) const
191 if (param == "pitchtype") {
193 } else if (param == "minfreq") {
195 } else if (param == "maxfreq") {
197 } else if (param == "wraprange") {
198 return m_wrapRange ? 1.0 : 0.0;
199 } else if (param == "silencethreshold") {
207 Pitch::setParameter(std::string param, float value)
209 if (param == "pitchtype") {
210 switch (lrintf(value)) {
211 case 0: m_pitchtype = aubio_pitch_yin; break;
212 case 1: m_pitchtype = aubio_pitch_mcomb; break;
213 case 2: m_pitchtype = aubio_pitch_schmitt; break;
214 case 3: m_pitchtype = aubio_pitch_fcomb; break;
215 case 4: m_pitchtype = aubio_pitch_yinfft; break;
217 } else if (param == "minfreq") {
219 } else if (param == "maxfreq") {
221 } else if (param == "wraprange") {
222 m_wrapRange = (value > 0.5);
223 } else if (param == "silencethreshold") {
229 Pitch::getOutputDescriptors() const
234 d.identifier = "frequency";
235 d.name = "Fundamental Frequency";
237 d.hasFixedBinCount = true;
239 d.hasKnownExtents = false;
240 d.isQuantized = false;
241 d.sampleType = OutputDescriptor::VariableSampleRate;
243 if (m_stepSize != 0) {
244 d.sampleRate = m_inputSampleRate / m_stepSize;
252 Pitch::process(const float *const *inputBuffers,
253 Vamp::RealTime timestamp)
255 FeatureSet returnFeatures;
257 if (m_stepSize == 0) {
258 std::cerr << "Pitch::process: Pitch plugin not initialised" << std::endl;
259 return returnFeatures;
262 for (size_t i = 0; i < m_stepSize; ++i) {
263 for (size_t j = 0; j < m_channelCount; ++j) {
264 fvec_write_sample(m_ibuf, inputBuffers[j][i], j, i);
268 float freq = aubio_pitchdetection(m_pitchdet, m_ibuf);
270 bool silent = aubio_silence_detection(m_ibuf, m_silence);
272 // std::cerr << "(silent)" << std::endl;
273 return returnFeatures;
277 while (freq > 0 && freq < m_minfreq) {
280 while (freq > m_maxfreq) {
285 if (freq < m_minfreq || freq > m_maxfreq) {
286 return returnFeatures;
290 feature.hasTimestamp = true;
291 feature.timestamp = timestamp;
292 feature.values.push_back(freq);
294 returnFeatures[0].push_back(feature);
295 return returnFeatures;
299 Pitch::getRemainingFeatures()