SPB Git

Repository Public

README.md 3.1 KB

# Acoustics of the Sonata instruments

Every engine in crates/sonata-instruments is described here: the equations it implements, what it approximates, and where the approximation stops being valid. None of these engines is an exact physical simulation. They are physically informed signal models chosen for stable, in-tune, real-time behaviour.

Model File Method Self-oscillating?
plucked_string, bass (electric) strings.md Extended Karplus-Strong waveguide passive loop
bowed_string strings.md Two-segment waveguide + friction curve yes
piano piano.md Modal sum of stiff-string partials no (struck)
clarinet winds.md Waveguide bore + reed table yes
flute winds.md Forced jet into a waveguide tube no, excitation prescribed
brass winds.md Forced lip valve into a waveguide tube no, excitation prescribed
modal_percussion, kick, snare, hihat percussion.md Modal sums, swept sine, filtered noise no
organ, synth, fm, bass (synth), voice, patch synthesis.md Additive, subtractive, FM, formant, graph n/a

# Conventions

  • Sample rate fs, fundamental f0, period in samples P = fs / f0, w0 = 2 pi f0 / fs.
  • "T60" is the time for a 60 dB decay. A per-sample gain g gives T60 = -6.908 / (fs ln g).
  • Levels: one note at velocity 1 on the default preset peaks between -24 and -3 dBFS (test every_preset_sounds_is_finite_and_below_full_scale); every preset stays below 0 dBFS.

# Measured tuning (48 kHz, default presets, vibrato and detuning off)

Measured by cargo test -p sonata-instruments --test engines -- --nocapture (lines TUNING), at the bottom, middle and top of each range. Tolerances enforced by the tests are in parentheses.

Model Low Middle High Tolerance
piano (fundamental, spectral peak) +0.00 -0.00 -0.00 2 cents
plucked_string +0.01 +0.03 +0.02 3
bowed_string -0.07 -0.03 -3.59 6
flute +0.00 +0.00 -0.00 2
clarinet +0.23 +1.03 +0.84 4
brass -0.01 +0.00 -0.00 2
organ (8' only) -0.04 -0.00 -0.01 2
bass +0.00 +0.00 +0.01 3
synth, fm, voice within 0.13 2
modal_percussion (fundamental) -0.00 -0.00 -0.00 2

At 44.1, 96 and 192 kHz the tests allow twice these tolerances; examples/calibrate.rs prints the full tables. The bowed string is the only engine with a measured correction table (TUNING in bowed.rs): its friction loop plays up to 12 cents sharp above MIDI 88 without it.

# Reproducing

bash
cargo test -p sonata-instruments                      # all behaviour tests
cargo run --release -p sonata-instruments --example audition   # WAV files in build/audition/
cargo run --release -p sonata-instruments --example calibrate  # tuning tables
cargo run --release -p sonata-instruments --example bench 16   # cost per engine
Files main
Menu

Theme