087c169Physically simulated pizzicato double bass and an SF2 built from itJeremy Magland 1# acoustic-base
3A physically simulated pizzicato double bass ("acoustic bass", GM program 32) and a SoundFont built from it. It was made to stand in for GeneralUser GS's *Acoustic Bass*, which it can be compared against note by note.
5Steel strings E1 A1 D2 G2 on a 1.06 m scale, plucked by a finger and stopped by a finger, couple at the bridge to a body. The body is either parametric or computed by finite elements from the geometry and the woods. The output is what a microphone in front of the bass hears, blended with a bridge pickup.
7```bash
8npm install
9npm run dev # the app, http://127.0.0.1:8023
10npm run build-sf2 # acoustic-bass.sf2 (+ acoustic-bass.json, the params used)
11```
13The app is also deployed as this repository's site on vault1 (built by `.mochi/workflows/deploy.yml` on every push to `main`). There, use **Ref SF2…** to choose a reference SoundFont from your computer (it is not uploaded); the dev server instead serves `~/Downloads/GeneralUser-GS/GeneralUser-GS.sf2` (or `$REF_SF2`) automatically.
15`acoustic-bass.sf2` in this folder was built with the default parameters and the FE body. It has 11 notes (E1 to A#3, every 3 semitones) × 3 velocity layers. The 33 samples are unlooped, 5 s at E1 down to 3 s at the top, 16-bit mono at 44.1 kHz, 11.4 MB in all. They are in tune within about ±8 cents across the keyboard, measured through spessasynth.
17## The app
19- **Keyboard.** C1 to D4 (dots mark the SF2's sample roots; the keys below E1 are on a low-C extension). Click a key to render that note and play it. Computer keys `A W S E D F T G Y H U J K O L P ;` and Web MIDI also work.
20- **Keys play.** Choose *simulation* (each note is rendered in a worker, 2–5 s), *built SF2* (plays live through spessasynth) or *reference SF2* (plays live).
21- **Sim / Ref / A/B.** Play the last render, the reference at the same note and velocity, or both in turn.
22- **Reference.** The dev server serves `~/Downloads/GeneralUser-GS/GeneralUser-GS.sf2` at `/ref.sf2`; set `REF_SF2=/path/to.sf2` to use another file. It stays on this machine. **Ref SF2…** picks a file instead (needed on the deployed site). The reference renders dry, through spessasynth_core, bank 0 program 32.
23- **Mic / Pickup mix.** Takes effect without re-rendering, because the engine returns both signals.
24- **Tabs.**
25 - *Sound:* envelope, spectrum, first 60 ms of the waveform, and mic vs pickup.
26 - *Spectrogram:* simulation and reference.
27 - *Partials:* level and T60 per partial, simulation vs reference.
28 - *Body:* bridge admittance (vertical and lateral) and radiation transfer at the played string's notch, plus the mode list.
182eaafAdd a Physics 3D tab: slow-motion 3D replay of the simulationJeremy Magland 29 - *Physics 3D:* the simulation in 3D and in slow motion (see below).
087c169Physically simulated pizzicato double bass and an SF2 built from itJeremy Magland 30 - *SF2:* build the SoundFont in the browser on all cores (about 20–30 s), then download it or play it on the keys.
31- **Parameters** (left) are grouped: Engine, Strings, Right hand, Left hand, Body (parametric), Body (FE), Output, SF2. Hover a parameter for an explanation. Parameters persist in the browser; *Save* / *Load* exchange them as JSON, the same format `scripts/build_sf2.ts --params` reads. *Compute FE body* takes about 15 s. The FE body is recomputed automatically when its inputs change.
182eaafAdd a Physics 3D tab: slow-motion 3D replay of the simulationJeremy Magland 33### The Physics 3D tab
35The tab records the current note with the engine's full state, then replays it. Three.js loads only when the tab is first opened.
37- **What is drawn.**
38 - The played string (gold) and the other strings, both polarisations.
39 - The plucking finger, which sticks, pulls, then lets the string slip off; and the stopping finger.
40 - The bridge, which rocks and slides with the notches.
41 - The top and back plates, displaced and coloured by their normal motion.
42 - The air pressure on a mid-depth slice of the cavity.
43 - The f-hole air plugs, drawn as arrows.
44 - The ribs, neck and tailpiece are static.
45- **Exaggeration.** Motion is scaled automatically so it shows. The string part of the strings' motion uses the string scale. The body, the bridge, and the bridge end of each string use the body scale. The legend gives both factors and the colour range.
46- **Recording.**
47 - Every engine step is kept from the start of the pull until 50 ms after the release. Elsewhere a frame is kept every 0.5 ms.
48 - The view interpolates between frames, and the time readout says which kind of frame you are on.
49 - *record detail here* re-records with every step kept for the 50 ms from the playhead.
50 - Forces, energies, and the mic and pickup signals are kept at every step.
51 - A 1 s note at the default settings is about 17 MB of frames.
52- **Playback.** Speeds run from 1/10000 to real time. Scrub with the time bar, or click and drag on a plot. Keys: space plays and pauses, ← and → step one frame, Home goes to the start. Playback is silent; *sound from here* plays the note at real speed from the playhead while the view follows.
53- **Plots.**
54 - Finger force on the string, and string force on the bridge.
55 - Energy in the played string, the other strings, the body structure and the air, in dB.
56 - The mic and pickup signals.
57 - They can show the whole note, the detail window, or ±50, ±5 or ±0.5 ms around the playhead.
58- **Mode explorer.**
59 - *Body modes* lists each FE mode with its frequency, Q, T60, coupling at the played string's notch, share of air energy, and radiation. Click a mode to animate its shape at 0.6 Hz: plates, air, plugs and bridge.
60 - *String partials* lists the played string's partials, with inharmonicity and T60. Click one to animate its shape.
61- **Mode shapes.**
62 - The FE solver can export each mode's normal displacement at the plate nodes, the pressure on the mid-depth air layer, and the plug displacement (`src/fe/shapes.ts`).
63 - `scripts/fe_body.ts` writes them for the default body to `bodies/fe_default_shapes.bin` (3.3 MB, int8 per mode). For other FE parameters the browser computes them, in about 20 s.
64 - The parametric body has no spatial shapes, so only the bridge moves.
087c169Physically simulated pizzicato double bass and an SF2 built from itJeremy Magland 66## Physics
68### Strings (`src/core/strings.ts`, `src/core/engine.ts`)
70Each string has two transverse polarisations: vertical (normal to the top) and lateral. The linear density is chosen so that the stiff open string's first partial is in tune. The core diameter sets the bending stiffness EI (times a rope-core flexibility factor) and the axial stiffness EA.
72**Modal form** (the default). The string is u(x,t) = w(t)·x/L + Σ qₙ sin(nπx/L), where w is the bridge notch displacement. The equations follow from the Lagrangian of string and body together, so the w″ mass coupling is exact. All notch displacements w⁺ (one per string and polarisation, at most 8) are solved each step from a small constant matrix, inverted once.
73- **Time stepping.** Each oscillator uses central differences with its stiffness replaced by (2/k·sin(ωk/2))². That makes every mode's frequency exact and the scheme stable below Nyquist.
74- **Damping per mode.** Valette's model: air viscosity (with diameter), viscoelastic δ·f², and a constant 1/Q floor (thermoelastic and winding friction).
75- **Geometric nonlinearity** (Kirchhoff–Carrier). The tension rises with ∫u_x² over both polarisations. It gives the pitch glide of hard plucks and couples the polarisations.
77**FD form** (`engine.stringModel = fd`). A finite-difference stiff string with Bilbao's loss σ₀ + σ₁β², fitted to the Valette damping by weighted least squares. The bridge-end node moves with the notch. Its force on the bridge (tension, bending shear, half a cell of mass) enters the same notch solve.
79### Right hand (plucking finger)
81- **Stick phase.** A pad (spring + dashpot, spread over the pad width by a raised cosine) is dragged at the pull speed. The pull direction is mostly sideways, angled slightly into the fingerboard.
82- **Release.** When the contact force reaches the release force (set by velocity), the string slides off the pad. The force falls to zero as cos² over the slip time, which scales as (10 N / F)^0.5. A harder pluck is louder and also brighter, and the tension modulation makes it go slightly sharp at first.
83- **Pluck point.** 30 cm from the bridge, moved toward the bridge for short stopped lengths.
85### Left hand (stopping finger)
87- **Fingering.** A note is played on the highest string whose open pitch is at or below it (lowest position). The notes below E1 are on a low-C extension.
88- **Finger damping.** The stopping finger is an implicit dashpot 12 mm from the stop. Open strings have none and ring longer.
89- **Sympathetic strings.** The other open strings are coupled through the bridge and ring along, partly damped by the player's hands. They also load the bridge, which matters for intonation (next item).
90- **Tuning by ear.** The bridge gives under the string: spring-like below the body resonances, so notes go flat, by up to 30 cents on low notes with the FE body. Near body resonances the shift is large and the fundamental splits into two beating peaks, because the two polarisations see different admittances. A player compensates by ear. The engine does the same with short quiet calibration renders: it adjusts all four open-string tensions (two passes), then the stopped length. Pitch is measured as the power-weighted centre of the split partial, in the output mix. Results are cached.
92### Body: parametric (`src/core/body.ts`)
94- **Signature modes.** A0 (air, about 61 Hz), T1 (about 104 Hz) and corpus modes up to about 350 Hz. Each has a frequency, Q, an effective mass at the bridge, a lateral/vertical coupling ratio, and a monopole volume per unit bridge displacement. Edit them in the panel.
95- **Statistical continuation above that.** Frequencies have the plate's modal density and Wigner (level-repulsion) spacing. Gaussian mode shapes at the two bridge feet have mean square 1/plate mass. The bridge's in-plane resonance (about 1.15 kHz) filters them; the notch sees the feet's translation, plus rotation × lateral position. Radiation follows from the plate's radiation efficiency, with random phase.
97### Body: finite elements (`src/fe/`, `npm run fe-body`)
99The FE body is computed from the outline (three bouts), rib depth, woods, bass bar, back bars, soundpost, f-holes and bridge.
101- **Top.** An orthotropic shallow shell (spruce, arched; bending plus Marguerre membrane coupling).
102- **Back.** A flat orthotropic maple plate with cross bars.
103- **Structure details.** An eccentric bass bar, the soundpost as a spring, and a 3-DOF bridge with rocking compliance. Rims are pinned, with rotational stiffness.
104- **Discretisation.** The strain energy is discretised on a grid, so K = BᵀDB is symmetric positive semi-definite by construction. Structural modes come from shift-invert Lanczos with spectrum slicing and skyline LDLᵀ.
105- **Air.** Cavity modes come from a finite-volume Laplacian. Each f-hole is an air plug (Rayleigh conductivity of a slot, corrected for the cavity near field).
106- **Coupling.** The structural–acoustic coupling is a symmetric modal formulation, solved densely.
107- **Damping.** Each coupled mode's damping is energy-weighted (top, back, bridge, air) plus viscous f-hole losses and radiation damping.
108- **Radiation.** A simple-source sum over top, back and plugs gives each mode's complex radiation coefficient at the mic.
109- **Above `fe.fmax`.** Statistical modes continue the FE body, matched to its last modes.
111The default body has A0 at 53 Hz, the first corpus modes at 93–132 Hz, and 804 FE modes up to 2.5 kHz plus statistical modes above (2274 in all).
113**Speed: mode thinning.** Above about 1 kHz the body's modes overlap heavily: half-power bandwidth × modal density is about 12 at 3 kHz. There the engine keeps every k-th mode with √k coupling. That preserves each band's mean admittance and radiated power, and leaves the overlap at about 3 (`engine.bodyOverlap`). It cuts the work 4×, and the band levels stay within the scatter of the full set.
115### Output
117- **Mic.** p = Σ (radRe·η̈ − radIm·ω·η̇) over the body modes, computed at the internal rate (2× oversampling for the SF2) and decimated.
118- **Pickup.** A bridge piezo: the strings' force on the bridge, vertical plus half the lateral.
119- **Why the default mix is mic 0.7 + pickup 0.6.** A real bass radiates its lowest fundamentals poorly: E1 sits below A0, where the body's monopole radiation falls at 12 dB/octave. So the mic alone is much brighter and thinner than GeneralUser's sample (spectral centroid about 280 Hz vs 70 Hz at E1). The pickup carries the fundamental, as in pickup and close-mic recordings. Set the mix to 1 / 0 for the pure far-field sound.
121## Verification
123`node scripts/test_engine.ts`:
125| Check | Result |
126|---|---|
127| Modal string, rigid bridge | Partials match n·f₀·√(1+Bn²) to 0.00 cents; decay rates match Valette's to 1% |
128| FD string | Partials within 1 cent; decays within 44% (the σ₀ + σ₁β² loss cannot follow Valette's near-linear law exactly) |
129| String on one body mode | Fundamental decay 0.576 /s vs 0.580 /s predicted (weak coupling, 1/Q = (2/nπ)·Z₀·Re Y) |
130| Stability | Hardest pluck (30 N), nonlinear, all strings: decays, no growth |
131| Tuning by ear, FE body | First partial within ±5 cents for E1 to A2 (up to −25 cents without) |
133`node scripts/test_fe.ts`: plate modes vs analytic within 0.21%, orthotropic within 0.46%, box cavity within 0.34%, Helmholtz resonator within 0.08%, and the sliced Lanczos solver against a dense solver to 7e-15.
135Against the reference (`npm run reference`, then `node scripts/render.ts 28:80 …` and `node scripts/compare.ts 28:80 …`), with the FE body at velocity 80:
137| | E1 | A1 | D2 | E3 | A#3 |
138|---|---|---|---|---|---|
139| t20 sim / ref (s) | 3.05 / 2.5 | 0.9 / 1.85 | 1.15 / 1.25 | 0.35 / 0.8 | 0.35 / 0.55 |
140| Early centroid sim / ref (Hz) | 80 / 71 | 80 / 89 | 143 / 130 | 164 / 210 | 230 / 270 |
142The reference is pitch-shifted, looped samples shaped by envelopes and filters, so its decays describe the SoundFont's envelopes, not a string. The simulation shows the two-stage decay of a real pizzicato: a quick drop as the bridge and body take energy from the low partials, then a long fundamental. Notes near strong body modes (open A, next to A0) lose energy faster, as on a real instrument. Above the middle of the range, the simulation decays faster than the reference.
144## Scripts
146| Command | What it does |
147|---|---|
148| `node scripts/render.ts [--params p.json] [--set path=value] note:vel …` | Renders to `renders/sim_N_V.wav` and prints diagnostics |
149| `node scripts/render_reference.ts [file.sf2] [--program 32] note:vel …` | Renders the reference to `refs/` |
150| `node scripts/compare.ts note:vel …` | Envelope, centroid, and partial levels and T60s, simulation vs reference |
151| `node scripts/build_sf2.ts [--params p.json] [--body body.json] [--out x.sf2] [--workers N]` | Builds the SF2 (parallel), with WAVs in `renders/sf2wav/` |
182eaafAdd a Physics 3D tab: slow-motion 3D replay of the simulationJeremy Magland 152| `node scripts/fe_body.ts [params.json] [out.json]` | Computes the FE body (`bodies/fe_default.json`) and its mode shapes for the 3D view (`bodies/fe_default_shapes.bin`); scripts cache bodies for other params in `bodies/fe_<hash>.json` |
087c169Physically simulated pizzicato double bass and an SF2 built from itJeremy Magland 153| `node scripts/test_engine.ts`, `node scripts/test_fe.ts` | Verification |
155## Files
157| Path | Contents |
158|---|---|
159| `src/core/params.ts` | All parameters, defaults, UI descriptors |
160| `src/core/types.ts` | Body modes, admittance and radiation transfer |
161| `src/core/strings.ts` | String constants, fingering, Valette damping, pluck force by velocity |
162| `src/core/engine.ts` | The time-domain engine (modal/FD strings, notch solve, finger, tuning by ear, mode thinning) |
163| `src/core/body.ts` | Parametric body and the statistical modes |
164| `src/core/sf2.ts` | SF2 layout, sample processing and leveling, SF2 writer (browser and Node) |
165| `src/core/dsp.ts` | Decimation, WAV, FFT, analyses |
166| `src/core/reference.ts` | Reference rendering (spessasynth_core) |
182eaafAdd a Physics 3D tab: slow-motion 3D replay of the simulationJeremy Magland 167| `src/fe/` | The FE body (see above); `shapes.ts` holds the mode shapes for the 3D view |
087c169Physically simulated pizzicato double bass and an SF2 built from itJeremy Magland 168| `src/app/` | The browser app (`main.ts`, `worker.ts`, `plots.ts`, `synth.ts`) |
182eaafAdd a Physics 3D tab: slow-motion 3D replay of the simulationJeremy Magland 169| `src/app/viz/` | The Physics 3D tab: `index.ts` (recording, playback, mode explorer), `scene.ts` (three.js scene), `traces.ts` (time plots) |
171## Limitations
173- **Pizzicato only.** No arco, slap, or string–fingerboard contact (buzz).
174- **Body.** Rigid ribs and neck. No tailpiece, afterlength, endpin, or player's body.
175- **FE body.** Its rim is a staircase on the grid, and its f-holes are straight slots. Radiation is a free-field simple-source sum, with no scattering by the body. See the notes in `src/fe/index.ts`.
176- **Parametric body.** Its signature modes are informed guesses guided by published double-bass measurements, not measured values. Use the FE body or edit them.
177- **FD string damping is approximate** (see Verification).
178- **The SF2 is a sampled snapshot.** Between sample roots the samples are pitch-shifted (±1 semitone). Key release is an envelope, not the string being damped.