SPB Git

Repository Public

strings.md 5.2 KB

# Strings

# The ideal string

A flexible string of length L, tension T and linear density mu, fixed at both ends, vibrates at

f_n = n / (2 L) * sqrt(T / mu),   n = 1, 2, 3, ...

Its motion is the sum of two waves travelling in opposite directions at c = sqrt(T / mu) (d'Alembert). A digital waveguide stores those travelling waves in delay lines; the round trip of 2L / c seconds is P = fs / f0 samples. Sonata does not ask for L, T or mu: the note gives f0 directly, so no dimensionally inconsistent physical parameter can be entered.

# plucked_string and electric bass: extended Karplus-Strong

The loop (StringLoop in engines/common.rs) is

y[n] = delay(D)                       (4-point Lagrange read)
l[n] = (1 - b) y[n] + b y[n-1]        (loss filter, 0 <= b <= 0.5)
d[n] = allpass(l[n]; a)               (dispersion, a <= 0)
write( g d[n] + excitation[n] )

Tuning. The loop resonates where its total phase delay is a whole number of samples per period. The filter delays at the fundamental are computed in closed form and subtracted:

D = P - tau_loss(w0) - tau_ap(w0)
tau_loss(w) = atan2(b sin w, 1 - b + b cos w) / w
tau_ap(w)   = -arg[(a + e^{-jw}) / (1 + a e^{-jw})] / w

Measured error of the engine: +0.01 to +0.03 cent at MIDI 30, 62 and 94 (the unit test string_loop_is_in_tune... allows 1.5 cents from 82 Hz to 2.1 kHz, with and without dispersion).

Decay. The fundamental must lose 60 dB in T60 seconds, i.e. a factor 10^(-3 / (f0 T60)) per period. The loop gain is that factor divided by the loss filter's and the interpolator's magnitude at w0, and never above 1 so that the loop stays passive:

g = min(1, 10^(-3 / (f0 T60)) / (|H_loss(w0)| |H_lagrange(w0)|))

When g clips at 1 (strong damping filter on a high note) the note decays faster than requested. damping maps to T60 = (0.06 / damping) sqrt(220 / f0) seconds.

Excitation. A pluck releases the string from a triangular displacement with its apex at the plucking point p (fraction of the length). Its harmonic amplitudes are sin(n pi p) / n^2: harmonics with a node at p are absent (test: with p = 0.35, harmonic 3 is weaker than harmonic 2). One period of that triangle (zero mean) is fed into the loop, blended with its derivative (a rectangular pulse, 1/n roll-off) for a harder plectrum, then low-passed according to hardness and velocity. strike injects a half-sine velocity pulse and its inverted reflection from the near end.

Stiffness. A real string is stiff: f_n = n f0 sqrt(1 + B n^2). One first-order allpass in the loop delays high frequencies less than low ones, which stretches the partials. This reproduces the direction of the effect, not a given B; a faithful dispersion filter needs several allpass sections designed for each note.

Body. resonance body adds five two-pole resonators (98, 204, 287, 414, 592 Hz, the order of magnitude of a guitar's air and top-plate modes). resonance modal(frequencies: [...]) replaces them by up to 16 user modes. They are parallel resonators after the string, with no coupling back into it.

Electric bass. The same loop, then a pickup: a string point at fraction q senses the wave and its reflection, y[n] - y[n - qP], a comb with notches at multiples of f0 / q; then a one-pole tone control and a tanh amplifier.

Validity. One polarisation, no string-body coupling, no fret or finger noise, linear string (no tension modulation, so no pitch glide on hard plucks).

# bowed_string: friction waveguide

Two delay lines model the string on each side of the bow, at fraction beta from the bridge. With v_b the bow velocity and v_s = v_bridge + v_nut the incoming string velocity at the bow:

dv = v_b - v_s
mu(dv) = min(1, (|slope (dv + 0.001)| + 0.75)^-4),   slope = 5 - 4 pressure
v_out  = dv mu(dv)       added to both outgoing waves

mu is 1 while the string sticks to the hair (small dv) and falls quickly when it slips: a memoryless approximation of the friction curve (after McIntyre, Schumacher and Woodhouse, in the form popularised by the Synthesis ToolKit). The bridge reflects through a one-pole low-pass with gain -0.95; the nut reflects with -1. The loop delay is P minus the low-pass's phase delay, split beta : 1 - beta.

Behaviour that is modelled: the Helmholtz stick-slip motion and its sawtooth-like spectrum; too little pressure gives a weak surface sound; pressure and speed trade off; bow.position near the bridge brightens the tone.

Behaviour that is not: hysteresis of the friction (no flattening with pressure), torsional waves, bow-hair compliance, a finite bow width. At high bow speed on short strings the model jumps to the octave: above MIDI 82 the engine lowers the bow speed, and a measured correction (TUNING) removes a residual sharpness of up to 12 cents. Extreme bow.pressure values can still leave the Helmholtz regime; the output stays finite and bounded (test extreme_parameter_values_stay_finite_and_bounded).

The body is six parallel resonators scaled by body.size; players runs up to four independent strings per note with their own tuning, vibrato phase and pan (a section).

Files main
Menu

Theme