T-042 — Hammer contact at the onset: spread each strike over the contact time instead of an impulse, so notes stop clicking
Status: done — D1–D6 accepted (maintainer, Dec 2026); Julia and Rust parts done; the maintainer listened to the demos: the click is gone, the sound is right (Dec 2026) · Area: julia, rust, piano · Depends on: T-007, T-008, T-009
Read for that: Piano 05 (contact time, the pulse as a low-pass, precomputed excitation), Piano model file (v1: excitation, validation, the format-version rule), T-007 (H1’s impulse; the onset gate is not in the reference; the attack-level check), T-008 (Outcome: CoeffSet, Bank, the kernel), T-040 (refreshing the demos), training/src/ReferencePiano.jl (render_events, advance!), crates/dsp/src/piano/{engine,resonator,coeffs}.rs.
Why: the maintainer’s listening to the demo renders: the piano sounds like a piano, but every note starts with a click. Cause: format v1’s excitation is an impulse (T-007 H1). A note-on adds each mode’s full amplitude to its state at one sample, so the output jumps from silence to almost the note’s peak in a single sample. Measured for this page with the engine and the committed model (2026-12-01-r2), at velocities 0.3, 0.6 and 1.0:
| key | first sample, % of the note’s peak | that jump compared with the largest sample-to-sample step after 1 ms |
|---|---|---|
| A0 | 44–49 % | 10–14× |
| C3 | 8–25 % | 2–4× |
| C4 | 88–91 % | 7–16× |
| A4 | 98–99 % | 8–17× |
| C5 | 69–92 % | 3–8× |
| C7, C8 | 48–62 % | 1.3–2× |
The recordings do not do this: T-036’s fits of C4 v8 have an attack rise time of τ = 0.2–0.7 ms per mic, and T-007 lists 0.002–8 ms over the samples. A real hammer stays on the string for 1–4 ms (Piano 05), so the string is driven over that time, not at one instant. This task makes the excitation a contact pulse: the step toward Piano 13’s precomputed hammer pulses, built on the measured excitation of format v1.
The catch: the fitted excitation already holds the hammer’s low-pass
A pulse of duration filters the impulse: a raised-cosine (Hann) pulse is, relative to its level at 0 Hz:
| pulse | 250 Hz | 500 Hz | 1 kHz | 2 kHz | 4 kHz |
|---|---|---|---|---|---|
| Hann 0.5 ms | −0.1 | −0.4 | −1.4 | −6.1 | −61 dB |
| Hann 1 ms | −0.4 | −1.4 | −6.0 | −67 | −81 dB |
| Hann 2 ms | −1.4 | −6.0 | −73 | −87 | −100 dB |
The model’s excitation and gains were fitted to the recordings’ partial amplitudes, which already contain the real hammer’s filtering (and its velocity-dependent brightness, through the four layers). Feeding the fitted modes a physical pulse filters them a second time: with 2 ms, everything above 1 kHz would be gone. Dividing the excitation by the pulse’s response cannot undo it (−70 dB and spectral zeros). D1 resolves this by letting the pulse shape when each mode gets its energy, not how much.
What
- Mechanism (D1, D2, D5): a note-on no longer adds to a mode’s state at once. It adds it to a pending state that rings with the mode’s own coefficient; for the samples of contact, the mode takes the share of the pending state each sample, with the running integral of a Hann pulse. Each mode’s amplitude therefore rises smoothly as (10–90 % in ) and, at the end of contact, holds exactly the amplitude and phase it holds today. After contact the output equals today’s sample for sample; during contact it is today’s output scaled by , mode by mode.
- Contact time (D3): per key and velocity layer, measured from the recordings’ onset rise and smoothed into a law.
- Model file (D4): format v2 = v1 +
[excitation] kind = "hann_contact"+ the tablekey.contact_s[V, K]. Julia writes it, Rust reads it; a new model directory. - Julia reference:
render_eventsandadvance!implement the pending state and the contact; the golden vectors are rendered again with events that exercise the contact (D6). - Rust engine:
PianoEngineimplements the same (D5); the plugin compiles in the new model. - Pages: Piano model file (v2), Piano 13 (what exists), T-007 gets a pointer here; demo renders refreshed (T-040).
Decisions (accepted as proposed)
| Question | Options | Proposal | |
|---|---|---|---|
| D1 | What the pulse does to the spectrum | (a) a physical pulse on top of the fitted excitation (each mode driven by the pulse): filters the fitted tone a second time (table above: Hann 2 ms takes 1 kHz down by 73 dB); (b) (a) with the excitation divided by the pulse’s response at each mode’s frequency, so the level after contact is the fit’s: impossible past the pulse’s first zero (−60…−100 dB to undo), and modes near a zero would swing wildly during contact; (c) per-mode rise: each mode’s amplitude follows the pulse’s running integral and reaches its fitted amplitude and phase at the end of contact; the spectrum after contact is today’s, the velocity-dependent brightness stays in the measured layers | (c): it removes the step without touching the fitted tone, and it is exact (a closed form to test against). The hammer’s spectral shaping as a mechanism (felt stiffness, strike position) needs an excitation that is no longer measured per partial: T-035 and the coupled hammer of T-010, which then replace (c) |
| D2 | Pulse shape | (a) Hann (raised cosine): force and its slope are zero at both ends, so the amplitude envelope has no corner; closed form, no tables; (b) half-sine (Piano 05’s usual sketch): the envelope , a corner in the force at both ends; (c) simulated felt pulses () as tables per key and velocity | (a): the smoothest envelope at the same rise time, and nothing to store or resample. Under (c) the pulse’s shape only changes the first millisecond’s envelope (D1), which does not justify tables; (c) belongs to the coupled hammer |
| D3 | Contact time per key and velocity | (a) measured: per Salamander sample (119) and mic, fit the onset rise of the broadband envelope (as T-036’s τ: the 10–90 % time of an envelope following the onset), take , average the two mics, smooth over the keys per layer (as T-037’s curves), clamp to 0.3–5 ms; layers between and below as the excitation (linear in velocity between layers, held outside); (b) literature law: 4 ms at A0 to 1 ms at C8 (log-linear over the keys), ×1.3 at v4 to ×0.8 at v16; (c) one value for every note (1 ms) | (a), with (b) as the fallback for any key where the fit is unreliable (rise below 2 samples or above 10 ms); the one data point at hand (C4 v8: τ 0.2–0.7 ms → ≈ 1 ms) is within (b)‘s range. Check: the reference’s rise time against each recording’s, median within 30 % per register |
| D4 | Where lives | (a) in the model file: format v2 = v1 + [excitation] kind = "hann_contact" + key.contact_s [V, K] f32 (positive, ≤ 10 ms); Rust reads v2 only, as the page’s rule says (one supported version), and the committed model is rebuilt as models/piano/salamander-c5/<date>/ with MODEL_VERSION bumped; (b) as constants of the engine and the reference (the model file unchanged) | (a): is fitted from the recordings, so it is model data, and Julia and Rust must agree on it through the file, not through two copies of a law |
| D5 | How the engine runs the contact | (a) pending state: a second complex state per mode, ur/ui in the Bank, advanced with the same coefficient (free or damped) as ; per key a contact counter and length; keys in contact go through an attack variant of the pulp kernel (two states per mode, the share per sample computed once per sample per key: one sin), all other keys through today’s kernel unchanged; a re-strike during contact adds to and restarts the counter (the first strike’s remainder follows the new pulse; no step); a release during contact uses the damped coefficient for both states; the activity bound includes ; (b) as (a), but keys in contact run the scalar reference loop (simpler; slower for chords) | (a), with the scalar version as the test oracle, as T-008 did. Cost: about 2× per mode, for 1–5 ms per strike; the chord benchmark below decides whether that matters |
| D6 | Golden vectors and the order of work | (a) Julia first: reference, fit, model v2 and golden vectors (the existing event list plus a re-strike inside the contact and a release during the contact), then Rust against them; tolerance unchanged (1e-4 of the peak at block sizes 1, 64, 513); (b) Rust first with constants, Julia after | (a): the golden vectors stay the contract between the two; Rust never defines what the piano sounds like |
Julia part (done)
Code. ReferencePiano (training/src/ReferencePiano.jl): PianoTables.contact [V, K], with_contact, contact_s(T, key, vel), hann_rise (), contact_share(k, L) (); KeyState holds the pending state ur/ui, the contact step and length; advance! and render_events run the contact (a contact of 0 is v1’s impulse); piano_tensors/piano_manifest write format v2. PianoModelFile accepts v2 only (key.contact_s in (0, 10 ms], excitation.kind = "hann_contact"). The exact recurrence is on the Piano model file page, so Rust can follow it. golden_events gains four events: C5 struck again 40 samples into its contact, D3 released 30 samples into its contact with the pedal up (23 events). Model models/piano/salamander-c5/2026-12-02/ (t007_reference_piano.jl build, MODEL_VERSION); Rust reads it since the Rust part.
Tests (training/test/referencepiano.jl, hammer contact; pianomodelfile.jl): the shares reproduce to 1e-12 for fractional and whole ; a single strike at three keys and two rates equals the impulse’s output times (1e-12 of the peak), silent at the note-on, identical after the contact; a re-strike inside the contact equals its closed form (the first strike’s remainder follows the new pulse); a release during contact has no step larger than the held note’s after contact; v1, the impulse kind, and a missing, misshapen, zero, too long or NaN key.contact_s are refused.
D3: the recordings do not resolve the contact. t042_contact.jl measure (training/results/salamander/t042_rise.csv): the 10–90 % rise of the recordings’ broadband envelope is 2–23 ms (the whole radiated sound builds up after the hammer has left), so the measure became the 10→50 % rise of the envelope high-passed at 500 Hz, matched through the same analysis on the reference (the contact at which the reference’s rise equals the recording’s):
| keys | 10→50 % rise of the recording (ms, median) | contact that matches it (ms): median [q25, q75] (reached / measured) | ratio of the two mics’ contacts (median) |
|---|---|---|---|
| A0–B1 | 10.0 | 0.5 [0.4, 1.2] (3 / 38) | — |
| C2–F#3 | 4.4 | 5.1 [1.6, 7.6] (33 / 56) | 2.2 |
| A3–F#5 | 3.5 | 1.9 [1.2, 2.8] (30 / 64) | 3.0 |
| A5–F#6 | 0.9 | 2.8 [1.5, 3.5] (31 / 32) | 2.2 |
| A6–C8 | 1.6 | 3.2 [2.1, 4.4] (30 / 48) | 2.0 |
The two mics of one sample disagree by a factor of 2–3 (F#3: 1.6 ms on one, 9.4 ms on the other, in every layer), the bass’s build-up (~10 ms) is longer than any contact reaches, and no velocity trend shows. What the mics record at the onset is the soundboard’s and the room’s build-up, not the hammer; every key is “unreliable” by D3’s rule, so D3 (b) applies to all keys: 4 ms at A0 to 1 ms at C8 (log-linear over the keys), ×1.3 at the quietest layer to ×0.8 at the loudest (log-linear in velocity), clamped to 0.3–5 ms (contact_law in t007_reference_piano.jl; 0.8–5.0 ms over the table). D3’s check (rise within 30 % of the recordings’) is replaced by the onset check below. The middle and treble medians (2–3 ms) suggest the treble’s contact may be longer than the law’s 1 ms; that is for the listening test, and for T-035/T-010, which model the hammer.
Check (t042_contact.jl check, t042_check.csv; 119 samples, each at its key and layer velocity):
| keys | contact (ms) | first sample, share of the note’s peak: impulse / contact (median [max]) | largest step from silence to the end of contact ÷ largest after it: impulse / contact / recording (median) | attack level shift, contact − impulse (dB) |
|---|---|---|---|---|
| A0–B1 | 2.6–5.0 | 49 % [70] / 0 % | 11.1 / 0.48 / 0.12 | 0.00 |
| C2–F#3 | 1.9–4.1 | 63 % [85] / 0 % | 8.3 / 0.64 / 0.09 | 0.00 |
| A3–F#5 | 1.3–2.9 | 68 % [99] / 0 % | 6.4 / 0.72 / 0.01 | 0.00 |
| A5–F#6 | 1.1–2.0 | 72 % [96] / 0 % | 3.6 / 0.79 / 0.01 | 0.00 |
| A6–C8 | 0.8–1.7 | 53 % [95] / 0 % | 1.7 / 0.94 / 0.00 | 0.00 |
The step at the onset (the click) falls below the note’s own later steps in the median of every register; 5 of the 119 samples stay just above (1.01–1.11, C4 at the loudest layer the most): there the contact ends at the attack’s peak, where the steps are largest, and the rise adds its own slope; T-007’s attack level (each partial’s peak in the first 0.5 s) does not move (|shift| < 0.005 dB), so the attack-level table of T-007 stands. The golden output of 2026-12-02 equals 2026-12-01-r2’s exactly from the end of each contact on. The recordings start more gently still (ratio 0.00–0.12): their attack builds up over several ms at the mics.
Rust part (done)
Code. Reader (crates/model-format/src/piano.rs): PianoModelV2 (renamed from PianoModelV1), FORMAT_VERSION = 2, EXCITATION_KIND = "hann_contact", key.contact_s [V, K] with contact_s(), checked finite and in (0, MAX_CONTACT_S = 10 ms]; v1 is refused (“format_version must be 2”). Tests crates/model-format/tests/piano_v2.rs: the fixture is v2; seven more broken models (version 1, impulse kind, missing, misshapen, zero, too long, NaN contact); the committed model’s contact table and its 23 golden events.
Engine (crates/dsp/src/piano/): contact.rs holds (hann_rise), (share), the number of steps and shares(first, len, out) (per key per sample in f64, one sin per sample: the previous step’s is carried); the Bank gains the pending state ur/ui; KeyState the contact step, steps and length (PianoModel::contact_s: linear in velocity between the layers, held outside). A note-on adds to ur and restarts the contact. render_chunk runs keys in contact through resonator::process_attack (pulp, KA = 2 vectors per group: 1 and 4 measured 21 % and 13 % slower) with that block’s shares, the rest through the unchanged kernel; when a key’s contact ends its pending state is zeroed. The activity bound includes ; choke, AllNotesOff and deactivation clear both states. process_attack_scalar is the oracle.
Tests. Golden vectors at block sizes 1, 64, 513: max error 3.7e-5 / 4.75e-5 of the peak (tolerance 1e-4; the same margin as before). attack_kernel_matches_the_scalar_reference (spans of 1, 3, 5 vectors, free and damped, a contact ending inside a block: outputs within 2e-5, nothing pending after it); contact.rs’s tests (the shares reproduce to 1e-12; block shares equal single shares). Onset test notes_start_without_a_click over A0, C3, C4, A4, C5, C7, C8 at velocities 0.3, 0.6, 1.0, rendered with allocation forbidden: the first sample is at most 0.01 % of the note’s peak (criterion 1 %); the largest step from silence to the end of the contact ÷ the largest after it (to 300 ms) is 0.38–1.11, ≤ 1 in 19 of 21 — C4 and C8 at velocity 1.0 give 1.108 and 1.012, as the Julia reference does (Check above). So the test bounds that ratio at 1.25, not 1 as Done when first said: a smooth onset that ends at the attack’s peak lands near 1, the impulse gave 1.7–11 below C7. (Accepted with the listening test.) The plugin’s no_alloc test and every engine test now play through the contact.
Benchmark (cargo run -p instruments-dsp --release --example chord_attack; cloud VM, Xeon 2.1 GHz with AVX-512, 4 vCPU; 7904 modes): a 10-note chord (C2–C6, velocity 0.8), median of 2000 runs, 256 samples at 48 kHz:
| µs | % of real time | |
|---|---|---|
| first 5 ms (keys in contact 0.9–2.9 ms of it) | 76.4 | 1.43 % |
| 5 ms of the same chord after the contact (today’s kernel) | 37.3 | 0.70 % |
2.05× for the first 5 ms of a chord, as D5 estimated (about 2× per mode); negligible against the budget.
Plugin and demos: the plugin compiles in 2026-12-02 (crates/piano/src/model.rs); bundle and clap-validator 35 passed, 0 failed, 9 skipped. 2026-12-01-r2/ is deleted (one model in the tree, as T-039 H5). Demo renders refreshed (demos/CHANGES.md) and published to listening (the previous renders, with the click, are in demos/previous/ for an A/B).
Done when
Tests first.
- Julia: for one mode struck once, the reference’s output equals times the impulse response during contact and equals the impulse response exactly after it (closed form,
Float64); a re-strike inside contact and a release during contact are continuous (no sample-to-sample step larger than the note’s largest step after the contact); T-007’s attack-level table (each partial’s peak in the first 0.5 s, model − recording) moves by less than 0.5 dB in every register; the rise times match per D3.Pkg.test()green. - Model file: v2 written and read; validation covers
key.contact_s(shape, finite, 0 < ≤ 10 ms) andexcitation.kind; a v1 file is rejected with a message naming the version. - Rust: the golden test passes at block sizes 1, 64, 513; an onset test over A0, C3, C4, A4, C5, C7, C8 at velocities 0.3, 0.6, 1.0: the first sample is below 1 % of the note’s peak, and no sample-to-sample step in the first exceeds the largest step after it (the test allows 1.25×, see Rust part); the SIMD attack kernel equals the scalar loop;
renderstays allocation-free with keys in contact (no_alloc); a benchmark of a 10-note chord’s first 5 ms against today’s engine, recorded on this page. - Plugin and demos: the plugin gates (bundle,
clap-validator), demo renders refreshed with a line indemos/CHANGES.mdand published; the maintainer listens for the click.
Out of scope, noted here: the later mic’s onset delay (up to 10 ms in the recordings; both mics share one state, T-007) and the hammer knock and key-bottom noises (Piano 10, T-010) — once the click is gone, a missing knock may make the treble attack sound soft.