// Physics laws shared by the modal model and the SoundFont export. // Damping law of the modal model: Rayleigh damping matched to loss factor eta at F1 and // F2, with the stiffness term rolled off above F_TAU (a Zener element). export const F1 = 400, F2 = 4000, F_TAU = 40000; export const TAU = 1 / (2 * Math.PI * F_TAU); export function rayleigh(eta) { const w1 = 2 * Math.PI * F1, w2 = 2 * Math.PI * F2; return { alpha: (eta * w1 * w2) / (w1 + w2), beta: eta / (w1 + w2) }; } // Amplitude decay rate (1/s) of a mode at angular frequency w. export function decayRate(w, eta) { const { alpha, beta } = rayleigh(eta); return alpha / 2 + (beta * w * w) / (2 * (1 + (w * TAU) ** 2)); } // Hertz contact (F = K d^1.5) of mass m at speed v0 against a rigid surface. export function hertzPulse(K, m, v0) { const dmax = Math.pow((5 * m * v0 * v0) / (4 * K), 0.4); return { T: (2.9432 * dmax) / v0, Fm: K * Math.pow(dmax, 1.5) }; } // Fourier transform of a half-sine pulse A sin(pi t/T), 0 a: integral = T/2 * (-i) * A (approximately) return [0, -A * T / 2]; } const re = (A * a * (1 + Math.cos(w * T))) / den; const im = (-A * a * Math.sin(w * T)) / den; return [re, im]; } export const pitchScale = (semitones) => Math.pow(2, semitones / 12);