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_blockSize(0),
- m_channelCount(0)
+ m_blockSize(0)
{
}
{
if (m_pitchdet) del_aubio_pitch(m_pitchdet);
if (m_ibuf) del_fvec(m_ibuf);
+ if (m_obuf) del_fvec(m_obuf);
}
string
bool
Pitch::initialise(size_t channels, size_t stepSize, size_t blockSize)
{
- m_channelCount = channels;
+ if (channels != 1) {
+ std::cerr << "Pitch::initialise: channels must be 1" << std::endl;
+ return false;
+ }
+
m_stepSize = stepSize;
m_blockSize = blockSize;
- m_ibuf = new_fvec(stepSize, channels);
+ m_ibuf = new_fvec(stepSize);
+ m_obuf = new_fvec(1);
- m_pitchdet = new_aubio_pitchdetection(blockSize,
- stepSize,
- channels,
- lrintf(m_inputSampleRate),
- m_pitchtype,
- m_pitchmode);
+ 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)aubio_pitch_yinfft;
+ desc.defaultValue = (int)PitchYinFFT;
desc.isQuantized = true;
desc.quantizeStep = 1;
desc.valueNames.push_back("YIN Frequency Estimator");
desc = ParameterDescriptor();
desc.identifier = "minfreq";
desc.name = "Minimum Fundamental Frequency";
+ desc.description = "Lower 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;
{
if (param == "pitchtype") {
switch (lrintf(value)) {
- case 0: m_pitchtype = aubio_pitch_yin; break;
- case 1: m_pitchtype = aubio_pitch_mcomb; break;
- case 2: m_pitchtype = aubio_pitch_schmitt; break;
- case 3: m_pitchtype = aubio_pitch_fcomb; break;
- case 4: m_pitchtype = aubio_pitch_yinfft; break;
+ case 0: m_pitchtype = PitchYin; break;
+ case 1: m_pitchtype = PitchMComb; break;
+ case 2: m_pitchtype = PitchSchmitt; break;
+ case 3: m_pitchtype = PitchFComb; break;
+ case 4: m_pitchtype = PitchYinFFT; break;
}
} else if (param == "minfreq") {
m_minfreq = value;
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) {
- for (size_t j = 0; j < m_channelCount; ++j) {
- fvec_write_sample(m_ibuf, inputBuffers[j][i], j, i);
- }
+ fvec_set_sample(m_ibuf, inputBuffers[0][i], i);
}
- float freq = aubio_pitchdetection(m_pitchdet, m_ibuf);
+ aubio_pitch_do(m_pitchdet, m_ibuf, m_obuf);
+
+ float freq = m_obuf->data[0];
bool silent = aubio_silence_detection(m_ibuf, m_silence);
if (silent) {