# Pitch correction

> Detects the pitch of a monophonic input and pulls it to the nearest note of the Toy tuning, a scale or held MIDI notes.

Source: https://docs.tune.toys/nodes/std.autotune/

Pitch correction listens to a single voice or instrument, finds the note it is closest to and moves it onto that note.

## What it does

The node measures the input's pitch every 5–6 ms with the YIN method, searching between Lowest note and Highest note. Steady tones are measured to well inside a cent. Silence, noise and other sounds without a clear pitch keep the last correction.

The target is the nearest note of the Toy's tuning, the same tuning its instruments play, so it follows 19-EDO, just intonation or a custom scale. In a 12-degree tuning, Scale and Key limit the targets to the notes of a scale. When notes are held on the `midi` input, the nearest held note is the target instead. A target changes only when another note is clearly nearer, so a voice sitting between two notes does not flutter.

Retune sets how quickly the correction reaches a new target, and Amount how much of the distance it corrects. The correction drives the same splicing shifter as the [Pitch shifter](https://docs.tune.toys/nodes/std.pitch/), with a fixed 40 ms window. Every channel of the cable is corrected together from the pitch of all channels mixed.

The node delays everything by 20 ms, and the Patch aligns parallel paths around it. At Amount 0 it is an exact delay.

## When to use it

Use it to tighten a sung or played line, for the hard snapped effect at Retune 0, to force a melody into a scale, or with held MIDI notes to play a voice's pitch from a keyboard. It expects one note at a time; chords and drums have no single pitch to correct.

## Ports

<!-- ports:start -->

| Port    | Direction | Signal | Lanes                   |
| ------- | --------- | ------ | ----------------------- |
| `audio` | Input     | Audio  | Inferred from the cable |
| `midi`  | Input     | MIDI   | 16 MIDI channels        |
| `audio` | Output    | Audio  | Inferred from the cable |

<!-- ports:end -->

## Parameters

<!-- parameters:start -->

| Parameter   | Label        | Range       | Default | Unit | Scale  | Notes                                                                                                                                                                                                                                                                              |
| ----------- | ------------ | ----------- | ------- | ---- | ------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `retune_ms` | Retune       | 0 to 500    | 40      | ms   | linear | Time the correction takes to reach a new target; 0 snaps at once.                                                                                                                                                                                                                  |
| `amount`    | Amount       | 0 to 1      | 1       |      | linear | Fraction of the distance to the target that is corrected.                                                                                                                                                                                                                          |
| `scale`     | Scale        | 0 to 6      | 0       |      | linear | Notes the correction may target. Tuning allows every note of the Toy tuning; the scales apply to 12-degree tunings and allow every note otherwise. Held MIDI notes override it. Choices: 0 Tuning, 1 Major, 2 Minor, 3 Pentatonic major, 4 Pentatonic minor, 5 Blues, 6 Chromatic. |
| `key`       | Key          | 0 to 11     | 0       |      | linear | Tonic of the scale. Choices: 0 C, 1 C♯, 2 D, 3 D♯, 4 E, 5 F, 6 F♯, 7 G, 8 G♯, 9 A, 10 A♯, 11 B. Shown when `scale` is 1 or 2 or 3 or 4 or 5.                                                                                                                                       |
| `low_hz`    | Lowest note  | 50 to 1000  | 70      | Hz   | log    | Lowest pitch the detector looks for.                                                                                                                                                                                                                                               |
| `high_hz`   | Highest note | 100 to 2000 | 1000    | Hz   | log    | Highest pitch the detector looks for.                                                                                                                                                                                                                                              |
| `mix`       | Mix          | 0 to 1      | 1       |      | linear | Dry/wet blend. The dry signal is delayed by the same latency before blending.                                                                                                                                                                                                      |

<!-- parameters:end -->

### Retune (`retune_ms`)

The time the correction takes to cover 99% of a change in target, 0 to 500 ms. 0 snaps at once for the robotic effect; 20–60 ms is tight but smooth; 100 ms and up lets vibrato and slides through.

### Amount (`amount`)

How much of the distance to the target is corrected, from 0 (none) to 1 (all of it).

### Scale (`scale`)

The notes the correction may target. Tuning allows every note of the Toy tuning. Major, Minor, Pentatonic major, Pentatonic minor, Blues and Chromatic apply in 12-degree tunings such as 12-TET, just or Pythagorean; in other tunings they allow every note. Held MIDI notes override the scale.

### Key (`key`)

The tonic of the scale, C to B.

### Lowest note (`low_hz`)

The lowest pitch the detector looks for, 50 to 1000 Hz.

### Highest note (`high_hz`)

The highest pitch the detector looks for, 100 to 2000 Hz. If it is set below Lowest note, the two swap.

### Mix (`mix`)

The blend of the dry input and the corrected sound. The dry input is delayed by the same 20 ms so the two line up.

## Tips

- Set Lowest note and Highest note just around the voice: a tighter range avoids octave mistakes and saves work.
- Retune 0 with Scale set to Pentatonic minor gives the hard stepping effect.
- Connect a [Keyboard](https://docs.tune.toys/nodes/midi.keyboard/) to `midi` and hold a chord: the voice jumps to whichever held note is nearest.
- Change the Toy's tuning to 19-EDO and the same voice snaps to 19 notes per octave.

## See also

[Pitch shifter](https://docs.tune.toys/nodes/std.pitch/), [Harmonizer](https://docs.tune.toys/nodes/std.harmonizer/), [Tuner](https://docs.tune.toys/nodes/std.tuner/), [Keyboard](https://docs.tune.toys/nodes/midi.keyboard/), [MIDI](https://docs.tune.toys/concepts/midi/).
