Centre for Digital Music, Queen Mary, University of London.
This file copyright 2006 Chris Cannam.
- This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License as
- published by the Free Software Foundation; either version 2 of the
- License, or (at your option) any later version. See the file
- COPYING included with this distribution for more information.
+ This file is part of vamp-aubio-plugins.
+
+ vamp-aubio is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ vamp-aubio is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with aubio. If not, see <http://www.gnu.org/licenses/>.
*/
using std::cerr;
using std::endl;
-static float
-getFrequencyForMIDIPitch(int midiPitch)
-{
- return 440.f * powf(2.0, (float(midiPitch) - 69.0) / 12.0);
-}
-
Pitch::Pitch(float inputSampleRate) :
Plugin(inputSampleRate),
m_ibuf(0),
m_obuf(0),
m_pitchdet(0),
m_pitchtype(PitchYinFFT),
- m_minfreq(getFrequencyForMIDIPitch(32)),
- m_maxfreq(getFrequencyForMIDIPitch(95)),
+ m_minfreq(aubio_miditofreq(32)),
+ m_maxfreq(aubio_miditofreq(95)),
m_silence(-90),
m_wrapRange(false),
m_stepSize(0),
m_ibuf = new_fvec(stepSize);
m_obuf = new_fvec(1);
- m_pitchdet = new_aubio_pitch
- (const_cast<char *>(getAubioNameForPitchType(m_pitchtype)),
- blockSize,
- stepSize,
- lrintf(m_inputSampleRate));
-
- aubio_pitch_set_unit(m_pitchdet, const_cast<char *>("freq"));
+ reset();
return true;
}
void
Pitch::reset()
{
+ if (m_pitchdet) del_aubio_pitch(m_pitchdet);
+
+ m_pitchdet = new_aubio_pitch
+ (const_cast<char *>(getAubioNameForPitchType(m_pitchtype)),
+ m_blockSize,
+ m_stepSize,
+ lrintf(m_inputSampleRate));
+
+ aubio_pitch_set_unit(m_pitchdet, const_cast<char *>("freq"));
}
size_t
ParameterDescriptor desc;
desc.identifier = "pitchtype";
desc.name = "Pitch Detection Function Type";
+ desc.description = "Type of pitch detection function to use";
desc.minValue = 0;
desc.maxValue = 4;
desc.defaultValue = (int)PitchYinFFT;
desc = ParameterDescriptor();
desc.identifier = "minfreq";
desc.name = "Minimum Fundamental Frequency";
+ desc.description = "Lowest frequency to look for";
desc.minValue = 1;
desc.maxValue = m_inputSampleRate/2;
- desc.defaultValue = getFrequencyForMIDIPitch(32);
+ desc.defaultValue = aubio_miditofreq(32);
desc.unit = "Hz";
desc.isQuantized = false;
list.push_back(desc);
desc = ParameterDescriptor();
desc.identifier = "maxfreq";
desc.name = "Maximum Fundamental Frequency";
+ desc.description = "Highest frequency to look for";
desc.minValue = 1;
desc.maxValue = m_inputSampleRate/2;
- desc.defaultValue = getFrequencyForMIDIPitch(95);
+ desc.defaultValue = aubio_miditofreq(95);
desc.unit = "Hz";
desc.isQuantized = false;
list.push_back(desc);
desc = ParameterDescriptor();
desc.identifier = "wraprange";
desc.name = "Fold Higher or Lower Frequencies into Range";
+ desc.description = "Frequencies detected outside the range will be transposed to higher or lower octaves";
desc.minValue = 0;
desc.maxValue = 1;
desc.defaultValue = 0;
desc = ParameterDescriptor();
desc.identifier = "silencethreshold";
desc.name = "Silence Threshold";
+ desc.description = "Silence threshold, the higher the least detection";
desc.minValue = -120;
desc.maxValue = 0;
desc.defaultValue = -90;
OutputDescriptor d;
d.identifier = "frequency";
d.name = "Fundamental Frequency";
+ d.description = "List of detected frequencies";
d.unit = "Hz";
d.hasFixedBinCount = true;
d.binCount = 1;
}
for (size_t i = 0; i < m_stepSize; ++i) {
- fvec_write_sample(m_ibuf, inputBuffers[0][i], i);
+ fvec_set_sample(m_ibuf, inputBuffers[0][i], i);
}
aubio_pitch_do(m_pitchdet, m_ibuf, m_obuf);