Note gaps
Audio to MIDI: one silent frame between notes.
That is 22 ms at 44.1 kHz on a normal attack — and only 6 ms if the attack and release take 80 ms. A shorter gap merges the pair into one note.
🔒 The selected audio is decoded in your browser; it is not uploaded to a server.
The rule
A note is extended, never restarted, while the next frame lands within one semitone of it.
Inside the detector the audio is cut into overlapping windows 1,024 samples long, advanced 256 samples at a time. Each window produces one pitch estimate. If that estimate is within one semitone of the note currently in progress, the note is extended and its end moves forward; anything further starts a new note. Nothing else marks a note boundary — not an onset, not a change in loudness, not a change in timbre.
For two notes to come back separately, the run of windows must be broken by at least one window that reads as silence. A window reads as silence when its RMS falls below 0.015. That is the whole test, and it is why the number that matters is not how long the gap sounds but how many windows it is wide enough to starve.
This page measures that number for the case that produces the complaint: two different pitches, played back to back, with a short gap. The same-pitch case behaves differently and is covered on the missing-notes page, because repeated fingerings are a separate rule.
Measured
On a normal attack the gap has to reach 22 ms — and the analysis frame is 23.2 ms.
Take twelve rising semitones, C4 to B4, each 0.40 s long, built from three harmonics at 1, 0.5 and 0.25 amplitude, peak 0.32, 44.1 kHz mono. Give every note the same linear fade-in and fade-out of length r, and put a gap of g between consecutive notes. Change only r and g. The table gives how many of the twelve semitones survive.
| Fade r | 0 ms gap | 10 ms | 20 ms | 25 ms | 30 ms |
|---|---|---|---|---|---|
| 1 ms | 6 of 12 | 6 of 12 | 9 of 12 | 12 of 12 | 12 of 12 |
| 5 ms | 6 of 12 | 6 of 12 | 10 of 12 | 12 of 12 | 12 of 12 |
| 10 ms | 6 of 12 | 6 of 12 | 10 of 12 | 12 of 12 | 12 of 12 |
| 20 ms | 6 of 12 | 6 of 12 | 12 of 12 | 12 of 12 | 12 of 12 |
| 40 ms | 6 of 12 | 6 of 12 | 12 of 12 | 12 of 12 | 12 of 12 |
| 80 ms | 6 of 12 | 12 of 12 | 12 of 12 | 12 of 12 | 12 of 12 |
Balanced (RMS gate 0.015, minimum note 75 ms). "6 of 12" is the floor, not a failure of the run: the merged pairs still produce six pitches that were genuinely played, so the count saturates there no matter how tight the gap. Reproduction: node run-gap-ramp.js, table A.
Follow one column down and the fade length barely matters: at a 10 ms gap every row from 1 ms to 40 ms returns six. Follow one row across and the gap matters enormously. The exception is the bottom-left corner, where an 80 ms fade rescues the pair with a 10 ms gap. That corner is the whole subject of this page.
The threshold
The minimum gap is 22 ms on a sharp attack, and it halves once the fade passes 15 ms.
Bisecting the gap to a quarter of a millisecond gives the exact threshold for each fade length. The interesting column is the ratio to the analysis frame, which is 23.22 ms at 44.1 kHz.
| Fade r | Minimum gap | Gap ÷ frame |
|---|---|---|
| 1 ms | 22.03 ms | 0.95 |
| 5 ms | 22.34 ms | 0.96 |
| 10 ms | 22.34 ms | 0.96 |
| 15 ms | 20.63 ms | 0.89 |
| 20 ms | 18.13 ms | 0.78 |
| 30 ms | 17.66 ms | 0.76 |
| 40 ms | 15.00 ms | 0.65 |
| 60 ms | 10.63 ms | 0.46 |
| 80 ms | 6.41 ms | 0.28 |
Each row is a bisection held to 0.25 ms. Reproduction: node run-gap-ramp.js, table B.
Three things fall out. First, a sharp attack sits at 0.95 to 0.96 frames, which is the statement that the gap has to be about one window wide: with a shorter gap, no single window can be positioned so that it contains mostly silence. Second, the ratio is flat from 1 ms to 10 ms and then breaks downward, so there is a knee rather than a slope. Third, by 80 ms the requirement has dropped to 6.41 ms, well under a third of a frame — the slow fade has done most of the work the gap used to do.
That last point is the practical one. If your notes fade in and out over 80 ms — which is what a soft pad, a bowed string, or any note with a gentle attack looks like — then 10 ms of silence is enough and you never see this problem. If your notes have sharp attacks, as plucked and struck instruments do, 10 ms is less than half of what you need.
The mechanism
A slow fade puts a quiet window at the boundary; a sharp one never does.
The threshold follows from where the windows land, and the per-frame trace makes it concrete. Below is the boundary between C4 and C#4, printed as RMS and reported pitch for every window that overlaps it. The gate is 0.015, so a row marked below the gate is a window the detector counts as silence.
| Time | RMS | Reported | Case |
|---|---|---|---|
| 0.7430 s | 0.135 | MIDI 61 | 5 ms fade, 10 ms gap |
| 0.7488 s | 0.162 | MIDI 61 | 5 ms fade, 10 ms gap |
| 0.7546 s | 0.205 | MIDI 61 | 5 ms fade, 10 ms gap |
| 0.7488 s | 0.003 | — (silence) | 5 ms fade, 22 ms gap |
| 0.7546 s | 0.076 | MIDI 62 | 5 ms fade, 22 ms gap |
| 0.7605 s | 0.160 | MIDI 61 | 5 ms fade, 22 ms gap |
| 0.7430 s | 0.013 | — (silence) | 80 ms fade, 7 ms gap |
| 0.7488 s | 0.024 | MIDI 61 | 80 ms fade, 7 ms gap |
All three runs are C4 to C#4, 0.40 s per note, 0.35 s of lead silence, three harmonics, peak 0.32, Balanced. Rows are a subset of the full trace in run-gap-ramp.js, table H. C4 reads lag 169 (261.6 Hz), C#4 reads lag 159 (277.2 Hz).
Read the first three rows together. With a 5 ms fade and a 10 ms gap, every window at the boundary still carries energy well above the gate, and every one of them reads MIDI 61. There is no silence in the run, so the note is extended from C4 into C#4 and the pair collapses to one event. The pitch flips at 0.7430 s and nothing marks it.
Now the fourth through sixth rows, the same fade with a 22 ms gap. One window at 0.7488 s lands at RMS 0.003, less than a fifth of the gate. The run is broken there, the first note closes, and the next window opens a new one. Note the transition row in between: at 0.7546 s with the 22 ms gap the estimate reads MIDI 62, then settles onto 61. That is the window still straddling the boundary and mixing the two tones, and it is why the repair is not instant — the first window after the break can read one semitone past the note that is actually sounding.
The last two rows are the 80 ms fade with only 7 ms of gap. A single window at 0.7430 s reads RMS 0.013, just under the gate. That is enough. The slow fade has already pulled the boundary energy down to 88% of the threshold at the right moment, so the gap does not need to be wide at all. The window that breaks the run is not a silent gap in the signal; it is a boundary the fade made quiet.
What does not move it
Sensitivity, level and timbre leave the threshold alone. Note length moves it by 2 ms.
Five settings were varied around the sharp-attack case to see whether the 22 ms figure is robust or a coincidence of one configuration.
| Setting | Minimum gap | Change |
|---|---|---|
| More notes | 22.34 ms | — |
| Balanced | 22.34 ms | 0.00 ms |
| Fewer notes | 22.34 ms | 0.00 ms |
| Pure sine | 22.03 ms | −0.31 ms |
| 8 harmonics | 22.34 ms | 0.00 ms |
| Peak 0.50 | 22.34 ms | 0.00 ms |
| Peak 0.10 | 20.47 ms | −1.87 ms |
All rows at a 5 ms fade, 0.40 s notes, twelve rising semitones from C4. Reproduction: node run-gap-ramp.js, tables C and E.
The sensitivity slider does nothing at all here, which is worth knowing before you reach for it: all three positions give the same 22.34 ms. It moves the RMS gate and the minimum note length, but a quiet window at a boundary is quiet by more than the slider can compensate for, and the merge decision is made before the duration test that the missing-notes page covers.
Level is nearly flat too, and only the quiet end moves. Dropping the peak to 0.10 — about −20 dBFS — shortens the requirement by 1.87 ms, because a quieter file crosses the fixed gate a little sooner at the boundary and a slightly narrower gap can starve a window. That is the same asymmetry the note-length page measures from the other direction, where a quieter take produces shorter notes for the same reason.
Note length is the only one of the five that moves the threshold by more than 2 ms, and even then only at the extremes:
| Note length | Minimum gap | Gap ÷ frame |
|---|---|---|
| 0.15 s | 20.63 ms | 0.89 |
| 0.25 s | 21.41 ms | 0.92 |
| 0.40 s | 22.34 ms | 0.96 |
| 0.80 s | 22.97 ms | 0.99 |
| 1.50 s | 22.81 ms | 0.98 |
5 ms fade throughout. Reproduction: node run-gap-ramp.js, table D.
Across a tenfold range of note lengths the requirement stays inside 2 ms of one frame. Longer notes need marginally more gap, which is the frame-count argument in a different coat: the note has to fill enough consecutive windows to survive the 75 ms minimum, and a shorter note reaches that count with a shorter run, leaving the boundary windows a little more room.
Two notes or twelve
Two adjacent notes open with 8 ms. Twelve need 22 ms. The chain length sets the bar.
Everything above used a twelve-note chromatic line, and that choice was not neutral. Running the same bisection on shorter chains shows the threshold is not a property of a single boundary but of how many boundaries are stacked in a row.
| Notes in the line | Minimum gap | Gap ÷ frame |
|---|---|---|
| 2 | 15.31 ms | 0.66 |
| 3 | 18.13 ms | 0.78 |
| 4 | 18.13 ms | 0.78 |
| 6 | 18.28 ms | 0.79 |
| 8 | 18.75 ms | 0.81 |
| 12 | 22.34 ms | 0.96 |
5 ms fade, 0.40 s notes, rising semitones from C4. Reproduction: node run-gap-ramp.js, table F.
The threshold climbs from 15 ms for a pair to 22 ms for a full octave of semitones. The reason is that a merged pair does not just cost you one note — it hands the following note a pitch that is already one semitone away from where the detector thinks it is, and the stack of small errors accumulates until a slightly wider gap is needed to break the run somewhere. For a two-note phrase, 8 ms of silence is enough; for a chromatic run, it is not.
This is why site-wide advice on this topic is fragile. A number measured on a pair, or on a phrase, will not hold for a line, and the difference is almost 50%.
The other rule
Repeating the same pitch is a different problem, and an 8 ms gap settles it.
The missing-notes page reports that two notes of the same pitch separated by 10 ms come back as two, and that is correct — but it is a different mechanism from the one above, and mixing them up produces wrong advice. Both cases were run side by side at a 5 ms fade.
| Gap | A3 then A3 (same pitch) | A3 then A#3 (semitone) |
|---|---|---|
| 0 ms | 1 note | 1 note |
| 5 ms | 1 note | 1 note |
| 8 ms | 2 notes | 2 notes |
| 10 ms | 2 notes | 2 notes |
| 15 ms | 2 notes | 2 notes |
| 25 ms | 2 notes | 2 notes |
Two notes, 0.40 s each, 5 ms fade, 0.35 s lead silence, three harmonics, peak 0.32, Balanced. Reproduction: node run-gap-ramp.js, table G.
On a pair, both rules give the same answer and both cross at 8 ms, so a pair cannot tell them apart. The difference appears at length: the same-pitch rule does not care how many repeats are stacked, because each repeat is measured against its immediate predecessor only, while the different-pitch rule tightens as the chain grows, from 15 ms to 22 ms between two notes and twelve. That is the reason a chromatic run loses notes and a repeated note does not, and it is why the advice cannot be carried from one page to the other without re-measuring.
Limits
What this test does not cover
The limit of this test. Every signal here is synthesised, not recorded: exact harmonics at 1, 0.5 and 0.25 amplitude, no noise, no vibrato, one channel, 44.1 kHz, and a linear fade that is the same length at the front and the back of each note. A real instrument has an asymmetric envelope, a moving spectrum and a noise floor, and none of that was measured. The gap is a true digital silence; a recording with room tone in the gap would need a wider one, because the gate tests loudness rather than whether a note is sounding, and room tone above 0.015 would keep every window alive.
The frame size and the hop are both derived from the sample rate, so at 48 kHz the frame becomes 1,024 samples at 48,000 Hz — 21.3 ms rather than 23.22 ms — and every millisecond figure on this page scales with it. The percentages do not. Do not carry the 22 ms number to a different device without re-running it.
Two boundaries are also excluded by design. Pitches above 1,423 Hz are outside the search range entirely and come back an octave low rather than merging, which is a different failure measured on the high-notes page. And a note shorter than the 75 ms minimum is removed before the merge rule can act on it, which is the gate described on the missing-notes page.
Questions
Note gaps and this converter
How much silence do I need between two notes?
For two adjacent semitones with a normal attack, about 22 ms, which is close to the analysis frame of 23.22 ms at 44.1 kHz. If the notes fade in and out over 80 ms, 6 ms is enough. Between those two extremes the requirement scales with the fade length, and the ratio to the frame drops from 0.96 to 0.28.
Why does a chromatic run lose half its notes when a two-note phrase does not?
Because the threshold grows with the number of boundaries in the line. Two notes need 15 ms of gap; twelve need 22 ms. Each merge hands the next note a pitch that is already slightly off, and the accumulated error means a wider gap is required to break the run at all. A short phrase measured in isolation gives a threshold that is too optimistic for a full run.
Does the sensitivity slider help?
No. All three settings give the same 22.34 ms threshold on a sharp attack, because the merge decision happens when a window reads below the RMS gate, and the three gates differ by less than the margin at the boundary. The slider moves the minimum note length and the loudness floor, neither of which is the deciding test here. Widen the gap in the source instead.
My notes fade, so is this a problem for me?
Probably not. A fade of 20 ms brings the requirement down to 18 ms, and 80 ms brings it to 6.4 ms. If your instruments have slow attacks — pads, bowed strings, anything with a swell — 10 ms of separation is enough and the merge will not bite. Plucked and struck instruments sit at the other end, which is where 10 ms fails.
Can I fix this after the conversion instead?
Yes, and for a passage that is already merged it is the only practical fix. The exported file contains note events, so you can split the merged note in a piano roll and move the second half up a semitone. What the file does not contain is a boundary marker at the point the merge happened, so you have to find it by ear against the source — which is why separating the notes before converting, by articulating them with a short gap, is cheaper than repair.
Doesn't the missing-notes page already say 10 ms is enough?
It says that for two notes of the same pitch, and it is right for that case. Repeated fingerings are evaluated against the immediately preceding note only, so the threshold does not grow with the chain, and a pair crosses at 8 ms for both rules. The 22 ms figure applies to different pitches in a longer line, which the missing-notes page does not measure. Both numbers are correct for their own condition.
Related readings
Other measurements on the same loop.
The missing-notes page covers the minimum-duration gate that removes notes entirely, including the same-pitch repeat rule contrasted above. The note-length page measures how long a surviving note is written, which is the same loudness gate read at the tail rather than at the boundary. The accuracy page collects the register and ceiling failures that this page leaves out — including the chromatic run whose 10 ms result depends on the 80 ms fade used there.
Reproduction: node run-gap-ramp.js regenerates every table on this page and prints the detector’s sha256 in its first line (77a9dd6b, 8,069 B). The detector is read straight out of the production converter.js by detector-from-live.js rather than re-implemented, so these numbers move when the shipped detector moves. The log for this run is localmidi-private/logs/gap-ramp-2026-12-01.txt.