/ music / acoustic-base
Sign in
music / acoustic-base
acoustic-base / src / core / body.ts
153 lines · 6.2 KBBlameHistoryRaw
1// The parametric body: a few named low modes (A0 air mode, the main corpus modes) given directly,
2// plus a statistical continuation of the plate modes above them (random frequencies with the
3// plate's modal density and level-repulsed spacing, Gaussian mode shapes at the bridge feet with
4// the mean square fixed by the plate mass, filtered by the bridge's own in-plane resonance, and a
5// radiation coefficient from the plate's radiation efficiency). The FE body (../fe) reuses
6// statisticalModes() above its own f max.
8import type { Params } from "./params.ts";
9import type { BodyMode, BodyModel } from "./types.ts";
10import { N_STRINGS } from "./types.ts";
12/** Small deterministic PRNG (mulberry32) and a Gaussian from it. */
13export function rng(seed: number) {
14 let a = (seed * 2654435761) >>> 0 || 1;
15 const uni = () => {
16 a = (a + 0x6d2b79f5) >>> 0;
17 let t = a;
18 t = Math.imul(t ^ (t >>> 15), t | 1);
19 t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
20 return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
21 };
22 const gauss = () => {
23 const u = Math.max(uni(), 1e-12), v = uni();
24 return Math.sqrt(-2 * Math.log(u)) * Math.cos(2 * Math.PI * v);
25 };
26 return { uni, gauss };
29/** Lateral positions of the string notches on the bridge top (E on the bass side, negative). */
30export function notchPositions(spacing: number): number[] {
31 return Array.from({ length: N_STRINGS }, (_, i) => (i - (N_STRINGS - 1) / 2) * spacing);
34/** Second-order resonance gain magnitude |1 / (1 - r^2 + i r / Q)|, r = f / f0. */
35function resGain(f: number, f0: number, q: number): number {
36 const r = f / f0;
37 return 1 / Math.hypot(1 - r * r, r / q);
40const FOOT_HALF_SPAN = 0.06; // m, half the bridge foot spacing (rotation of the feet line)
42export interface StatOpts {
43 fLow: number;
44 fHigh: number;
45 /** modes per Hz (plate-like: constant) */
46 density: number;
47 /** plate mass, kg: the mean square of a mass-normalised mode shape at a point is 1/mass */
48 mass: number;
49 lossFactor: (f: number) => number;
50 /** lateral (rocking) coupling relative to the rotation of the feet */
51 lateralRatio: number;
52 bridgeF: number;
53 bridgeQ: number;
54 radCorner: number;
55 radScale: number;
56 plateArea: number;
57 notchY: number[];
58 micDistance: number;
59 airRho: number;
60 seed: number;
63/**
64 * Statistical plate modes. Spacing: Wigner surmise (level repulsion, as for chaotic plate shapes),
65 * mean 1/density. Mode shape values at the two feet: independent Gaussians with mean square 1/mass.
66 * The notch sees the feet through the bridge: vertical = mean of the feet (via a stiff vertical
67 * bridge resonance at 2.5 bridgeF), lateral = rocking of the feet line (via the in-plane bridge
68 * resonance bridgeF), and the notch's vertical motion includes the rotation times its lateral
69 * position. Radiation: a mode with spatial-mean-square velocity v^2 radiates power
70 * rho c sigma A v^2; spread over a sphere this gives |p| per unit modal acceleration of
71 * rho c sqrt(sigma A / M) / (w d sqrt(4 pi)), with sigma = radScale (f/fc)^2 / (1 + (f/fc)^2),
72 * and a random phase.
73 */
74export function statisticalModes(o: StatOpts): BodyMode[] {
75 const r = rng(o.seed);
76 const modes: BodyMode[] = [];
77 const c = 343;
78 const rms = 1 / Math.sqrt(o.mass);
79 let f = o.fLow + r.uni() / o.density;
80 while (f < o.fHigh) {
81 const fb = r.gauss() * rms, ft = r.gauss() * rms; // bass foot, treble foot
82 const gv = resGain(f, 2.5 * o.bridgeF, o.bridgeQ);
83 const gl = resGain(f, o.bridgeF, o.bridgeQ);
84 const v = 0.5 * (fb + ft) * gv;
85 const rot = ((ft - fb) / (2 * FOOT_HALF_SPAN)) * gv; // rad per unit eta
86 const lat = -o.lateralRatio * (ft - fb) * gl;
87 const by = o.notchY.map((y) => v + rot * y);
88 const bz = o.notchY.map(() => lat);
89 const w = 2 * Math.PI * f;
90 const x = f / o.radCorner;
91 const sigma = (o.radScale * x * x) / (1 + x * x);
92 const amp = (o.airRho * c * Math.sqrt((sigma * o.plateArea) / o.mass)) / (w * o.micDistance * Math.sqrt(4 * Math.PI));
93 const ph = 2 * Math.PI * r.uni();
94 modes.push({ f, zeta: 0.5 * o.lossFactor(f), by, bz, radRe: amp * Math.cos(ph), radIm: amp * Math.sin(ph) });
95 // Wigner surmise spacing, mean 1: s = sqrt(-4/pi ln u)
96 const s = Math.sqrt((-4 / Math.PI) * Math.log(Math.max(r.uni(), 1e-12)));
97 f += s / o.density;
98 }
99 return modes;
102/** Modal density (modes per Hz) of a thin orthotropic plate of area A: (A/2) sqrt(rho h / sqrt(D11 D22)). */
103export function plateDensity(area: number, h: number, rho: number, eL: number, eR: number, nu: number): number {
104 const d11 = (eL * h ** 3) / (12 * (1 - nu * nu * (eR / eL)));
105 const d22 = (eR * h ** 3) / (12 * (1 - nu * nu * (eR / eL)));
106 return (area / 2) * Math.sqrt((rho * h) / Math.sqrt(d11 * d22));
109export function parametricBody(p: Params): BodyModel {
110 const b = p.body;
111 const notchY = notchPositions(p.fe.stringSpacing);
112 const H = p.fe.bridgeHeight;
113 const rho0 = p.fe.airRho;
114 const d = p.output.micDistance;
115 const modes: BodyMode[] = [];
116 const r = rng(b.seed * 7919 + 13);
117 for (const m of b.lowModes) {
118 const v = 1 / Math.sqrt(m.mass);
119 const lat = m.lateral * v * (r.uni() < 0.5 ? -1 : 1);
120 // rigid bridge: lateral motion at the notches = -H * rotation, so rotation = -lat / H
121 const rot = -lat / H;
122 modes.push({
123 f: m.f,
124 zeta: 1 / (2 * m.q),
125 by: notchY.map((y) => v + rot * y),
126 bz: notchY.map(() => lat),
127 // monopole: m.rad is the volume displaced per unit (vertical) bridge displacement, m^2
128 radRe: (rho0 * m.rad * v) / (4 * Math.PI * d),
129 radIm: 0,
130 label: m.label,
131 });
132 }
133 const density = b.densityScale * plateDensity(b.plateArea, p.fe.topThickness, p.fe.topRho, p.fe.topEL, p.fe.topER, p.fe.topNu);
134 const stat = statisticalModes({
135 fLow: b.statFLow,
136 fHigh: b.statFHigh,
137 density,
138 mass: b.plateMass,
139 lossFactor: (f) => b.lossFactor * Math.pow(f / 1000, b.lossExp),
140 lateralRatio: b.lateralRatio,
141 bridgeF: b.bridgeF,
142 bridgeQ: b.bridgeQ,
143 radCorner: b.radCorner,
144 radScale: b.radScale,
145 plateArea: b.plateArea,
146 notchY,
147 micDistance: d,
148 airRho: rho0,
149 seed: b.seed,
150 });
151 modes.push(...stat);
152 return { name: "parametric", source: "parametric", modes, meta: { lowModes: b.lowModes.length, statModes: stat.length, density } };
↑↓ move↵openescclose