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)),
47 if (m_pitchdet) del_aubio_pitch(m_pitchdet);
48 if (m_ibuf) del_fvec(m_ibuf);
52 Pitch::getIdentifier() const
58 Pitch::getName() const
60 return "Aubio Pitch Detector";
64 Pitch::getDescription() const
66 return "Track estimated note pitches";
70 Pitch::getMaker() const
72 return "Paul Brossier (plugin by Chris Cannam)";
76 Pitch::getPluginVersion() const
82 Pitch::getCopyright() const
88 Pitch::initialise(size_t channels, size_t stepSize, size_t blockSize)
91 std::cerr << "Pitch::initialise: channels must be 1" << std::endl;
95 m_stepSize = stepSize;
96 m_blockSize = blockSize;
98 m_ibuf = new_fvec(stepSize);
100 m_pitchdet = new_aubio_pitchdetection(blockSize,
103 lrintf(m_inputSampleRate),
116 Pitch::getPreferredStepSize() const
122 Pitch::getPreferredBlockSize() const
128 Pitch::getParameterDescriptors() const
132 ParameterDescriptor desc;
133 desc.identifier = "pitchtype";
134 desc.name = "Pitch Detection Function Type";
137 desc.defaultValue = (int)aubio_pitch_yinfft;
138 desc.isQuantized = true;
139 desc.quantizeStep = 1;
140 desc.valueNames.push_back("YIN Frequency Estimator");
141 desc.valueNames.push_back("Spectral Comb");
142 desc.valueNames.push_back("Schmitt");
143 desc.valueNames.push_back("Fast Harmonic Comb");
144 desc.valueNames.push_back("YIN with FFT");
145 list.push_back(desc);
147 desc = ParameterDescriptor();
148 desc.identifier = "minfreq";
149 desc.name = "Minimum Fundamental Frequency";
151 desc.maxValue = m_inputSampleRate/2;
152 desc.defaultValue = getFrequencyForMIDIPitch(32);
154 desc.isQuantized = false;
155 list.push_back(desc);
157 desc = ParameterDescriptor();
158 desc.identifier = "maxfreq";
159 desc.name = "Maximum Fundamental Frequency";
161 desc.maxValue = m_inputSampleRate/2;
162 desc.defaultValue = getFrequencyForMIDIPitch(95);
164 desc.isQuantized = false;
165 list.push_back(desc);
167 desc = ParameterDescriptor();
168 desc.identifier = "wraprange";
169 desc.name = "Fold Higher or Lower Frequencies into Range";
172 desc.defaultValue = 0;
173 desc.isQuantized = true;
174 desc.quantizeStep = 1;
175 list.push_back(desc);
177 desc = ParameterDescriptor();
178 desc.identifier = "silencethreshold";
179 desc.name = "Silence Threshold";
180 desc.minValue = -120;
182 desc.defaultValue = -90;
184 desc.isQuantized = false;
185 list.push_back(desc);
191 Pitch::getParameter(std::string param) const
193 if (param == "pitchtype") {
195 } else if (param == "minfreq") {
197 } else if (param == "maxfreq") {
199 } else if (param == "wraprange") {
200 return m_wrapRange ? 1.0 : 0.0;
201 } else if (param == "silencethreshold") {
209 Pitch::setParameter(std::string param, float value)
211 if (param == "pitchtype") {
212 switch (lrintf(value)) {
213 case 0: m_pitchtype = aubio_pitch_yin; break;
214 case 1: m_pitchtype = aubio_pitch_mcomb; break;
215 case 2: m_pitchtype = aubio_pitch_schmitt; break;
216 case 3: m_pitchtype = aubio_pitch_fcomb; break;
217 case 4: m_pitchtype = aubio_pitch_yinfft; break;
219 } else if (param == "minfreq") {
221 } else if (param == "maxfreq") {
223 } else if (param == "wraprange") {
224 m_wrapRange = (value > 0.5);
225 } else if (param == "silencethreshold") {
231 Pitch::getOutputDescriptors() const
236 d.identifier = "frequency";
237 d.name = "Fundamental Frequency";
239 d.hasFixedBinCount = true;
241 d.hasKnownExtents = false;
242 d.isQuantized = false;
243 d.sampleType = OutputDescriptor::VariableSampleRate;
245 if (m_stepSize != 0) {
246 d.sampleRate = m_inputSampleRate / m_stepSize;
254 Pitch::process(const float *const *inputBuffers,
255 Vamp::RealTime timestamp)
257 FeatureSet returnFeatures;
259 if (m_stepSize == 0) {
260 std::cerr << "Pitch::process: Pitch plugin not initialised" << std::endl;
261 return returnFeatures;
264 for (size_t i = 0; i < m_stepSize; ++i) {
265 for (size_t j = 0; j < m_channelCount; ++j) {
266 fvec_write_sample(m_ibuf, inputBuffers[j][i], j, i);
270 float freq = aubio_pitchdetection(m_pitchdet, m_ibuf);
272 bool silent = aubio_silence_detection(m_ibuf, m_silence);
274 // std::cerr << "(silent)" << std::endl;
275 return returnFeatures;
279 while (freq > 0 && freq < m_minfreq) {
282 while (freq > m_maxfreq) {
287 if (freq < m_minfreq || freq > m_maxfreq) {
288 return returnFeatures;
292 feature.hasTimestamp = true;
293 feature.timestamp = timestamp;
294 feature.values.push_back(freq);
296 returnFeatures[0].push_back(feature);
297 return returnFeatures;
301 Pitch::getRemainingFeatures()