Lesson 9
Physical modelling
Every method so far has described a spectrum, whether by naming every partial, generating them with a nonlinearity, or storing them in advance. This one describes no spectrum at all. It describes an object, and lets the spectrum be a consequence.
The change of question
Additive asks what partials the sound has. FM asks what arrangement of oscillators would produce them cheaply. Wavetable asks which stored spectrum is closest. All three take the spectrum as the thing you specify.
Physical modelling asks a different question entirely: what is the thing that made this noise, and what happens if I simulate it? The spectrum then arrives on its own, as an output, and often you could not have written it down in advance even if you had wanted to.
The simplest useful example is a plucked string, and it is startlingly small.
A string is a delay line
A disturbance on a real string travels along it, reflects off the end, comes back, reflects off the other end, and arrives where it started slightly quieter than it left. That round trip takes a fixed time, and it repeats.
The digital version is exactly that sentence. Take a buffer. Read out of one end, write back into the other, and let it circulate:
- The length of the buffer is the round trip time, so it is the pitch. A loop of 218 samples at 48 kHz repeats 220 times a second, and that is a note.
- A gentle lowpass filter in the loop is the string losing energy, and losing it faster at high frequencies than at low ones, because that is what real materials do.
- A burst of noise to start it off is the pluck.
That is the whole algorithm. Karplus and Strong published it in 1983, and the striking thing is what it does not contain: no oscillator, no frequency, no partial, no spectrum. Just a length, a filter and a shove.
A delay line, plucked
Nothing below describes a spectrum. Watch one appear anyway.
Measured spectrum, with markers at whole multiples of the pitch
Press play to see the trace
- Pitch
- 196.0 Hz
- Delay line
- 244.9 samples
- Which is
- 5.10 ms
- Partials specified
- 0
The delay line is 244.9 samples long, which at 48,000 Hz is one period of 196.0 Hz. That single number is the whole of the pitch control: there is no oscillator here and no frequency anywhere in the loop, only a length. Plucking at one 5th along puts the pluck on a node of every 5th harmonic, so those are missing from the spectrum above.
Where the harmonic series came from
The markers on that spectrum sit at whole multiples of the pitch, computed from the pitch alone. The measured peaks land on them. Nobody put them there.
A loop of length L can only sustain a frequency whose period divides L exactly. Anything else arrives back out of step with itself and cancels within a few round trips. What survives is 1/L, 2/L, 3/L and so on: the harmonic series, not as a design decision but as the only thing the loop is capable of holding.
That is the same reason a real string produces one, which is the point. Foundations lesson 2 derives it from the physics; this lesson gets it for free by simulating the physics rather than the result.
The controls are the object, not the sound
Lesson 7 ended on FM being hard to steer, because its parameters do not map onto anything a person can picture. Physical modelling is the opposite case, and the contrast is worth drawing sharply.
Damping is how dead the string is. Turn it up and the high partials die first, so the note darkens as it decays, which is the per-partial envelope behaviour that additive had to buy sixty-four envelopes for. Here it is one number, and it is the same number the physics uses.
Pluck position is where you hit it. This one is worth playing with: you cannot excite a harmonic that has a node where you plucked, so plucking at the halfway point removes every even harmonic, at a third removes every third, and near the bridge removes almost nothing and sounds thin and bright. That is not an effect applied to the sound. It is a consequence of where the energy went in, and it is why a guitar picked near the bridge sounds the way it does.
There is a third control this figure does not have, and it is worth saying why. A real string resists bending, which makes high frequencies travel slightly faster, which stretches the partials apart so they are no longer quite whole multiples. That is why pianos are tuned with stretched octaves: the instrument is not harmonic, so tuning it as though it were sounds wrong.
A stiffness control was built for the figure and then removed, because measuring it showed it did nothing. Dispersion of that kind is usually modelled with allpass filters in the loop, and an allpass of the order used here has very nearly constant delay across the first eight harmonics of a low note - so it moves them all together and leaves the ratios alone. Rendered offline against the actual processor at three settings, the partials came back as 1, 2, 3.001, 4.001, 5.001 every time. Shipping a knob that looks like it models piano inharmonicity and does not seemed worse than not having one, and doing it properly needs a much higher-order dispersion filter than a forty-line demonstration should carry.
Waveguides, and the rest of the orchestra
A single delay line with a filter is a plucked string. The general technique is called digital waveguide synthesis, developed largely by Julius Smith at Stanford, and it extends the same idea in a fairly obvious direction.
Use two delay lines instead of one, carrying waves in opposite directions, and you have a proper model of a medium rather than a loop. Join several of them at scattering junctions, which split an incoming wave according to how the impedance changes, and you can model a tube that widens, a bore with tone holes, or a string coupled to a soundboard.
Replace the noise burst with a continuous nonlinear exciter and the plucked instruments become bowed and blown ones. A bow is a friction model that grips and slips; a reed is a valve that closes as the pressure across it rises. Both feed energy in continuously and both are only a few lines, and both produce the characteristic behaviour of the real instrument, including the awkward bits: a bowed string model will squeak if you bow it badly.
What it costs, and what it cannot do
It is extraordinarily cheap. A plucked string is a buffer, one multiply and one add per sample, and it produces a spectrum that additive would need dozens of oscillators for. Cheaper than FM, and with controls that make sense.
The costs sit elsewhere. The excitation matters enormously, and it is the hard part: the loop is easy and the noise burst here is crude, while a convincing piano needs a hammer model with felt that stiffens as it compresses.
It is hard to make it do anything unphysical. That is a real limitation and not only a virtue. Subtractive synthesis will happily make a sound no object could produce, which is frequently the point of using a synthesizer. A physical model tends to sound like a thing, and if you want it to sound like no thing at all you have to fight it.
And it can fall over. A feedback loop with a gain slightly above one does not produce a slightly louder note, it produces an exponentially growing one. Stability is a genuine design constraint here in a way it never was for the earlier methods, all of which are incapable of blowing up.
One implementation note, because it is the only place in this course where the platform actually got in the way. A feedback loop built from stock Web Audio nodes must hold at least one render quantum, 128 samples, because that is the granularity the graph runs at. That is 2.90 ms at 44.1 kHz, so the shortest loop such a graph can close is one period of about 345 Hz, or F4. Every note above that would come out at the wrong pitch. The figure above therefore runs in an AudioWorklet, where the loop is an array index and the limit does not exist. The processor is served as a plain file and is about forty lines; it is worth reading if you want to see that there is genuinely nothing else in there.