loading...
running...
How to use
Click or touch the keys (lower on the key = harder strike), or type A W S E D F T G Y H U J K on a computer keyboard; Z / X shift the octave and Space is the sustain pedal. Click a key in the 3D piano (or in the small keyboard below it); use the camera buttons for the keyboard, the hammers and strings, the top view and the action cutaway on the right. The ribbons over the strings are the real finite-difference solution in slow motion; the graphs below show the felt force, the bridge force, the partial frequencies against the formula, the spectrum and the inharmonicity B for all 88 keys.
Things to try: play the Ideal string preset and then Concert grand C4 (listen to the stretched, bell-like partials appear); compare Soft felt and Hard hammer; strike at 1/7 and watch partial 7 disappear in the spectrum; raise the wire diameter and watch B and the sharp upper partials grow; pick Honky-tonk to hear unison beating.
The science
String. Each key strikes 1 to 3 steel strings. A stiff string obeys mu u_tt = T u_xx - E I u_xxxx - 2 mu s0 u_t + 2 mu s1 u_txx + F_hammer, with linear density mu, tension T, bending stiffness EI = E pi d^4 / 64 and two loss terms (frequency independent s0, frequency dependent s1). With hinged ends the modes are sines and the frequencies are not exact multiples of the fundamental:
f_n = n f0 sqrt(1 + B n^2), f0 = (1/2L) sqrt(T/mu), B = pi^3 E d^4 / (64 T L^2)
For a mid-range piano key B is about 3e-4, so the 10th partial is already about 17 cents sharp; for the top octave B is about 5e-3. This stretching is why a piano is tuned with stretched octaves and why a real piano and an ideal string sound different.
Numerical model. The string is solved with an explicit finite-difference scheme (hinged ends, second-order in time and space) whose grid spacing obeys the stability bound h^2 >= (c^2k^2 + 4 s1 k + sqrt((c^2k^2 + 4 s1 k)^2 + 16 kappa^2 k^2)) / 2 at 44.1 kHz. The tension is tuned slightly so the discrete fundamental equals the target pitch. The same code runs in an AudioWorklet to make the sound, so what you hear is the model, not a recording.
Hammer. The felt is a nonlinear spring: F = K (y - u_h)^p while compressed (p about 2.3 to 3 from bass to treble), and the hammer mass obeys m_h y'' = -F. A harder felt (larger K) or a faster strike shortens the contact time (about 3 ms in the bass, 1 ms in the treble) and so adds high partials; a force pulse of width tau multiplies the partials by roughly cos(w tau/2) / (1 - (w tau/pi)^2). The strike point at fraction beta of the length weights mode n by |sin(n pi beta)|, so striking at 1/7 removes the 7th partial. Real pianos strike near 1/8 to 1/9.
Action (3D model). The key is a lever about the balance pin; its rear end lifts the wippen through the capstan, the jack pushes the hammer roller up, and just before the string the jack is tripped by the regulating button (let-off), so the hammer flies free, hits the string, rebounds and is caught by the back-check while the key is held. Releasing the key lowers the damper back onto the string unless the sustain pedal is down. The cutaway is a schematic of a grand action with plausible proportions, not the drawing of a particular maker; the hammer speed of the animation equals the strike speed that drives the string model, and the sound starts at the moment of felt contact.
Checks shown in the page. (1) measured partial frequencies from a high-rate numerical run against the analytic formula; (2) the node at L/7; (3) energy conservation: kinetic energy lost by the hammer equals the energy gained by the loss-free string within 1%.
Honest simplifications. The 3D strings are drawn at 82 % of the model length so that all 88 fit a 2.7 m case, and the string layout is a plain fan, not the overstrung bass of a real piano. The vibrating strings are slow-motion ribbons with exaggerated displacement. Only vertical polarisation is simulated (real strings also move horizontally and longitudinally, which adds the phantom partials and the bright attack of the bass); the three unison strings are not coupled through the bridge, so the double decay is only approximated by their small detuning; the soundboard is a few filters, not a radiating plate; the copper winding is treated as added mass only; felt parameters and the string scale are plausible values, not measurements of a particular instrument. The tone is physically motivated, but it is not a sampled Steinway.
Models and baked PBR textures made in Blender; Three.js r160 animates every part.