// Bar geometry, wood materials, the nominal size of each key's bar, and the resonator // and mic placement. Lengths in mm unless a name says otherwise. // Axes: x = length (grain, L), y = width (front edge at y = 0, T), z = thickness (up, R). // The top face is flat at z = h0; the undercut arch is cut into the bottom face. export const AIR = { rho: 1.2, c: 343 }; export const MATERIALS = { rosewood: { label: 'Honduras rosewood', rho: 1025, EL: 22.0, eta: 0.006 }, padauk: { label: 'Padauk', rho: 745, EL: 11.7, eta: 0.01 }, }; export const LOW_NOTE = 36; // C2 export const HIGH_NOTE = 96; // C7 const NOTE = ['C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#', 'A', 'A#', 'B']; export const noteName = (k) => NOTE[k % 12] + (Math.floor(k / 12) - 1); export const noteFreq = (k) => 440 * 2 ** ((k - 69) / 12); export const freqToMidi = (f) => 69 + 12 * Math.log2(f / 440); export const isBlack = (k) => [1, 3, 6, 8, 10].includes(k % 12); // Orthotropic hardwood stiffness (ratios as for dense hardwoods), scaled by E_L (Pa). export function woodStiffness(EL, scale = 1) { const E = EL * scale; const Ex = E, Ey = 0.065 * E, Ez = 0.132 * E; // L, T, R const nuLT = 0.476, nuLR = 0.424, nuRT = 0.774; const S = [ [1 / Ex, -nuLT / Ex, -nuLR / Ex], [-nuLT / Ex, 1 / Ey, -nuRT / Ez], [-nuLR / Ex, -nuRT / Ez, 1 / Ez], ]; const C = inv3(S); return { E: Ex, c11: C[0][0], c22: C[1][1], c33: C[2][2], c12: C[0][1], c13: C[0][2], c23: C[1][2], gxy: 0.063 * E, gxz: 0.111 * E, gyz: 0.02 * E, }; } function inv3(m) { const [a, b, c] = m[0], [d, e, f] = m[1], [g, h, i] = m[2]; const A = e * i - f * h, B = -(d * i - f * g), Cc = d * h - e * g; const det = a * A + b * B + c * Cc; return [ [A / det, -(b * i - c * h) / det, (b * f - c * e) / det], [B / det, (a * i - c * g) / det, -(a * f - c * d) / det], [Cc / det, -(a * h - b * g) / det, (a * e - b * d) / det], ]; } /** * A bar design: { L, W, h0 (mm), d: undercut depth (mm), a: undercut length as a * fraction of L, p: arch shape exponent (2 = parabola, larger = flatter bottom) }. */ export function thickness(b, x) { const u = Math.abs(x - b.L / 2) / ((b.a * b.L) / 2); return u < 1 ? b.h0 - b.d * (1 - u ** b.p) : b.h0; } export const MIN_THICK = 3; // mm left at the deepest point of the arch export const maxDepth = (b) => b.h0 - Math.max(MIN_THICK, 0.1 * b.h0); // Width and thickness change smoothly from C2 to C7; the tuner sets length and undercut. export function nominalDesign(note, mat) { const t = (note - LOW_NOTE) / (HIGH_NOTE - LOW_NOTE); const W = 72 - 32 * t, h0 = 24 - 4 * t; // typical 5-octave concert ranges // length guess: uniform-bar formula, with the arch lowering f1 more in the bass const c = Math.sqrt((mat.EL * 1e9) / mat.rho); const lower = 1.2 * 2 ** ((HIGH_NOTE - note) / 24); const L = 1000 * Math.sqrt((1.028 * c * h0 * 1e-3) / (noteFreq(note) * lower)); const b = { L, W, h0, d: 0, a: 0.45, p: 4 }; b.d = 0.65 * maxDepth(b); return b; } export function validateDesign(b) { const e = []; if (b.d > maxDepth(b) + 1e-9) e.push(`undercut deeper than ${maxDepth(b).toFixed(1)} mm`); if (b.L < 2 * b.W) e.push('bar shorter than twice its width'); return e; } // ---------- resonator and mic ---------- /** * Resonator: closed-bottom round tube centred under the bar. * res = { on, diam (fraction of W), gap (mm from the bar's bottom plane to the tube top), * detune (cents), loss (× wall loss) } */ export function tubeGeom(b, res) { const a = (res.diam * b.W) / 2; // radius, mm // end correction: unflanged pipe plus the bar acting as a partial lid over the mouth const delta = 0.61 * a + (0.15 * a * a) / Math.max(2, res.gap); return { a, delta, x: b.L / 2, y: b.W / 2, zTop: -res.gap }; } // Tube length (mm) whose air column, with the end correction, resonates at f (Hz). export function tubeLength(f, delta) { const k = (2 * Math.PI * f) / (AIR.c * 1000); // 1/mm return (Math.PI / 2 - Math.atan(k * delta)) / k; } export const MIC = { front: 300, up: 450 }; // mm in front of and above the bar centre export const micPos = (b) => [b.L / 2, b.W / 2 - MIC.front, b.h0 + MIC.up];