Slow attacks
Audio to MIDI and slow attacks: the note starts late, by a number you can calculate.
A slow attack makes every note land late. On one 220 Hz tone: 11 ms early at a 5 ms attack, 0.5 ms at 150 ms, 88 ms late at 1.4 s. Pitch never moved — the shift is set by the attack alone.
The selected audio is decoded in your browser; it is not uploaded to a server.
The converter stamps a note at the first analysis window whose loudness clears a threshold, not at the attack; on a slow attack that window arrives late, so every note in the take shifts later. This is the timing error that the existing timing page does not cover, and in one respect contradicts it. That page measures a lead — notes stamped before the attack — and concludes that sustained material does not care, because 20 ms is inaudible against an attack that takes 300 ms to develop. Both halves of that are wrong for a slow attack, and the second one is wrong in the direction that matters: a slow attack is exactly the case where the error grows large. At 1.4 s of attack the stamp lands 88 ms after the attack, not before it.
Nothing here is a bug report. A threshold on a frame of audio has to be crossed somewhere, and on a gradual onset it is crossed late. The point is that the delay is not random and not a constant you could nudge away. It is a function of the attack, computable in advance, and it moves every note in the take by the same amount.
Measured
One tone, one peak level, one variable: how long the attack takes.
The signal is a 220 Hz tone (A3, MIDI 57) built from five harmonics at 1/h amplitude, 1.2 seconds long, 44.1 kHz mono, peak-normalised to 0.5 (−6 dBFS), with 0.40 s of digital silence in front of it. The only thing that changes down the table is how long that silence takes to ramp up to full level. Pitch, peak level, harmonic count, note length and sensitivity are identical in every row.
The error is the stamped start minus the true onset, in milliseconds. Negative means the note was written before it was played; positive means after.
One 1.2 s tone per row, 5 harmonics at 1/h, 44.1 kHz mono, peak 0.5, 0.40 s of silence in front. Note sensitivity Balanced. Detector 77a9dd6b. Reproduction: node run-attack.js, section 1.
| Attack | Stamped start error | In hops (5.805 ms) | Written duration |
|---|---|---|---|
| 0 ms (instant) | −16.9 ms | −2.91 | 1,213 ms |
| 5 ms | −11.1 ms | −1.91 | 1,207 ms |
| 40 ms | −11.1 ms | −1.91 | 1,207 ms |
| 60 ms | −11.1 ms | −1.91 | 1,207 ms |
| 100 ms | −5.3 ms | −0.91 | 1,202 ms |
| 130 ms | +0.5 ms | +0.09 | 1,196 ms |
| 200 ms | +0.5 ms | +0.09 | 1,196 ms |
| 250 ms | +6.3 ms | +1.09 | 1,190 ms |
| 300 ms | +12.2 ms | +2.09 | 1,184 ms |
| 500 ms | +23.8 ms | +4.09 | 1,173 ms |
| 700 ms | +41.2 ms | +7.09 | 1,155 ms |
| 1,000 ms | +58.6 ms | +10.09 | 1,138 ms |
| 1,400 ms | +87.6 ms | +15.09 | 1,109 ms |
Two things in that table are worth more than the rest. First, there is a crossing point: on this one tone, at 130 ms of attack the error is zero, and below it every row is early while above it every row is late. The cross-pitch table further down shows that crossing is not the same for every note, so treat 130 ms as this signal's value rather than a general one. Second, look at the hop column. The error is not a smooth function of the attack — it is quantised in steps of one hop, 5.805 ms, because a note can only be stamped at the start of a frame. The underlying delay is continuous; the written result can only land on the grid.
The written duration falls as the attack lengthens, and by a smaller amount than the start error grows. A note that starts 88 ms late ends 111 ms earlier than the 5 ms case, so the note is shortened by 98 ms in total. Slow attacks do not just move the note; they eat into it from both ends.
Mechanism
The threshold is crossed late, and the first crossing reads as the wrong pitch.
The detector works in overlapping windows: 1,024 samples advanced 256 samples at a time, which at 44.1 kHz is a 23.2 ms window every 5.8 ms. Each window is judged as a whole. If its loudness clears the threshold — 0.015 at Balanced — the window is analysed for pitch; if not, it is recorded as silence. A note is then a run of consecutive windows on the same pitch, and it is stamped with the start of the first window in the run.
On a fast attack that first window arrives before the note does, because a window that opens in the silence still contains a few milliseconds of the note by the time it closes. That is the lead measured on the timing page, and it is why the fast rows above are negative. On a slow attack the same window contains almost nothing, stays under the threshold, and the first qualifying window arrives well after the attack. That is the late side.
Here is the frame sequence for the two ends of the table. Both are 220 Hz. Left to right: where the window starts relative to the true attack, the window's loudness, whether it cleared the threshold, and the pitch it produced.
Frame-by-frame dump, Balanced, threshold 0.015. Steady-state loudness of this signal is 0.21392. Reproduction: node run-attack.js, section 2.
| Window start | Loudness | Over threshold | Pitch |
|---|---|---|---|
| Attack 5 ms — fast | |||
| −22.68 ms | 0.00313 | no | — |
| −16.87 ms | 0.08438 | yes | MIDI 89 |
| −11.07 ms | 0.12767 | yes | MIDI 57 |
| −5.26 ms | 0.17021 | yes | MIDI 57 |
| Attack 300 ms — slow | |||
| −11.07 ms | 0.00327 | no | — |
| −5.26 ms | 0.00649 | no | — |
| +0.54 ms | 0.01035 | no | — |
| +6.35 ms | 0.01361 | no | — |
| +12.15 ms | 0.01703 | yes | MIDI 57 |
| +17.96 ms | 0.02158 | yes | MIDI 57 |
Now the part that is easy to miss. On the fast attack, the first window to clear the threshold is stamped MIDI 89, not 57. The signal has been audible for a few milliseconds and has no stable period yet, so the period search falls to the shortest delay it is allowed to test — 31 samples, which is 1,422.6 Hz. That window is the only one that reads 89; the next window already reads 57. A single window is 5.8 ms, and the shortest note the tool will keep at Balanced is 75 ms, so the 89 is discarded and the note begins at the second window instead. That is where the −11.1 ms comes from: not from the attack being early, but from a one-window wrong reading being thrown away, which pushes the reported start one hop later than the threshold crossing.
On the slow attack there is no 89 at all. By the time the level is high enough to clear the threshold, the waveform is already periodic, so the first surviving window reads 57 directly. The note begins 12.15 ms after the attack, and every hop after that is 57 as well.
Predictable
The late shift is not just repeatable, it can be calculated before you convert.
A measurement that only says "slow attacks arrive late" is not much use. The useful question is whether you can work out how late, for a given attack, without running the converter. For a linear ramp the answer is yes, and the arithmetic is short enough to do on paper.
Inside a linear ramp, the amplitude at a point u of the way through the attack is u times full scale. A window that starts at u and is f of the attack long covers the amplitudes from u to u+f, and its root-mean-square works out to the full-scale RMS times the square root of (3u² + 3uf + f²)/3. Set that equal to the threshold, solve the quadratic for u, and multiply by the attack length. That gives the time at which the first window clears the threshold.
The prediction and the measurement, at all three sensitivity settings:
Predicted first threshold-crossing window from the ramp formula, versus the window the detector actually used. Difference in milliseconds, and the same difference in hops. Full-scale window RMS measured at 0.21574. Reproduction: node probe-attack-model.js.
| Attack | Predicted | Measured | Difference | In hops |
|---|---|---|---|---|
| More notes — threshold 0.009 | ||||
| 200 ms | −6.64 ms | −5.26 ms | 1.38 ms | 0.24 |
| 400 ms | +3.67 ms | +6.35 ms | 2.68 ms | 0.46 |
| 700 ms | +16.81 ms | +17.96 ms | 1.15 ms | 0.20 |
| 1,400 ms | +46.41 ms | +52.79 ms | 6.38 ms | 1.10 |
| Balanced — threshold 0.015 | ||||
| 200 ms | +0.57 ms | +0.54 ms | −0.03 ms | −0.01 |
| 400 ms | +15.38 ms | +17.96 ms | 2.58 ms | 0.44 |
| 700 ms | +36.60 ms | +41.18 ms | 4.58 ms | 0.79 |
| 1,400 ms | +85.50 ms | +87.62 ms | 2.12 ms | 0.37 |
| Fewer notes — threshold 0.023 | ||||
| 200 ms | +8.63 ms | +12.15 ms | 3.52 ms | 0.61 |
| 400 ms | +30.50 ms | +35.37 ms | 4.87 ms | 0.84 |
| 700 ms | +62.72 ms | +64.40 ms | 1.68 ms | 0.29 |
| 1,400 ms | +137.49 ms | +139.86 ms | 2.37 ms | 0.41 |
Every row lands within about one hop of the prediction, which is the resolution of the grid it has to land on. That is what makes this usable: for a linear fade-in, you can predict the shift from the attack length and the threshold alone, without touching the converter. What you cannot do is predict the reported start from the formula alone on a fast attack — at 5 ms the threshold is crossed at −16.9 ms but the note is written at −11.1 ms, one hop later, because the crossing window read 89 and was discarded. Below roughly 150 ms of attack, add one hop to the prediction.
Not a pitch problem
The shift is the same at every pitch, and this is where it differs from every other failure on this site.
Almost every other error measured here depends on the pitch. The low-note page's band sits at 95 to 116 Hz. The bass page's collapse is at the bottom of the range. The piano page's failures are at the two ends of the keyboard. Timing, it turns out, is not like that: it depends on the attack and not on the note.
Same signal, same 5-harmonic recipe, same peak, 1.4 s tone. Rows are pitches, columns are attack lengths, cells are the stamped start error in milliseconds. Balanced. Reproduction: node run-attack.js and the cross-pitch probe.
| Played | 5 ms | 130 ms | 150 ms | 300 ms | 700 ms | 1,400 ms |
|---|---|---|---|---|---|---|
| E3 · 164.8 Hz | −5.3 | −5.3 | +0.5 | +12.2 | +41.2 | +87.6 |
| A3 · 220 Hz | −11.1 | +0.5 | +0.5 | +12.2 | +41.2 | +87.6 |
| E4 · 329.6 Hz | −16.9 | +0.5 | +0.5 | +12.2 | +41.2 | +87.6 |
| A4 · 440 Hz | −16.9 | +0.5 | +0.5 | +12.2 | +41.2 | +87.6 |
| E5 · 659.3 Hz | −16.9 | +0.5 | +0.5 | +12.2 | +41.2 | +87.6 |
Read down a column. From 150 ms of attack upward every pitch gives the identical number, to a tenth of a millisecond. The shift is a property of the envelope alone. Read across a row at the short attacks and there is a small pitch dependence, and it has two causes. One is the discarded MIDI 89: how many windows it survives depends on how quickly the waveform becomes periodic at that frequency, and a lower note needs longer to establish a period, so its 89 survives one window longer and its note is stamped one hop earlier. That is why the 5 ms column runs from −5.3 ms at E3 to −16.9 ms at E4 and above. The other is the crossing point itself: at 130 ms, A3 and above have just crossed to +0.5 ms while E3 is still a hop short at −5.3 ms, so 130 ms is not yet the safe attack for the lowest note in this set. By 150 ms it is.
The practical consequence is that you can fix it with one number. A take recorded with a 300 ms attack, converted at Balanced, comes out 12.2 ms late on every note from 164 Hz to 659 Hz. Shift the whole MIDI track 12 ms earlier and it is aligned. That is the opposite of the timing page's conclusion that no global nudge can work, and the difference is the source of the error: frame quantisation on a sharp attack varies from note to note, while a slow attack applies the same offset to all of them.
What works
Either shorten the attack before converting, or compute the shift and apply it once.
Two routes, and they trade off differently.
Shorten the attack in the audio. Trimming a fade-in is the only edit that changes the number. Going from 300 ms to 5 ms takes the error from +12.2 ms to −11.1 ms, which is not automatically better — it swaps a late note for an early one and adds a discarded-window artefact. Going to about 150 ms is the actual optimum for this signal, where the error is +0.5 ms across the pitches tested, but that value is specific to this threshold crossing and should not be carried to another recording without re-measuring. What shortening the attack does not do is remove the problem; it moves the crossing point.
Convert first, then shift the track. Because the shift is constant across pitches from 150 ms of attack upward, one nudge fixes the whole take. This is the cheaper route and it preserves the performance's dynamics, which trimming a fade-in does not. Use the sensitivity you converted at — the three settings give different numbers, and a track nudged by the Balanced figure will be wrong by 23 ms at Fewer notes.
Stamped start error in milliseconds for the same 220 Hz tone at each of the three sensitivity settings. Reproduction: node run-attack.js, section 5.
| Attack | More notes | Balanced | Fewer notes |
|---|---|---|---|
| 5 ms | −11.1 ms | −11.1 ms | −11.1 ms |
| 150 ms | −5.3 ms | +0.5 ms | +6.3 ms |
| 300 ms | +0.5 ms | +12.2 ms | +23.8 ms |
At a 5 ms attack all three settings print the same −11.1 ms, which is worth understanding rather than filing away: the note is not being stamped by the threshold at all in that case, it is being stamped one window after a discarded 89, and the threshold only decides whether that 89 window qualifies. Once the attack is slow enough that no 89 appears, the threshold is doing the work and the three settings diverge, by roughly 11.8 ms per sensitivity step at 300 ms of attack.
One case that neither route fixes: an attack so slow that the ramp never gets loud enough before the note ends. That is not a timing error, it is a note that never qualifies, and it belongs with the short-note failures rather than here.
Limits
The limits of this test.
Every signal is synthesised. Five harmonics at 1/h, a linear fade-in, 44.1 kHz mono, one channel, 0.40 s of digital silence in front. No real bowed string, no pad, no breath was recorded. A real slow attack is not linear — it curves, it has noise on it, and its harmonics do not all arrive together. The mechanism (a threshold crossed late on a gradual onset) generalises; the exact millisecond values belong to this waveform.
The attack is linear, not exponential. The calculation in the predictable section assumes a straight ramp, and it is only as good as that assumption. An exponential fade-in crosses the threshold at a different point for the same nominal duration. Re-run probe-attack-model.js with your own envelope before carrying the numbers over.
One note at a time, one peak level. Peak was 0.5 (−6 dBFS) in every row. A quieter take crosses the threshold later, so its shift is longer; a louder one crosses earlier. The relationship is not linear, because the threshold is fixed and the ramp is not, so these numbers do not scale with level. Nothing here covers two notes sounding at once, or a slow attack under a melody.
The zero crossing is signal-specific. 130 ms is where this particular tone, at this peak level, at this threshold, happens to cross — and the cross-pitch table shows it is not even the same for every note: at 130 ms, E3 is still 5.3 ms early while A3 and above sit at +0.5 ms. Re-measure before quoting any number from the main table as a target, and do not read "130 ms is the safe attack" off a single note.
Duration shortening was not separated from start delay. The written duration falls from 1,207 ms to 1,109 ms across the table, but the note's true length is 1.2 s throughout and the frame grid explains both ends. This page does not model the end-of-note behaviour beyond noting that it moves; the missing-notes page covers duration gates separately.
One sensitivity level was swept, three were spot-checked. The full 32-row sweep is at Balanced. More notes and Fewer notes were run at three attack lengths only, which is enough to show they differ but not enough to claim a curve.
Reproduction: node run-attack.js regenerates sections 1, 2, 3, 4 and 5 in full and prints the detector's sha256 on its first line (77a9dd6b, 8,069 B), writing a log to localmidi-private/logs/attack-2026-11-23.txt. The ramp formula check is node probe-attack-model.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
Slow attacks and this converter
Why are my converted notes late when the recording is in time?
Because the converter stamps a note at the first analysis window loud enough to clear a threshold, and on a slow attack that window arrives after the note began. Measured on a 220 Hz tone: 12.2 ms late at a 300 ms attack, 87.6 ms late at 1.4 s. The performance is not late; the stamp is.
Is this a constant offset I can just nudge away?
From 150 ms of attack upward, yes — the shift was identical to a tenth of a millisecond across five pitches from 164 Hz to 659 Hz. Below that it varies, for two reasons: a discarded one-window pitch reading moves the start by a hop, and the lowest notes cross the zero point at a longer attack than the higher ones (at 130 ms, E3 is still 5.3 ms early while A3 and above are already at +0.5 ms). This is the opposite of the timing page's frame-quantisation error, which varies from note to note on a sharp attack.
Can I predict how late it will be?
For a linear fade-in, yes. Set the ramp's window RMS equal to the threshold, solve for the point in the attack where that happens, and multiply by the attack length. Every row checked landed within about one hop of the prediction. Below roughly 150 ms of attack, add one hop, because the crossing window reads MIDI 89 and is discarded.
Does the note sensitivity setting change the shift?
Yes, once the attack is slow enough that no MIDI 89 appears. At a 300 ms attack the three settings give +0.5, +12.2 and +23.8 ms — about 11.8 ms per step. At a 5 ms attack all three give −11.1 ms, because the start is being set by a discarded window rather than by the threshold.
Should I trim the fade-in before converting?
It moves the crossing point rather than removing the problem. Going from 300 ms to 5 ms takes the error from +12.2 ms to −11.1 ms, which is not obviously better. The cheapest correct route is to convert as recorded and shift the MIDI track once, using the sensitivity you actually converted at.
Does this affect pitch?
No. Every row in the main table returned MIDI 57. One window at the very start of a fast attack reads MIDI 89, but it is 5.8 ms long against a 75 ms minimum and is discarded, so it never reaches the output — it only shifts where the surviving note is stamped.
Does a slow attack make notes shorter too?
Yes, at both ends. A 1.2 s note written from a 1.4 s attack comes out 1,109 ms long against 1,207 ms for a 5 ms attack — 98 ms shorter, with the start 88 ms later and the end 10 ms earlier.
Related readings
Other failures with a measured cause.
The timing drift page measures the opposite sign of this error — notes stamped before the attack, varying from note to note on a sharp onset — and is the right place to start if your material is percussive. Short notes that never arrive covers the duration gate this page's error interacts with, and the low-note band covers the pitch-dependent failures that this timing error is not. For material where the attack is the whole point rather than an accident, the drum workflow takes a different approach to onset detection entirely.