@maruaudio/dsp/analysis/pitch-tracking interprets a stream of measured pitches as one causal monophonic voice. In direct mode (0) it passes the fractional MIDI pitch through once a note is active; in note mode (1) it outputs integer notes gated by attack, release and change dwell times with hysteresis around the held note. Each update reports noteOn and noteOff flags for that update only. An optional, experimental tuning estimate accumulates stable pitches on the semitone circle (a confidence-weighted circular mean of the fractional part, 0.75 s time constant) and, in note mode with compensation on, slews a correction of up to ±50 cents toward it over 250 ms.
Parameters
configurePitchTracking(state, mode, compensation, attackMs, releaseMs, changeMs, hysteresisCents)
| Argument | Range as coded | Default from init | Unit |
|---|---|---|---|
mode | ≥ 0.5 is note mode, else direct | 0 | index |
compensation | ≥ 0.5 is on | 0 | flag |
attackMs | 0 to 1000 | 35 | ms |
releaseMs | 0 to 2000 | 80 | ms |
changeMs | 0 to 1000 | 35 | ms |
hysteresisCents | 0 to 49 | 15 | cents |
Lifecycle
initPitchTracking(sampleRate) (a rate outside 8 to 192 kHz becomes 48 kHz) → configurePitchTracking → updatePitchTracking(state, midi, confidence, rms, voiced, elapsedSamples) per detector hop, or advancePitchTracking, which separates render-clock time from fresh measurement time → resetPitchTracking. Configuring a different mode requires the caller to release any held note and then reset.
When to use it
Turning a pitch detector's output into MIDI notes or a continuous pitch for a pitch-to-MIDI or pitch-following instrument. The Pitchy module uses it.
Limits
- Scalar state, no allocation. An observation counts only when voiced, MIDI is 0 to 127, confidence 0.5 to 1 and RMS above 0; otherwise silence accumulates and releases the note after
releaseMs. Two seconds of silence clear tuning. - Updates with
elapsedSamplesof 0 or more than ten seconds are ignored. - The tuning estimate is experimental: not a key or scale estimator and not a calibrated probability. Onsets, transitions and slides faster than 4 semitones per second are excluded from it.
- Velocity is
min(1, rms × √2).