#include "signalsmith-pitchtrack/pitchtrack.h"
signalsmith::pitchtrack::PitchTrack tracker;
tracker.config(sampleRate, maxBlockLength=0, latencySamples=<2ms>, overlap=<2.5>);The maxBlockLength is optional, but providing it guarantees no allocations. Latency is specified in samples, and shouldn't be greater than 10ms. Higher latency uses less CPU, and increased overlap uses more, but I think the default configuration is pretty reasonable.
You pass the tracker a block of audio, but it doesn't give you any output. Instead, you then check the list of timed pitch updates:
const float *floatSamples;
tracker.analyse(floatSamples, length);
for (auto &update : tracker.events()) {...}
These update events (signalsmith::pitchtrack::PitchEvent) have:
.voiced(bool) - if this isfalse, then the other results should be less trusted.hz(Hz).energy- square-root this to get an RMS (amplitude) level.tonality(0-1), where0means it's classified as noise,1means it's a note..tonalityRaw(0-1), a raw energy ratio which never actually reaches 0-1 except in silence..offset(size_t) relative to the start of the block, not including the analysis latency.
This event array is replaced by the next .analyse() call, and cleared by a call to tracker.reset() (which also clears the internal buffers/etc.)
For simplicity (and speed), it uses single-channel, 32-bit float. There are four steps to the processing:
This is done using the Linear library, so set SIGNALSMITH_USE_... if you want Accelerate/PFFT/IPP/etc.
The resonators are complex Butterworth filters (roughly equivalent to 4th-order bandpass) run at the downsampled rate.
This estimates the instantaneous pitch (and confidence), by comparing energy near harmonics against total energy.
The estimator produces multiple peaks, and this stage has some heuristics to produce smoother results in the case of noise/uncertainty.
The code is MIT Licensed, and there may be some quirks since this is a fairly new project.
The test/ directory includes a smoke-test which runs the tracker over an audio file from the vocadito data set.