/ music / acoustic-base
Sign in
music / acoustic-base
acoustic-base / README.md
13.6 KBPreviewCodeBlameHistoryRaw

acoustic-base#

A 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.

Steel 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.

npm install
npm run dev          # the app, http://127.0.0.1:8023
npm run build-sf2    # acoustic-bass.sf2 (+ acoustic-bass.json, the params used)

The 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.

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.

The app#

Physics#

Strings (src/core/strings.ts, src/core/engine.ts)#

Each 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.

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.

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.

Right hand (plucking finger)#

Left hand (stopping finger)#

Body: parametric (src/core/body.ts)#

Body: finite elements (src/fe/, npm run fe-body)#

The FE body is computed from the outline (three bouts), rib depth, woods, bass bar, back bars, soundpost, f-holes and bridge.

The 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).

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.

Output#

Verification#

node scripts/test_engine.ts:

Check Result
Modal string, rigid bridge Partials match n·f₀·√(1+Bn²) to 0.00 cents; decay rates match Valette's to 1%
FD string Partials within 1 cent; decays within 44% (the σ₀ + σ₁β² loss cannot follow Valette's near-linear law exactly)
String on one body mode Fundamental decay 0.576 /s vs 0.580 /s predicted (weak coupling, 1/Q = (2/nπ)·Z₀·Re Y)
Stability Hardest pluck (30 N), nonlinear, all strings: decays, no growth
Tuning by ear, FE body First partial within ±5 cents for E1 to A2 (up to −25 cents without)

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.

Against 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:

E1 A1 D2 E3 A#3
t20 sim / ref (s) 3.05 / 2.5 0.9 / 1.85 1.15 / 1.25 0.35 / 0.8 0.35 / 0.55
Early centroid sim / ref (Hz) 80 / 71 80 / 89 143 / 130 164 / 210 230 / 270

The 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.

Scripts#

Command What it does
node scripts/render.ts [--params p.json] [--set path=value] note:vel … Renders to renders/sim_N_V.wav and prints diagnostics
node scripts/render_reference.ts [file.sf2] [--program 32] note:vel … Renders the reference to refs/
node scripts/compare.ts note:vel … Envelope, centroid, and partial levels and T60s, simulation vs reference
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/
node scripts/fe_body.ts [params.json] [out.json] Computes the FE body (bodies/fe_default.json); scripts cache bodies for other params in bodies/fe_<hash>.json
node scripts/test_engine.ts, node scripts/test_fe.ts Verification

Files#

Path Contents
src/core/params.ts All parameters, defaults, UI descriptors
src/core/types.ts Body modes, admittance and radiation transfer
src/core/strings.ts String constants, fingering, Valette damping, pluck force by velocity
src/core/engine.ts The time-domain engine (modal/FD strings, notch solve, finger, tuning by ear, mode thinning)
src/core/body.ts Parametric body and the statistical modes
src/core/sf2.ts SF2 layout, sample processing and leveling, SF2 writer (browser and Node)
src/core/dsp.ts Decimation, WAV, FFT, analyses
src/core/reference.ts Reference rendering (spessasynth_core)
src/fe/ The FE body (see above)
src/app/ The browser app (main.ts, worker.ts, plots.ts, synth.ts)

Limitations#

↑↓ move↵openescclose