Piano model file — the contract between the Julia fit and the Rust engine
The piano’s instance of the general model file of Model pipeline (ADR-0003). Julia writes it (Piano 12); Rust reads and validates it (Piano 13). Anything not in this file is not part of the model. The current format is v4: the stage-1 measured modal model of T-007 in the layout of v1 (T-015), with the hammer contact of T-042 replacing v1’s impulse excitation (v1 made every note click), and since T-050 a level below the first layer that is linear in velocity, fitted on Salamander’s soft layers (v2 had a guessed 40 dB per decade), and since T-035 a spectral tilt there too: softer than the first layer, a note gets darker, as Salamander’s v1–v3 are (v3 played the first layer’s spectrum, only quieter).
Code: writer and validator InstrumentsTraining.PianoModelFile (write_piano_model, validate_piano_model; training/src/PianoModelFile.jl, v4 only); reader instruments-model-format (crates/model-format: piano::PianoModelV4, piano::PianoGolden; v4 only). Both apply the checks under Validation; keep the two lists equal. The engine: instruments_dsp::PianoEngine (T-008, the contact: T-042), checked against the golden vectors. The model: models/piano/salamander-c5/2026-12-04/ (v4, T-035; its tables are byte-identical to the v3 model 2026-12-03/ and the v2 model 2026-12-02/, which with the v1 model 2026-12-01-r2/ are in Git history); a committed model directory never changes, a new fit gets a new directory.
Layout
models/piano/<name>/<version>/
manifest.toml format, version, dimensions, rule parameters, sources, licence, provenance
model.safetensors all tables (below)
golden.safetensors test events and expected output (optional)
LICENSE per ADR-0007
ATTRIBUTION.md sources and creditsFormat v4: the measured modal model with hammer contact
v2 = v1 plus the hammer contact: excitation.kind = "hann_contact" and the table key.contact_s. v3 = v2 with excitation.below_first_layer_db_per_velocity in place of below_first_layer_db_per_decade (T-050 D1). v4 = v3 with the tilt below the first layer: excitation.below_first_layer_tilt_knots, below_first_layer_tilt_db_per_octave_per_velocity and below_first_layer_tilt_pivot_octaves (T-035 D1 b, D3). Everything else means what it meant in v1.
Each key has S “strings” that are the fitted components of each partial (T-007 H2: prompt at , slow at , slow_partner at ), Q = 1 polarisation. A note-on adds a real excitation to each mode’s complex state ; the mode rings at its frequency and decay; channel hears . Hammer, mode shapes, bridge and radiation are all folded into and (T-007 H1).
Mechanisms fixed by the format (the manifest carries only their parameters):
- Resonator: per sample, in delta form, , with =
partial.decay, orpartial.damped_decaywhile damped. - Excitation (
[excitation] kind = "hann_contact", T-042): frompartial.excite_db, linear in dB in MIDI velocity betweenvelocity.layers, held above the last layer, below the first, with and the mode’s partial number (its index on the P axis + 1): =below_first_layer_db_per_velocity≥ 0 (0.36 dB per MIDI step, the fit 0.3598 rounded, on Salamander’s layers v1–v3 by T-050: RMS 1.9 dB over 21 keys, where v2’s guessed 40 dB/decade missed by 6 dB); the tilt’s slope at MIDI key in dB per octave of partial number per velocity step, linear betweenbelow_first_layer_tilt_knots(MIDI) with the valuesbelow_first_layer_tilt_db_per_octave_per_velocity≥ 0 and held outside them (Salamander: 0.115, 0.323, 0.298, 0.117, 0 at MIDI 36, 48, 66, 78, 90, fitted by T-035 on v1–v3, RMS 2.3 dB/octave); =below_first_layer_tilt_pivot_octaves≥ 0, the partial that keeps its level (0.244: partial 1.18, chosen so the level of harmonics 1–6 stays T-050’s in the least-squares sense over keys and velocities; per key it moves by −3.2…+1.4 dB at velocities 13–40, mean −0.1). From the first layer up, and v3’s excitation is unchanged. The amplitude is added to a second, pending state of each mode, not to ; the note-on starts the key’s contact of samples, fromkey.contact_s(linear in MIDI velocity between the layers, held outside). Per sample, after the output and the update of and (both with the mode’s current coefficient, free or damped): during contact step (0 after the note-on’s own sample), with (the running integral of a Hann pulse; at the last step, ), then , ; after contact . A single strike’s mode is therefore : it rises to exactly the amplitude and phase an impulse gives, and from the end of contact on the output equals v1’s. A re-strike adds to and restarts the contact (what is still pending follows the new pulse); a struck mode keeps what holds. - Output (
[output] kind = "re_complex_gain"): channel = , =partial.out_gain[c, …, 0] + i·[…, 1]. - Damper: a key’s modes decay at
partial.damped_decaywhile the key has a damper (has_damper = 1), is not held and the sustain pedal is up, and atpartial.decayotherwise; the state is re-evaluated at every event.
manifest.toml
Unknown fields are refused, so a typo cannot pass silently. Values of the Salamander model:
format = "piano-modal"
format_version = 4 # bump on any change that alters meaning or shapes
model = "measured-modal" # a later version adds "physical"
name = "salamander-c5"
model_version = "2026-12-04" # date of the fit, -rN for a revision of that date
units = "SI" # Hz, 1/s, s
reference_rate_hz = 48000 # all frequencies are below its Nyquist
keys = { first_midi = 21, count = 88 }
max_strings = 3 # S
polarisations = 1 # Q
max_partials = 60 # P: the most partials any key has
velocity_layers = 4 # V
channels = 2 # C
channel_names = ["Salamander mic 1", "Salamander mic 2"]
components = ["prompt", "slow", "slow_partner"] # one name per S
license = "CC-BY-4.0" # ADR-0007: most restrictive source
[excitation]
kind = "hann_contact" # v1: "impulse"
below_first_layer_db_per_velocity = 0.36
below_first_layer_tilt_knots = [36.0, 48.0, 66.0, 78.0, 90.0] # MIDI
below_first_layer_tilt_db_per_octave_per_velocity = [0.115, 0.323, 0.298, 0.117, 0.0]
below_first_layer_tilt_pivot_octaves = 0.244
[output]
kind = "re_complex_gain"
[damper]
placeholder = false # fitted (T-039); T-007's model had true …
# … and damped_t60_s = 0.3, the placeholder's T60 (optional)
[[sources]] # name, license; optional author, url, sha256, attribution
name = "Salamander Grand Piano V3"
license = "CC-BY-3.0"
[fit] # commit, julia_manifest_sha256, tasks; optional loss
commit = "3b1c161…"
tasks = ["T-006", "T-037", "T-038", "T-007"]
[golden] # present exactly when golden.safetensors is
rate_hz = 48000
seconds = 2.0
max_abs_error_rel_peak = 1e-4 # tolerance relative to the output's peak
block_sizes = [1, 64, 513]
[tensors] # generated by the writer: dtype and shape of every tensorTables in model.safetensors
Row-major, little-endian, with the Julia shape (Model pipeline); indices below are 0-based in Rust, key is MIDI . K = 88.
| Tensor | Shape, dtype | Meaning |
|---|---|---|
key.has_damper | [K] u8 | 1 if the key has a damper (Yamaha C5: none from F#6 up) |
string.n_partials | [K, S] u16 | valid partials per string, 1…P |
partial.freq_hz | [K, S, Q, P] f32 | per component (includes inharmonicity and the beat offset) |
partial.decay | [K, S, Q, P] f32 | free decay rate (1/s) |
partial.damped_decay | [K, S, P] f32 | decay with the damper down; ≥ decay. Salamander: T-039’s damper law at , the same for the three components of a partial |
partial.excite_db | [V, K, S, Q, P] f32 | excitation (dB) per velocity layer |
partial.out_gain | [C, K, S, Q, P, 2] f32 | complex response (re, im) per channel; velocity-independent |
velocity.layers | [V] f32 | MIDI velocity of each layer, strictly increasing in (0, 127] |
key.contact_s | [V, K] f32 | hammer contact time (s) per layer and key, in (0, 0.01]. Salamander: T-042’s law, 4 ms at A0 to 1 ms at C8, ×1.3 (quietest layer) to ×0.8 (loudest) |
curve.<name>.knots, curve.<name>.values | [J] f32 | smooth per-key curves the tables came from (tuning, , decay laws, the damper law’s damper_a, damper_b: ); documentation and editing, the engine uses the tables |
Invalid partials (index ≥ n_partials) are exactly zero in every table and never computed. Size of the Salamander model: 0.7 MB, golden 0.8 MB.
Golden vectors (golden.safetensors)
An event stream and the expected output of the Julia reference (T-007 H7: 25 events over 2 s at 48 kHz — notes across the keyboard at several velocities, a chord, a re-strike, releases with and without pedal, a key without damper, a velocity below the first layer; T-042: a re-strike and a release inside the hammer contact; T-035: two notes below the first layer where the tilt is not zero, A3 at velocity 15 and E1 at 8). Rust must match within max_abs_error_rel_peak at each of block_sizes (T-008).
| Tensor | Shape, dtype | Meaning |
|---|---|---|
events.sample | [E] u32 | sample index (0-based), non-decreasing; events at a sample apply before its output |
events.kind | [E] u8 | 1 note-on, 2 note-off, 3 sustain pedal down, 4 pedal up |
events.key | [E] u8 | MIDI key (21–108) for notes, 0 for pedal events |
events.velocity | [E] f32 | MIDI velocity of a note-on, fractional allowed (CLAP), in (0, 127] |
output | [N, C] f32 | expected output, N = rate_hz · seconds |
Validation
A model that fails any check is refused with an error, never half-loaded:
- Structure:
format,format_version = 4(v1, v2 and v3 are refused, naming the version),model; all manifest fields present with the right types, no unknown ones; K = 88 from MIDI 21; dimensions positive;channel_namesandcomponentsone per channel and string;excitation.kind,output.kindas above;format_versionan integer and checked before the other fields (a v3 manifest is refused for its version);below_first_layer_db_per_velocityfinite and in [0, 10];below_first_layer_tilt_knotsa non-empty, strictly increasing list of MIDI keys 21–108,below_first_layer_tilt_db_per_octave_per_velocityone finite value in [0, 10] per knot (the bounds keep the engine’sf32tables finite),below_first_layer_tilt_pivot_octavesfinite and in [0, log2max_partials];licenseandsources(ADR-0007); every table present with its dtype and the shape the dimensions give, no other tensor thancurve.*pairs (equal length ≥ 2, knots strictly increasing, finite); the manifest’s[tensors]equal to the file’s header;[golden]present exactly when the golden file is. - Values:
has_damper∈ {0, 1}; 1 ≤n_partials≤ P; for valid partials 0 <freq_hz<reference_rate_hz/2,decay> 0 and finite,damped_decay≥decayand finite,excite_dbandout_gainfinite; each mode’s excitation amplitude is within thef32limit at the stored layers and at the velocity-zero endpoint of the extrapolation; invalid partials zero;velocity.layersas above; everykey.contact_sfinite and in (0, 0.01] s. - Golden: the five tensors with their dtypes and no others, equal event counts, events in time order and inside the output, kinds 1–4, note keys on the keyboard, note-on velocities in (0, 127], output finite with shape [N, C].
A partial above a lower host rate’s Nyquist is not an error: the engine culls it at activate (T-008). Partial tables are rate-independent; the format has no sampled tables, so nothing is resampled ( is a time, converted at the engine’s rate).
Planned: the physical model
When Piano 13’s physical stage 1 replaces the measured excitation and gains (T-035 hammer felt and strike position, T-012 soundboard responses, T-010), model = "physical" adds real strings and polarisations on the S and Q axes and these tables; until then they are not part of any format:
| Tensor | Shape | Meaning |
|---|---|---|
key.n_strings | [K] u8 | strings per key (1–3) |
key.strike_pos | [K] | |
key.hammer_mass, key.felt_k, key.felt_p, key.felt_alpha | [K] | hammer (05); stage 2 |
partial.gain | [K, S, Q, P] | coupling of the hammer force into the mode (mode shape at , polarisation share) |
partial.bridge_gain | [K, S, Q, P] | contribution of the mode to the bridge force |
hammer.velocities, hammer.pulse | [V], [V, K’, N] | precomputed force pulses (stage 1) for K’ key regions, at reference_rate_hz |
soundboard.ir | [C, M] | radiation responses per virtual mic channel (06) |
noise.<kind> | [N] | key, knock, damper, pedal excitations (10) |
Sampled tables (pulses, IRs, noises) will be resampled at activate when the host rate differs from reference_rate_hz. Sizes: a partial table at P = 400, S = 3, Q = 2 is 0.8 MB; Git LFS if a model exceeds a few MB. Rust supports the current format_version only and states which one it needs.