Trills and fast alternation

Audio to MIDI and trills: past about 7 alternations a second, two notes come back as one.

Measured on C4 ↔ D4: at 6 Hz both pitches survive as 19 notes; at 8 Hz the whole run collapses to one 75 ms note. The pitch never changes — only the rate.

Select an audio file to create a MIDI draft locally.

The selected audio is decoded in your browser; it is not uploaded to a server.

A trill is two pitches trading places fast, and on C4 ↔ D4 a 1.6 s run of it at 8 Hz comes back as a single 75 ms note. Nothing about the pitch changes — the alternation rate does.

The converter turns a run of analysis windows into one note when consecutive windows agree on a pitch within one semitone. A trill is the gesture built to break that rule, but it breaks it by length rather than by ambiguity: while the window can still sit inside a single half-cycle it reads each note correctly, and the note is thrown away anyway because the run of agreeing windows is shorter than the minimum note the tool will keep. The alternation does not have to confuse the pitch search. It only has to make every segment too short to pass a gate.

That failure has a number attached and it is not the one you would guess. It is not set by the pitch distance and it is not set by the note length you played — it is set by the shortest note the tool will keep, divided by the half-cycle. The rate at which a trill stops being a trill is measurable, and it moves when you change the sensitivity setting but not when you change the instrument.

Measured

One pair of pitches, one peak level, one variable: how fast they alternate.

The signal is C4 (261.6 Hz, MIDI 60) and D4 (293.7 Hz, MIDI 62) trading places for 1.6 seconds. Each note is built from five harmonics at 1/h amplitude, the pair is crossfaded over 5 ms at each handover, peak is normalised to 0.5 (−6 dBFS), 44.1 kHz mono, with 0.40 s of digital silence in front. Down the table only the alternation rate changes — the two pitches, the peak level, the harmonic count and the total length are identical in every row.

1.6 s of C4↔D4 alternation per row, 5 harmonics at 1/h, 5 ms crossfade, 44.1 kHz mono, peak 0.5, 0.40 s of silence in front. Note sensitivity Balanced (75 ms minimum note). Detector 77a9dd6b. Reproduction: node run-trill.js, section 1.

Alternations / sHalf-cycleNotes returnedAverage note length
2250 ms7231 ms
3167 ms10161 ms
4125 ms13124 ms
5100 ms16101 ms
683 ms1984 ms
771 ms976 ms
863 ms175 ms
1050 ms0—
1242 ms0—
2025 ms0—
3017 ms0—

Two rows carry the story. Up to 6 Hz the note count tracks the alternation almost exactly — 19 notes for 19 half-cycles in 1.6 seconds — and each note is about as long as the half-cycle it came from. At 8 Hz the same 1.6 seconds of audio returns one note, 75 ms long, at the very start of the run; everything after it is gone. There is no gradual degradation between them: 7 Hz still returns 9 notes, so the step from 7 to 8 is where the count falls off a cliff rather than a slope.

The 7 Hz row is worth reading closely because it is intermediate in an unexpected way. It returns 9 notes for 22 half-cycles, and the notes that survive are not spread evenly through the run — the sequence is 60, 60, 62, 62, 62, 62, 62, 62, 62. The first pitch is duplicated, then the second one repeats six times. Individual half-cycles are being merged into runs that happen to land on the same pitch, and the boundaries between them fall wherever the window grid allows.

Mechanism

Every note is one window, so a note shorter than the minimum cannot exist.

The detector works in overlapping windows: 1,024 samples advanced by 256, which at 44.1 kHz is a 23.2 ms window every 5.8 ms. A note is a run of consecutive windows that agree, and it is only written if the run lasts at least the minimum note length — 75 ms at Balanced. That is not a segmentation heuristic, it is a hard gate: a run one window short of 12.9 window-steps is discarded outright, with no output and no warning.

So the question for a trill is simply whether a half-cycle can produce a run of windows long enough. A half-cycle of 83 ms contains 14 window-steps, and a note survives. A half-cycle of 63 ms contains 11, and it does not. The threshold sits at 12.9 window-steps, which is 75 ms, which for this pair is 6.67 alternations a second.

Segment lengths measured on the same signal, Balanced, threshold 0.015. Median over the 1.6 s run, with the window grid at 5.805 ms. Reproduction: node probe-trill-threshold.js, section 2.

RateHalf-cycleMedian segmentSegments over 75 msNotes returned
4 Hz125.0 ms121.9 ms13 of 1413
5 Hz100.0 ms98.7 ms16 of 1716
6 Hz83.3 ms81.3 ms19 of 2119
7 Hz71.4 ms75.5 ms9 of 249
8 Hz62.5 ms75.5 ms1 of 271
10 Hz50.0 ms52.2 ms0 of 330

Look at the segment lengths against the half-cycles: at 4 and 5 Hz they match within 3 ms, and from 6 Hz up they stop matching. At 8 Hz the median surviving segment is 75.5 ms for a half-cycle of 62.5 ms — 13 ms longer, and 75.5 is exactly the gate. That is not a coincidence and it is not a coincidence that it is the only segment that survives. A segment runs from the frame where the pitch changes to the frame after the next change, so its length is the half-cycle plus one hop of 5.8 ms plus wherever the grid happens to land; the ones that clear the gate are the ones where that arithmetic tips over 75. Read the “9 of 24” row the same way: fifteen segments were just under, nine were just over, and the nine that were over are the nine that got written.

Here is the handover frame by frame at 8 Hz, single harmonic to keep it readable. Column five is the pitch the window's own period search returned.

Frame dump around one handover, 8 Hz, single-harmonic C4↔C5, Balanced, threshold 0.015. Window 1,024 samples, hop 256 (5.805 ms). Reproduction: node probe-trill-boundary.js.

Window startShare of window on the low notePitch read
429.6 ms100%MIDI 60
441.2 ms92%MIDI 60
447.0 ms67%MIDI 60
452.8 ms42%MIDI 60
458.6 ms17%MIDI 60
464.4 ms0%MIDI 72
470.2 ms0%MIDI 72

The window keeps reporting the low note until it contains none of it, then switches. There is no frame in between that reports a pitch between the two. So the boundary the detector draws is late on one side and clean on the other: the outgoing half-cycle is stretched by one window, the incoming one is shortened by the same amount. For a two-semitone trill that asymmetry is small enough to ignore. For an octave it is not, and the next section shows what it does.

Widest interval, worst outcome

An octave trill returns the low note and throws the high note away.

The 8 Hz number above is for two semitones. Widen the interval and something unexpected happens: the trill starts working again at 8 Hz, and the high note disappears entirely.

Same recipe, same rate, same sensitivity, only the interval changes. Cells are notes returned from 1.6 s of alternation at 8 Hz, five harmonics, Balanced. Reproduction: node run-trill.js, section 2.

IntervalPitchesNotes at 8 HzWhat came back
1 semitoneC4↔C♯41one held note, 1,614 ms, at C♯4
2 semitonesC4↔D41the first 75 ms only
3 semitonesC4↔D♯40nothing
5 semitonesC4↔F40nothing
7 semitonesC4↔G40nothing
12 semitonesC4↔C51313 notes, all MIDI 60, median 81 ms

Thirteen notes come back and every one of them is the low pitch. The high note is played for half the run and appears zero times. That is worse than returning nothing, because the file looks complete: the rhythm of the trill is there, at roughly half the rate it was played, and the second pitch has silently been deleted.

The reason is in the segment table. At 8 Hz an octave apart, the low note's half-cycles produce segments with a median of 81 ms and the high note's produce 41 ms — 1.30 half-cycles against 0.65. All thirteen low segments pass the 75 ms gate; none of the thirteen high segments does, the longest of them 52 ms. Nothing is being averaged; the high segments are simply half as long as they should be, and half is shorter than the gate.

The asymmetry comes from the lag, not from the loudness. The low note C4 has a period of 3.82 ms (168 samples) and the high note C5 has a period of 1.91 ms (84 samples). An octave is exactly a factor of two, so lag 168 is a valid period for both notes at once: C5 shifted by 168 samples is C5 again, two cycles later. The period search therefore has one lag that both notes reinforce, and it climbs whenever there is any low content in the window. Measured frame by frame: of the frames reading the low pitch during the octave trill, 14 of 177 (7.9%) contain less than a quarter of the window on the low note — the window has already handed over and the lag has not. On a two-semitone trill the same count is 0 of 124, because 3.90 ms is not a multiple of 3.41 ms and no shared lag exists. Record the same trill backwards, high note first, and the numbers swap: the high segments measure 46 ms and the low ones 81.

Segment medians and counts for the same 8 Hz octave trill, both orders, five harmonics, Balanced. Reproduction: node probe-trill-edge.js, section 2.

Played firstLow-note segmentHigh-note segmentNotes outPitches out
C481 ms (13 of 13 pass)41 ms (13, none pass)13all C4
C581 ms (12 of 13 pass)46 ms (14, none pass)12all C4

Both orders return only the low pitch, and the low segments are 81 ms in both, so the asymmetry follows the pitch and not the order. A two-semitone trill does not show this because the two half-cycles produce segments of 58 and 64 ms — both below the gate, both discarded, which is why the whole run collapses instead of half of it.

The one-semitone row deserves its own note because it is a different failure with the same symptom. Two neighbouring pitches merge into a single note under the detector's one-semitone rule, so a C4↔C♯4 trill is never two notes no matter how slowly it is played: at 3 Hz it returns one 1,614 ms note, at 30 Hz it returns one 1,614 ms note. What changes is which pitch gets printed. The frame counts settle at almost exactly half each, and the median therefore flips with tiny changes in the run: 60 at 3, 4 and 6 Hz; 61 at 5, 7, 8, 10, 15, 20 and 30 Hz. A semitone trill is not lost, it is averaged into one long note at whichever of the two pitches happened to win the tie.

Where the line sits

The cut-off is a fixed number of milliseconds, so the rate depends on your sensitivity setting.

The gate is a duration, not a rate, which means the cut-off rate is the gate halved — plus one hop. A note is not measured from its own start: the analysis window reaches back 23.2 ms, so a half-cycle that lasts s milliseconds still produces a segment of roughly s + 7 ms, because the last frame that still reads the outgoing pitch is the one that starts just after the change. That much is the answer to why the measured line sits above 1000/(2 × gate) and not on it.

Last alternation rate at which 3 or more notes are still returned, 1.6 s runs, five harmonics, peak 0.5, one pair of pitches (C4↔D4). 0.25 Hz coarse scan to locate, then 0.05 Hz to fix the value. Reproduction: node run-trill-limit.js, sections 1–3.

SensitivityMinimum noteTrill survives toHalf-cycle thereOvershoot
More notes55 ms10.25 Hz48.8 ms+6.2 ms
Balanced75 ms7.40 Hz67.6 ms+7.4 ms
Fewer notes110 ms4.85 Hz103.1 ms+6.9 ms

The overshoot is 6.2, 7.4 and 6.9 ms at the three settings — one hop is 5.805 ms, so it is between 1.07 and 1.28 hops, and it does not scale with the gate. Put that constant back into the formula and the line predicts itself: 1000/(2 × (gate − 6.9)) gives 10.40, 7.34 and 4.85 Hz against measured 10.25, 7.40 and 4.85, a worst error of 0.15 Hz. The textbook form, 1000/(2 × gate) with no overshoot, gives 9.09, 6.67 and 4.55 — all three low by 11–13%.

So a real trill — and a real one on a violin or a flute usually sits between 6 and 12 alternations a second — straddles the line rather than sitting safely on one side. At Balanced, a 6 Hz trill is written as 19 notes and an 8 Hz trill is written as one. Switching to More notes moves the line to 10.25 Hz, which puts both of them on the working side, at the cost of double the note count on material that was already fine.

The starting pitch barely matters, with two exceptions worth recording. Scanning eleven starting notes from A2 (110 Hz) to C6 (1,046 Hz) at Balanced puts ten of them between 7.20 and 7.45 Hz, a spread of 0.25 Hz — five scan steps across two octaves of pitch. A2 is the low outlier at 5.75 Hz, 1.50 Hz below that median, because at 110 Hz the period search prefers a longer lag and the alternation collapses sooner. And G4 with G♯4 returns 2 notes at 4 Hz, where every other pair returns 13 — at that specific pair the two pitches support a shared lag of two periods, which collapses the alternation into a handful of long notes. It is the same mechanism as the octave result, showing up a fourth above middle C for no reason other than where the harmonics land.

What works

Slow the trill, raise the sensitivity, or accept that it is one note.

There is no setting that recovers a fast trill as two alternating pitches at Balanced, because the information is not lost to noise — it is lost to a gate that deletes every segment shorter than 75 ms. Three routes, in order of how much they cost.

Raise the sensitivity. More notes lowers the gate to 55 ms and moves the cut-off from 7.40 Hz to 10.25 Hz. That covers most of the musical trill range in one click, and it is the only option that does not require re-recording. The cost is real: at 8 Hz, Balanced returns 1 note and More notes returns 25 — and those 25 are correct, checked pitch by pitch against the played sequence at 25 of 25 with zero misplaced. So the extra notes are not false positives, they are the trill you played.

Play the trill slower than 7 Hz. Below the cut-off the detector tracks an alternation almost note for note: 4 Hz gives 13 notes for 13 half-cycles, and every pitch is right. A trill at 5 Hz is still recognisably a trill to a listener and converts cleanly at Balanced.

Convert the trill as a separate pass. Since the failure is a duration gate and nothing else, a take that is mostly sustained melody with two fast trills in it does not need the whole file at More notes. Convert once at Balanced for the melody, once at More notes for the passages with the trills, and splice. The melody pass will not gain spurious notes from the sensitivity change because its notes are already far longer than 55 ms.

Notes returned by the same 1.6 s C4↔D4 alternation at each sensitivity setting. Reproduction: node run-trill.js, section 3.

RateMore notesBalancedFewer notes
4 Hz131312
5 Hz16161
6 Hz19190
7 Hz2290
8 Hz2510
10 Hz200

Fewer notes is the mirror image, and it is worth knowing before you reach for it: it returns 1 note at 5 Hz, where Balanced returns 16. On trill material, moving the slider one step toward Fewer notes destroys the trill entirely, and it does so before it does anything useful to the rest of the take.

Above the cut-off

Past the limit it goes silent, then starts returning nonsense.

Above the cut-off the trill does not fade out. It goes quiet for a wide band and then comes back, and the band is the part nobody expects. Between 10.75 and 27.00 Hz at More notes — that is 66 consecutive steps of the 0.25 Hz scan — the converter returns nothing at all. From 27.25 Hz upward it returns notes again: 50 of the next 60 rates, averaging 4.8 notes each at More notes, 45 of 60 at Balanced, 40 of 60 at Fewer. Nothing about the audio changes at 27.25 Hz. What changes is how many half-cycles fit inside one 23.2 ms window.

Quarter-Hz scan from 8 to 42 Hz, same 1.6 s runs and same C4↔D4 pair. Reproduction: node run-trill-limit.js, section 4; the 8–22 Hz detail with per-rate segment lengths is node run-trill-upper.js, sections 1, 6 and 7.

SensitivitySilent fromBack atRates returning notes, 27.25–42 Hz
More notes10.75 Hz27.25 Hz50 of 60
Balanced8.25 Hz30.25 Hz45 of 60
Fewer notes8.00 Hz30.25 Hz40 of 60

What comes back is not the trill. At 43 Hz the window spans two whole half-cycles, so no single frame sits inside one note; the pitch readings scatter across 60, 61 and 62 and change every few frames. The segments that survive are mostly the ones whose starting frame reads 61 — the midpoint — because 60 and 62 are both within the one-semitone merge rule of 61, so the segment only breaks when a reading lands two semitones away. Shift the audio by half a millisecond and the whole pattern moves: across 20 shifts, 170 segments survive and 83% of them start on 61, none on 60. They are artefacts of where the frame grid lands, and they are the same ones you would get from noise with a pitch.

The control that makes this concrete: move the pre-silence by 1 ms, nine times, and the count at 20 Hz and 25 Hz stays at zero every time — the silent band is robust. At 33 Hz it reads 4, 5, 4, 5, 5, 3, 4, 4, 4 at Balanced, and at 40 Hz it reads 6, 7, 7, 6, 7, 7, 6, 6, 7. Stable in count, arbitrary in pitch. It is the clearest case in this whole set of a number that is reproducible without being meaningful: run the same file twice and you get the same 7 notes; change one thing you cannot hear and you get 4.

Limits

The limits of this test.

Every trill is synthesised and perfectly even. Five harmonics at 1/h, a 5 ms crossfade, an exact half-cycle split, 44.1 kHz mono. A played trill is not even: the two notes are rarely the same length, the fingers or the bow do not hand over on the beat, and there is usually a small gap or overlap at each change. An uneven trill will hit the gate differently on each half-cycle, so expect some segments to survive and others not, rather than the clean all-or-nothing this page measures.

The 5 ms crossfade is a choice, and it was tested. Re-running the same two rates with a 1 ms and a 20 ms crossfade gives 9 notes at 7 Hz in all three cases, and 1, 1 and 0 at 8 Hz — the only change is that a wider crossfade removes the single surviving note at 8 Hz. So the collapse itself does not depend on how the handover is smoothed, which matters because a real instrument's handover is not smooth at all; only the one leftover note does.

The envelope is flat, and that was checked against a decaying one. Every note holds at 0.5 for its whole half-cycle. Adding a 6 or 12 dB/s decay changes nothing at 6, 8 or 10 Hz at Balanced — the counts stay 19, 1 and 0. At 24 dB/s the 6 Hz count drops from 19 to 11 as the later half-cycles fall under the loudness threshold, which is a different gate doing the work. That is the point worth keeping: the cut-off this page measures is a duration gate, not a level gate, and a decaying note that lasts 63 ms is still 63 ms.

Two notes only, one interval at a time. Every measurement is a single pair trading places. Three-note ornaments, a trill that accelerates, and a trill over a sustained bass note are all untested here. The bass note would matter: a sustained low pitch under a fast alternation gives the period search a long lag to lock onto, which is the mechanism behind the octave result and could plausibly pull a two-semitone trill the same way.

The note count is not the only thing that changes. At 8 Hz with two semitones, the single surviving note is 75 ms; at 6 Hz the notes average 83 ms. So the surviving output is not the printed trill with some notes removed, it is a different rhythm. Anything timed against that MIDI will be timed against the gate.

The 25-note result at More notes was checked for accuracy, not just counted. Every one of the 25 pitches matched the played sequence in order, 25 of 25, with segment lengths between 58 and 75 ms. A count alone would not have shown that, and a count alone is not enough to recommend the setting.

Reproduction: node run-trill.js regenerates the rate sweep, the interval sweep, the three-sensitivity table and the frame dump and prints the detector's sha256 on its first line (77a9dd6b, 8,069 B). The mechanism probes are node probe-trill-frames.js (which first proves a line-by-line replica of the detector matches the real one on 105 input/sensitivity combinations, 105 of 105), node probe-trill-threshold.js, node probe-trill-edge.js, node probe-trill-final.js and node probe-trill-boundary.js. The cut-off section is node run-trill-limit.js; the 8 Hz and above band is node run-trill-upper.js (its own replica check runs before any of its numbers are reported, and it refuses to print a conclusion if the segment counts differ from the real detector by even one); the starting-pitch sweep is node run-trill-pitch.js. The detector is read directly out of the production converter.js by detector-from-live.js rather than re-implemented, so these numbers move if the shipped detector moves.

Questions

Trills and this converter

Why does a fast trill come out as one note or no notes?

Because a note has to survive a minimum-duration gate, and a trill's half-cycles are shorter than it. At Balanced the gate is 75 ms: a 6 Hz trill has 83 ms half-cycles and returns 19 notes, an 8 Hz trill has 63 ms half-cycles and returns one 75 ms note. The segments themselves are the right pitches — they are measured at 63 ms median and then discarded for being too short.

Where exactly is the cut-off?

At Balanced, 7.40 alternations a second is the last rate that still returns three or more notes. 1000 divided by twice the minimum note gives 6.67 Hz, so the measured line sits 0.73 Hz above the textbook figure. That gap is one analysis hop: a segment runs about 7 ms longer than its half-cycle, because the last frame reading the outgoing pitch starts just after the change. Feeding that constant back in — 1000/(2 × (75 − 7)) — gives 7.34 Hz against 7.40 measured.

Why does an octave trill behave differently?

Because the low note's period is twice the high note's, so a window that spans the handover supports both lags and picks the longer one while there is enough low content to back it. At 8 Hz an octave trill gives low-note segments of 81 ms and high-note segments of 41 ms: the 12 low ones pass the gate and the 13 high ones do not. The result is 13 notes that are all the low pitch — the trill's rhythm at half its rate with the second note deleted. Record it high-first and the same thing happens with the numbers swapped.

What about a semitone trill?

It never becomes two notes, at any rate. Two neighbouring pitches fall inside the detector's one-semitone merge rule, so a C4↔C♯4 trill comes out as one long note of 1,614 ms at 3 Hz and at 30 Hz alike. Which pitch gets printed flips with tiny changes in the frame counts: 60 at 3, 4 and 6 Hz, 61 at 5, 7, 8, 10, 15, 20 and 30 Hz.

Does raising the sensitivity fix it?

Yes, and it does not invent notes. More notes drops the gate to 55 ms and moves the cut-off to 10.25 Hz. At 8 Hz it returns 25 notes instead of 1, and all 25 pitches matched the played sequence in order. The cost is double the note count on material that was already converting fine, so convert the trill passages separately if the rest of the take is sustained.

Does the instrument or the pitch change the result?

Mostly not, with one clear outlier. Ten starting notes from E3 (165 Hz) to C6 (1,046 Hz) cut off between 7.20 and 7.45 Hz at Balanced — a spread of 0.25 Hz, which is five steps of the scan. Two octaves of pitch move the line by less than one scan step. A2 (110 Hz) is the exception at 5.75 Hz, 1.50 Hz early: at that pitch the period search prefers a longer lag and the alternation collapses sooner. Separate from that, G4 with G♯4 returns only 2 notes at 4 Hz where every other pair returns 13 — the same shared-lag mechanism that does the damage an octave apart, landing on one specific pair. The interval matters much more than the pitch, and only at an octave, in the direction described above.

My trill came out with the right number of notes but wrong pitches. Why?

Check whether the two pitches are a semitone apart. If they are, the merge rule is combining them and the printed pitch is whichever won the frame-count tie, which is unstable: on the same input, 4 Hz prints 60 and 5 Hz prints 61. Nothing in the audio changed enough to explain that. Widen the interval or accept the merged note.

Does a trill at 20 Hz or faster still work?

Not at 20 or 25 Hz — every setting returns zero. But it is not a clean ceiling: from about 27 Hz upward notes reappear, and at 33 Hz Balanced returns four or five per run. They are not the trill. Once a half-cycle is shorter than the 23.2 ms window, no frame sits inside a single pitch, so the readings land on 60, 61 or 62 almost at random. A segment only survives if its first frame reads the midpoint, 61, because 60 and 62 both fall inside the one-semitone merge rule; across 20 half-millisecond shifts of the same audio, 83% of the surviving segments start on 61. Never trust a note count from an alternation faster than about 20 Hz.

Related readings

Short notes that never arrive covers the same 75 ms gate from the other direction — one note played once, too short to survive — and is the right page if your problem is a single staccato note rather than an alternation. The chords page measures what happens when two pitches sound at the same time instead of in turn, which is where the period search has to choose between them within a single window. The accuracy page covers the one-semitone merge rule in the context of a chromatic scale, where it costs you half the notes of a twelve-note run. For material where the alternation is deliberate and the rhythm is what you want, the drum workflow approaches onset detection from a different angle entirely.