T-007 — Modal reference piano: the fitted piano rendered offline in Julia, with golden vectors
Status: done — reference piano, models/piano/salamander-c5/2026-12-01/ (format v0) with golden vectors; H1–H10 and the per-partial factorisation accepted (maintainer, Dec 2026) · Area: julia, piano · Depends on: T-037, T-038
Read for that: Piano 12 (steps 1–3), the T-038 page (final fit), training/results/salamander/README.md, the Piano model file page, Piano 13 (key states, delta-form resonator, stage 1), Model pipeline (reference recurrence, golden vectors).
Why: Milestone M2 of the Roadmap. Steps 1–3 of Piano 12 produced fitted curves and per-sample partial tables for 30 of 88 keys at 4 velocity layers. Nothing yet turns them into an instrument: every key, any velocity, note-on and note-off at any time, repeated notes hitting a moving string, pedal. T-007 builds that instrument in Julia as the reference the Rust engine (T-008) must reproduce sample for sample, renders it for listening, and writes the golden vectors.
What
- Parameter expansion (
InstrumentsTraining.ReferencePiano): from the committed results to per-key tables on the model file’s axis key × string × polarisation × partial (K = 88): from the tuning and curves (curves.toml); slow and prompt rates from T-038’s laws plus the deviation curves of partials 1–8 (t038_curves.toml); beat rates, amplitudes and phases per partial, per mic and per velocity layer, filled in for the 58 unsampled keys (H3); damped decay rates (H5). Partials at or above Nyquist of the reference rate are dropped. - Renderer: 88 key states with the delta-form complex one-pole per mode, in
Float64, driven by an event list (note-on with velocity, note-off, sustain pedal down/up) at sample offsets; a struck key adds a new excitation to whatever its modes still hold; a released key switches its modes to the damped rates (unless the pedal holds them or the key has no damper). Two output channels, the Salamander mics (H2). The closed form (sum of damped sinusoids) of a single note is the test oracle. - Golden vectors and export (H6): the expanded tables and a short event list with its expected stereo output, written with
write_model. - Check against the recordings: render every Salamander key at v4, v8, v12, v16 and compare per-partial envelopes and the STFT loss with the recording and with T-038’s per-sample fits; leave-one-key-out at a few keys (render a sampled key from its neighbours only) to measure what the filling of H3 costs. Renders of the sampled notes, a chromatic scale, chords, a repeated note and a pedalled passage go to
data/t007/for listening.
Decisions
| Question | Options | Proposal | |
|---|---|---|---|
| H1 | What the reference model contains | (a) “Measured modal” stage 1: the fitted components as they are, struck by an impulse; per-mic complex amplitudes stand in for hammer, mode shapes, bridge and radiation together; velocity enters only through the amplitude tables; (b) physical stage 1 as in Piano 13: precomputed hammer pulses, mode gains from strike position, bridge gains, a soundboard IR per mic; needs T-035 (hammer felt, strike position) and T-012 (radiation responses), neither started | (a): it is what the fits determine, it reproduces the recordings to the 2 dB T-036–T-038 measured, and it gives T-008 a complete target now. (b) replaces the amplitude tables piece by piece later (T-035, T-012, T-010) without changing the resonators |
| H2 | How the fitted components map onto the model file’s key × string × polarisation axis, and how two mics fit in | (a) one “string” per component: prompt → string 1, slow → string 2, beat partner → string 3, one polarisation; per-mic gains as a new tensor partial.out_gain [C, K, S, Q, P] (complex: re/im), excitation gain 1; (b) keep the model file’s gain × bridge_gain (real, one channel) and a soundboard IR per mic: cannot carry per-mic phases, so it does not reproduce the fits | (a), as a stage-1 meaning of the axis: the components are not physical strings yet (T-036–T-038 fit “prompt + beating slow pair”, not three strings), and the file says so (excitation = "impulse", components = ["prompt", "slow", "slow_partner"]). The model-file page gains partial.out_gain; T-015 makes it part of format v1. Single-string keys (top) use the same three components |
| H3 | The 58 keys Salamander does not sample, and velocities between layers | (a) amplitudes interpolated linearly over the key in dB per partial number between the two neighbouring sampled keys; beat rates and phases from the nearer sampled key; velocity: linear in dB between layers v4, v8, v12, v16 (MIDI velocity → layer by the Salamander SFZ: v4 = 37–43, v8 = 57–64, v12 = 89–96, v16 = 121–127), clamped below v4 and above v16, so 1–36 is v4 scaled down by a velocity curve; (b) amplitude curves over the key per partial number (smooth, like the laws), velocity as a spectral tilt; (c) amplitudes from all 16 layers of T-006’s partials.csv | (a): it keeps what was measured at sampled keys exactly, and the leave-one-key-out check (What 4) measures its cost; (b) is the step after T-035 (velocity → felt), and (c) mixes T-006’s per-mic fits with the joint fits’ rates. Below v4: amplitudes of v4 times (vel / 40)² in amplitude, until T-018 calibrates the curve |
| H4 | Amplitudes and phases that match T-038’s rates | (a) T-037’s t037_partials.csv as it is (amplitudes fitted to 6 s with T-037’s shorter slow rates: the prompt/slow split is off for T-038’s rates); (b) the per-sample parameters of T-038’s stage EB (data/t038/env_b.csv: amplitudes fitted with the final curves over the whole length; phases and beat rates from T-037, since envelopes do not see phases), exported as t038_partials.csv in results/; (c) (b) plus a short audio-domain refit of phases and amplitudes only (rates held at the curves; ~2 h for 119 samples) | (b): amplitudes and rates from the same fit; phases only shape the first milliseconds and the beat pattern, which T-037 fitted in the audio domain. (c) if the comparison of What 4 shows attack errors well above T-037’s |
| H5 | Note-off: damped decay | (a) a placeholder law for now: damped T60 of 0.3 s at every partial, keys from F#6 (MIDI 90) up without dampers (Yamaha C5); the release fit becomes its own task (Salamander has 88 release samples, rel1–88, Piano 12 step 1 item 6); (b) fit the release samples here | (a): keeps T-007 the size of one task; a new task T-039 fits the damped rates and the damper’s timing from the release samples and replaces the placeholder. The golden vectors include one release so T-008 implements the mechanism |
| H6 | What T-007 writes, given that T-015 (model file v1) is open | (a) the full directory of the Piano model file page now, models/piano/salamander-c5/<date>/, as format_version = 0 (draft), with write_model; T-015 then fixes v1 and adds the Rust reader and validation; (b) only golden vectors and Julia-side tables in data/ | (a): T-008 needs both tables and golden vectors from one place; v0 states that it is a draft. Size: partial tables 88 × 3 × 1 × P_max × 4 B for a dozen tensors, a few MB at P_max = 400 → P_max as the most partials any key has (60 in the bass, T-037’s cap), well below 1 MB per tensor; golden output 2 s × 2 ch × 48 kHz × 4 B ≈ 0.8 MB. No Git LFS needed |
| H7 | Golden event list and tolerance | (a) one 2 s stream at 48 kHz: A0 v8, C4 at v4/v16, a C-major chord, C4 struck again at 0.5 s while ringing, a release at 1 s, pedal down before and up after a release, a top key without damper; reference in Float64 (delta form, as Rust will run it), stored as f32; tolerance max abs error 1e-4 of the peak at block sizes 1, 64, 513 (as the Piano model file page); (b) one file per event | (a): one stream also tests that events at sample offsets and overlapping key states add correctly |
All seven proposals accepted by the maintainer (Dec 2026). New decisions after the first results: H8–H10 under Results so far.
Done when
Tests first: the renderer matches the closed form of a single note (prompt + beating pair, 3 partials) to 1e-9; a re-strike of a ringing key equals the sum of the two notes; a release switches to the damped rate from that sample on (envelope slope), and does nothing with the pedal down or on a key without damper; parameter expansion reproduces T-038’s per-sample parameters exactly at sampled keys and layers (where the samples factor as below; on the real data the factorisation’s residuals are reported); interpolation over keys and velocities is tested on synthetic tables; write_model → read_model round trip of the piano tables and golden vectors.
A results section here: the per-key comparison with the recordings (envelope error, STFT loss, against T-038’s per-sample fits), the leave-one-key-out cost of H3, render timings, notes from listening; models/piano/salamander-c5/<date>/ with manifest, tables, golden vectors, LICENSE and ATTRIBUTION; t038_partials.csv with README; the Piano model file page updated (H2, H6); Piano 12 and Piano 13 updated where the reference changes them; T-039 (release fit) in the backlog.
Results
First build (stopped on the levels)
Code: training/src/ReferencePiano.jl (submodule InstrumentsTraining.ReferencePiano, tested in training/test/referencepiano.jl, 754 tests of the package green): expand (tables), render_events (88 key states, delta form, events at sample offsets), joint_theta (one note as a T-037 θ: the test oracle with render_joint_closed!, and the way to score the reference with T-037’s and T-038’s losses), piano_tensors, golden_events. Driver training/scripts/t007_reference_piano.jl (modes export, build, check). t038_partials.csv (T-038 stage EB’s per-sample parameters, amplitudes and phases at each sample’s onset) is in results/. The model directory models/piano/salamander-c5/2026-12-01/ is written by build (model.safetensors 0.7 MB, golden 0.8 MB) but was not committed until the levels were settled (below).
A consequence of H2 + H3 (accepted by the maintainer). Every mode has one state that both mics hear, and a second strike adds to it, so the per-mic output gain cannot depend on the velocity: velocity must sit in a real excitation per mode, and the fitted amplitudes (layer, mic, component, partial) must be factored as excitation × response. Two factorisations were tried:
| excitation | response out_gain | residual (dB), strong components (within 30 dB of the sample’s peak): median / p90, A0–G#2, A2–B3, C4–F#5, G5–C8 | single notes peaking above 1 (recordings < 1) | |
|---|---|---|---|---|
| per component | per mic | 1.1 / 7.6, 0.8 / 3.3, 0.5 / 1.6, 0.6 / 2.9 | 22 keys, A0 at 24 | |
| per partial (used) | = norm over mics and components | = the v8 layer’s amplitudes / their norm, from the nearer key between sampled keys | 0.6 / 7.6, 0.4 / 3.3, 0.4 / 2.4, 0.7 / 6.4 | 11 keys, all C7–C8 (below) |
Per partial keeps each layer’s balance of prompt, slow and partner as v8 has it. That matters because 9 % of the strong bass partials are near-cancelling pairs in the fits (the largest component 2–10× the partial’s sum at the onset): factoring them per component broke the cancellation and gave peaks up to 24. Physically it is the natural split too: the hammer excites a partial, and how that splits into components and reaches each mic belongs to the string and the soundboard.
The onset gate is not in the reference (H1’s impulse): every mode starts at full amplitude at the note-on, where the fits had a rise of τ = 0.002–8 ms per mic and the later mic’s onset up to 10 ms after the earlier one. The reference starts both mics at the earlier onset. Every note therefore clicks; T-042 replaces the impulse by a hammer contact (format v2).
Check against the recordings (check, 119 samples in 1 min; medians over layers; envelope error as T-038’s, the STFT loss as T-037’s on its 6 s windows):
| register | envelope RMS 0.3–6 s (dB): T-038 per sample / reference | STFT loss: T-037 / T-038 / reference |
|---|---|---|
| A0–A1 | 1.1–2.3 / 1.7–3.3 | 0.32–0.57 / 0.35–0.62 / 0.43–0.66 |
| C2–A3 | 2.3–3.6 / 3.1–4.4 | 0.17–0.29 / 0.20–0.31 / 0.24–0.42 |
| C4–A5 | 2.9–3.7 / 4.0–4.7 | 0.11–0.18 / 0.11–0.18 / 0.12–0.21 |
| C6–C8 | 2.5–3.8 / 3.5–6.0 (A7: 14.4) | 0.24–0.47 / 0.25–0.52 / 0.26–0.53 |
The reference costs about 1 dB of envelope error against T-038’s own per-sample fits (factorisation, velocity-independent mic responses, curves for f0 and B). Leave one key out (F#1, D#3, C4, A4, F#5 rendered from their neighbours only, 6 semitones apart): 6.0–7.7 dB against 1.7–4.7 dB, STFT loss +25–90 %. Partial amplitudes do not interpolate well over 6 semitones; real unsampled keys are 1–2 semitones from a sampled key, so this is an upper bound.
The levels of the fits are not reliable at the attack, which none of the earlier checks measured (T-038’s envelope errors start at 0.3 s). Measured here with the same analysis on model and recording (NoteAnalysis.partial_envelopes, each partial’s peak in the first 0.5 s, model − recording in dB, level-weighted median over partials within 30 dB of the strongest; median and range over the samples of a register):
| register | T-037 | T-038 | reference |
|---|---|---|---|
| A0–B1 | −0.2 [−2, 0] | −0.7 [−2, 0] | −1.1 [−4, 0] |
| C2–F#3 | −3.3 [−24, 0] | −4.6 [−18, 0] | −4.3 [−20, +1] |
| A3–F#5 | −0.8 [−6, +6] | −6.8 [−11, −1] | −7.0 [−10, 0] |
| A5–F#6 | +12.6 [+9, +33] | −3.0 [−8, −2] | −3.2 [−7, −1] |
| A6–C8 | +33.5 [+19, +57] | +2.0 [−3, +28] | +1.5 [−3, +30] |
Three different causes:
- Middle (A3–F#5): T-038’s attack is 5–10 dB too quiet. Its prompt-decay curve is slower than the samples’ own (C4: prompt T60 6.5 s on the curve, 4.0 s per sample, 4.2 s in T-037), so the envelope fit lowers the prompt amplitude to follow 0.4–2 s and loses the first 0.2 s (C4 v8, partial 2: recording −18, T-037 −19, T-038 −24 dB at 30 ms; equal from 0.4 s on). An amplitude refit with T-038’s rates held (H4 (c)) cannot fix this; the prompt rates must change.
- Treble (A5 up): T-037’s levels are 10–57 dB too loud. With 2–6 partials, T-037’s STFT loss (log-magnitude L1 over all bins) is lowered by a too-loud partial whose window skirt covers the broadband attack noise: at C7 v8 the loss is 0.284 at T-037’s level, 0.306 at a quarter of it, 0.333 at 1/17 (the recording’s level). T-038’s envelope fit corrected this except in a few samples where it kept T-037’s start (C7 v8 +23, A7 v8 +30, C8 v8–v16 +7…+15 dB).
- C2–F#3: a fast fundamental none of the fits has. At C3 v8 the recording’s fundamental is at −12 dB at the onset and falls 44 dB in 0.8 s; both fits put it at −35 dB (the other partials are right). C2 and C3 are 8–24 dB low by the level-weighted measure, D#2–F#3 3–5 dB.
The golden vectors and the renders (data/t007/: scale, velocities, chords, repeated note, pedalled arpeggio, recording-then-reference comparisons of C2, C4, A4 v8) are made with these levels. The renderer, the tables’ structure and the golden-vector mechanics do not depend on them; the numbers in the tables do.
| Question | Options | Proposal | |
|---|---|---|---|
| H8 | The middle register’s quiet attack (cause 1) | (a) rerun T-038’s envelope fit (stages EA, EB; ~6 min) with the attack as its own span (edges 0.5, 2, 6 s, four spans a quarter each), regenerate t038_curves.toml and t038_partials.csv, and recheck the slow T60 against T-038’s (stop if it moves by more than 10 % in the middle); (b) prompt law from T-037 (right at the attack), slow law and deviations from T-038, then an audio-domain refit of amplitudes and phases with all rates held (~2 h); (c) keep the levels and fix them in a later task | (a): one consistent fit, minutes, and the envelope domain is level-calibrated (it corrected the treble); the attack metric of this page becomes its check (target: within 3 dB in the middle, as T-037) |
| H9 | Treble samples with inflated levels (cause 2) | (a) in that rerun, start the treble samples’ amplitudes from the recording’s measured envelopes (each partial’s components scaled to its first frames) instead of T-037; (b) treat a layer whose attack error exceeds 6 dB as missing and fill it from the key’s other layers; (c) keep | (a), with (b) as the fallback for samples still above 6 dB |
| H10 | C2–F#3’s fast fundamental (cause 3) | (a) record it as an open question (problem log) and keep three components; (b) a fourth, fast component for partials 1–2 where needed; (c) free per-sample prompt rates for n = 1 | (a): it concerns the fundamental of a few keys, its cause is open (a soundboard or bridge resonance near 65–185 Hz is a candidate, Piano 06), and T-012 (soundboard responses) is where it belongs |
Final: H8–H10 (maintainer, Dec 2026: all three proposals and the per-partial factorisation accepted)
H8: T-038’s envelope fit rerun with the attack as its own span (edges 0.5, 2, 6 s; EDGES in t038_slow_tail.jl, 6 min), its tables regenerated (t038_curves.toml, t038_keys.csv, t038_partials.csv; the G5–G7 run is kept in data/t038/v2/). The slow T60 at f0 moves by 6–8 % in the middle (C4 20.8 → 19.2 s, D#4 19.9 → 18.4, A4 17.5 → 16.4; rule 10 %), 1–3 % elsewhere; the prompt curve now follows the samples (C4 6.5 → 4.1 s, per sample 3.9 s). G1’s ratios against the earlier audio fits stay 0.93–1.06; G3 keeps three components (4–17 % of partials > 3 dB above the tail).
H9: from A5 (key 81) up, stage EA starts with each partial’s components levelled to the recording’s first frame (level_start). Two layers stayed far too loud (C7 v8 +21.5, A7 v8 +34.6 dB) and are left out of the reference (EXCLUDED in the driver; filled from their key’s other layers); check lists any sample above +6 dB.
H10: the fast fundamental of C2–F#3 is P-007.
Attack level error (as above, dB, median [min, max] over samples; t007_check.csv):
| keys | T-037 | T-038 (rerun) | reference |
|---|---|---|---|
| A0–B1 | −0.2 [−2, 0] | −0.3 [−1, 0] | −0.3 [−3, +1] |
| C2–F#3 | −3.3 [−24, 0] | −2.6 [−15, 0] | −2.7 [−15, 0] |
| A3–F#5 | −0.8 [−6, +6] | −3.1 [−6, +1] | −3.1 [−6, +1] |
| A5–F#6 | +12.6 [+9, +33] | −5.2 [−7, −2] | −5.1 [−7, −2] |
| A6–C8 | +33.6 [+19, +57] | −11.0 [−18, +35] | −10.9 [−15, −6] |
The middle moved from −7.0 to −3.1 dB, about at H8’s target of 3 dB. The treble’s negative numbers are mostly the hammer knock, which this measure counts: from A5 up the peak is searched within ± f0/4 (± 500 Hz at C7), and the first frames hold the knock. On the strongest partial between 0.1 and 0.3 s the rerun is within ±2 dB of the recording (A6: +3 … +6), against −5 … −14 dB in the first 50 ms.
Envelope error and STFT loss after the rerun (medians over layers; t007_check.csv): envelope RMS 0.3–6 s of the reference 1.6–3.6 dB in the bass, 3.3–4.9 dB from A3 to A5, 2.9–5.5 dB in the treble (C7 and A7: 4.3 dB with their v8 layers left out), about 1 dB above T-038’s own per-sample fits. Leave one key out: 5.7–7.8 dB (upper bound, 6 semitones apart).
The model directory models/piano/salamander-c5/2026-12-01/ (format_version = 0, CC BY 4.0): model.safetensors 0.7 MB (88 keys, 3 components, up to 60 partials, 4 velocity layers, 2 mics), golden.safetensors 0.8 MB (the 19 events of H7, 2 s at 48 kHz, peak 0.85), manifest with the excitation, output and damper rules and the tolerance (max abs error 1e-4 of the peak at block sizes 1, 64, 513). The loudest single note peaks at 1.02 (A2 at v16); no other key above 1.
Timings (4-vCPU VM): tables 0.4 s; the Julia renderer (not optimised) 34–38 s for the 28 s chromatic scale, 1.4–1.8 s for a 7 s pedalled arpeggio over 12 keys; check 70 s for 119 samples.
Listening (data/t007/: scale, velocities, chords, repeated note, pedalled arpeggio, recording-then-reference for C2, C4, A4 v8): not yet listened to by the maintainer; the reference has no hammer knock, soundboard or room, so the attack is clean and the tone is the strings’ alone.
Follow-ups: T-039 (release fit, replaces H5’s placeholder); P-007 (fast fundamental, T-012); T-015 makes format v0 the model file v1 (Rust reader, validation); T-008 builds the engine against the golden vectors.