Synthesizing a Plucked String Sound with the Karplus-Strong Algorithm
blog.demofox.org
blog.demofox.org
[1] http://chuck.stanford.edu/
[2] http://chuck.stanford.edu/doc/examples/deep/plu.ck
edit: hacked together a string plucking thing here: https://www.shadertoy.com/view/ldVSzd
modify the coefficient inside pluckPoint from 0.5 to 0.01 and hear the difference in timbre.
[1] https://ccrma.stanford.edu/~jos/pasp/Commuted_Synthesis.html
Original author's demo: https://www.shadertoy.com/view/MdyXRd
http://www.folklore.org/StoryView.py?project=Macintosh&s...
Maybe a small nitpick, but by using the filter described in this article (taking the average with the next sample), the frequency isn't exactly equal to sample rate / samples per buffer, as the filtering method is asymmetric, and it shifts the signal half a sample to the left every pass. With a more symmetric method, like replacing each value by the average of the surrounding values, that doesn't happen. It may sound pedantic, but the difference is quite clear audible
ListPlay@ Flatten@ NestList[
0.996*#& /@ MovingAverage[# ~Join~ {First[#]}, 2]&,
RandomReal[1.0, {80}], 100]
https://i.imgur.com/aIufLHn.pngTimbre is not the same as fundamental frequency. A guitar, a piano or a violin playing the same note, say, a middle C, will have wildly different timbres, but they should have the same fundamental frequency (261 Hz). That's what allows them to play together in orchestras. However, if you use, say 50 samples per buffer and a sample rate of 8192, with your original filter you won't get a frequency of 163.84 Hz, but 8192/49.5 = 165.49 Hz. That might look like a small difference, but to our ears it sounds wildly out of tune. You can use a tone analyzer app to verify it.
Thanks for the shout out :) I know I'm nitpicking :p
0: like for example, replacing with the average of the two surrounding values
Here's a nice web audio demo: https://chinpen.net/castro/ that uses this js lib: https://github.com/mrahtz/javascript-karplus-strong/
The basic principle was really the same with the circular buffer and a filter, the combo of which can be understood as a long IIR filter. The fancier parts included tunable harmonic bandpass filter (in place of OP's two sample average), and a fractional delay filter for fine-tuning.
By changing the parameters on the bandpass filter it could be made to sound anything from a plucked string to a church bell (minus the reverb since we didn't have that). We were quite surprised how good it sounded.
Unfortunately I seem to have misplaced all the materials related to that course. The hardware we implemented it for was some exotic audio DSP, but we had a matlab model that could produce output samples. If only I could find it.. =/
http://falstad.com/loadedstring/
A more accurate (?) version of a loaded string. Requires Java.
This guy also has bunch of other really cool stuff. Go to the root of that website.
As the article says this is a good analogue for how a lot of musical instruments work. A string is a resonator, and plucking it gives it a wideband excitation.