Piano
The piano engine is modal: each note is a sum of exponentially decaying sinusoids, the partials of its strings. There is no hammer-string contact simulation and no soundboard simulation; their effects are imposed on the partials' amplitudes and decays.
Partials of a stiff string
f_n = n f_s sqrt(1 + B n^2), f_s = f0 / sqrt(1 + B)
so that the first partial is exactly the requested pitch. The stiffness coefficient is
B = inharmonicity * max(8e-5, 3e-4 exp(0.085 (m - 60))) (m = MIDI note)
about 1e-4 in the bass, 3e-4 at middle C and above 1e-2 in the top octave, the orders of magnitude reported for grand pianos. Up to 36 partials below 0.45 fs are generated. Because the partials are stretched, a periodicity estimator reads a piano note sharp; the tests measure the first partial as a spectral peak (error below 0.01 cent).
Hammer
A string struck at fraction p of its length cannot excite partials with a node there:
a_n = sin(n pi p) / n * 1 / (1 + (f_n / f_c)^2)
p = 1/8 by default (partials 8, 16, ... vanish). The low-pass models the finite contact time
of the felt, which shortens when the key is struck harder:
f_c = (300 + 11000 v^2 (0.25 + 1.5 brightness)) (0.5 + hardness) + 1.5 f0 [Hz]
That is the source of "louder is brighter" (test louder_is_brighter_for_brass_and_piano).
Amplitudes are normalised so that the sum of |a_n| is constant; loudness follows
0.08 + 0.92 v^1.6. A 12 ms burst of band-passed noise stands for the knock of the hammer and
action.
Double decay and beating
Two or three strings per note, slightly mistuned and coupled at the bridge, give the piano its fast "prompt sound" followed by a slow "aftersound", and a slow beating. Each partial is therefore two sinusoids:
0.72 a_n sin(2 pi f_n d1 t) exp(-6.9 t / (0.45 T_n)) + 0.28 a_n sin(2 pi f_n d2 t) exp(-6.9 t / (1.7 T_n))
with d1, d2 detuned by a seeded random fraction of unison_detune (reduced to 30 % below
MIDI 34, where notes have one string), and
T_n = decay * 12 s * 2^(-(m - 21) / 20) / (1 + 0.05 n^1.4)
(12 s at A0, about 3 s at middle C, 0.6 s at C8, shorter for higher partials.) This reproduces the shape of the double decay; the coupling itself is not simulated, so the ratio of the two rates does not depend on the bridge admittance as it does on an instrument.
Dampers, pedal, soundboard
Note-off closes an amplitude envelope (envelope.release, 0.18 s by default). Notes from MIDI
90 up have no dampers and ring out. With the sustain pedal down note-offs are deferred.
resonance feeds the sum of the voices to 14 two-pole resonators between 55 Hz and 2.6 kHz
whose decay time is 0.35 s with the pedal up and 3.5 s with it down: a coarse stand-in for the
soundboard and for the sympathetic ringing of undamped strings. It is not a model of string to
string coupling (a held silent key does not resonate at its own partials).
Validity. Timbre is plausible from A0 to C8 and responds to velocity; attack transients, longitudinal modes ("phantom partials"), una corda and half-pedalling are not modelled. Pitch bend is ignored by this engine.