Pitch Correction and Note Editing
Pitch correction nudges a note from its current pitch toward a target.
Note editing reshapes a chosen region, such as stretching one held note or tightening timing, without touching the rest of the clip.
Both are surgical, region-aware edits rather than whole-clip transforms. This page explains them through libsonare's PitchCorrector and NoteEditor; for the vocabulary, read Editing Basics.
You supply the current pitch
pitchCorrectToMidi does not guess what note you sang. You provide the current note.
The workflow is:
- Estimate the current pitch with
pitchYin,pitchPyin, or your own detector. - Convert or read that pitch as a MIDI note number.
- Pass the measured value as the current MIDI note.
- Pass the desired note as the target MIDI note.
MIDI note numbers are semitone indexes:
| Example | Meaning |
|---|---|
69 | A4, 440 Hz |
68.7 | Slightly below A4 |
60 | C4, middle C |
Fractional values are normal because singers are rarely exactly on a note.
Correction strength and transparency
Correction is a pitch shift applied over a region, so the same artifact rules apply: small intervals stay transparent, large ones expose phase-vocoder smearing. For natural vocals, correct by small amounts toward the nearest scale tone rather than forcing a big jump. Hard, full-snap correction is a creative effect, not a transparent fix.
Note regions: samples, not seconds
Region-based edits like noteStretch take sample offsets, not seconds, because sample positions are exact and never drift. Convert with samples = round(seconds × sampleRate) — at 48 kHz, 0.25 s is sample 12000. A region has an onset sample and an offset sample; stretchRatio > 1 lengthens that region while leaving the surrounding audio in place.
How libsonare corrects and edits
pitchCorrectToMidi maps a current→target MIDI interval to a pitch shift over the signal, reusing the phase-vocoder path from Time Stretch and Pitch Shift. Region edits use NoteEditor (NoteEditorConfig) over a NoteRegion defined by onset/offset sample offsets, with NoteSegmenter helping locate regions. noteStretch applies a region-bounded stretch ratio. All operate on decoded mono samples; the Audio wrapper exposes the same operations as instance methods so file workflows can load once and edit.
Related: Editing Basics, Time Stretch and Pitch Shift, Melody and Pitch, Editing DSP