Show HN: Karplus-Strong Guitar Synthesizer in JavaScript
amid.fish
amid.fish
In fact it forms the basis of a large branch of DSP for sound effects and synthesis, physical modeling. Of course many techniques can be used in physical modeling, but often it's actually delay lines all the way down, and delay lines are really a generalization of the KS algorithm with a better interpolation. Many crucial effects in digital music such as chorus, phaser/flanger, and algorithmic reverbs are also just delay lines fed into each other.
Then there are masters of the genre that create jaw-dropping effects and instruments by making massive use of delay lines - I'm looking at xoxos:
It's starkly different from "core CS" because almost everything operates on arrays and pure functions. Yet at the same time it presents an immense design space for both software engineering and UX - most of the "secret sauce" in an audio DSP product comes from exposing the right parameters in the right combinations. A low level tool like Max/MSP or PD leads to a different workflow from a "pick the presets" VST plugin, in the same way that programming languages are targeted against certain problem domains.
In the early 1980's, the big excitement in Stanford EE and CS was that you could take the new VLSI course and they'd actually fab your chip for you if you made it to the end of the course. (Actually, each student project just got a small section of the whole mask; enough chips were manufactured so that everyone could get a few, and they'd just wire the pins to different pads for each particular project's ICs.) I remember Alex showing off his first working Digitar chip to my officemate at the time, Danny Sleator (who is also credited in the paper), using the ice cube technique.
Are the asm.js annotations required for this to work in Firefox? I thought the primary use case for asm.js was converting low-level code into something that could run efficiently in JS, and not so much for handwritten JS. And the demo seems to work fine in Chrome, which has no optimizations specific to asm.js that I know of.
https://github.com/mrahtz/javascript-karplus-strong/blob/mas...
Something like:
* model a room
* model an 'instrument'
* place a virtual microphone
* hit/trigger the instrument model
* render sound waves produced by the model and sample the incoming waves at the microphone
In my mind this could be doable with GPUs.There's a lot of non-linearity in the physics, and any rendered model has to allow for that. So it's a long way short of real time synthesis, even with a GPU.
Karplus-Strong is the entry-level version of various complex waveguide and resonator models, and the technology has been used in commercial products for more than twenty years now.
The commercial problem is that for many applications, multi-sampling sounds better. Most musicians don't want experimental sounds, and those who do prefer other ways to make unusual noises - preferably more intuitive ways that are easier to control.
So there's limited commercial demand for waveguide modelling, and no demand at all for a full-fat 3D rendered synthesis engine.
The setting that sounded best to my ear was:
Character variation 0.7
String damping 0.7
String damping variation 0.15
Pluck damping 0.5
Pluck damping variation 0.40
String tension 0.0
Stereo spread 0.1
String damping calculation Magic
Body resonation None
Simple Precache time 11.3 seconds
Simple additive synthesis usually falls short for something like a piano, too, since there are a lot of factors that influence the frequency content of a single struck note. This was posted a while ago, describing Pianoteq's approach to piano modeling: https://www.pianoteq.com/tutorials?play=modelling
Edit: There's this too by the inimitable Iñigo Quilez: https://www.youtube.com/watch?v=ogFAHvYatWs And here's a tool which you can play with: http://www.iquilezles.org/apps/soundtoy/index.html
_______________
there's also 3 good basic textbooks on synthesis/sound design by Rick Snoman (Dance Music Manual), Martin Russ and Brian Shepherd that have specific recipes ("detune a saw and square by 3 cents...)
___________
and if you don't have a synth, ask around for somebody that has Logic Pro X (several good synth models included) or Ableton with VST or AU's installed (you have to pay e.g. $100 for Analog unless you have Ableton Suite).
The description begins on p.46 of their article:
http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.144...
It is really cheap to implement -- you can use a shift-xor random bit generator to get the blend factor of ½ that they mention. The whole thing was about 10 8086 instructions, as far as I recall (it's been twenty years since I played with it).
Here's a paper with more extensions to the Karplus-Strong algorithm (+ analyses thereof):
http://www.music.mcgill.ca/~gary/courses/papers/Jaffe-Extens...
Here's an anthology from 1992, which is where I learned about Karplus-Strong:
http://www.amazon.co.uk/Music-Machine-Selected-Readings-Comp...
http://ems.music.uiuc.edu/beaucham/papers/JAES.10.95.pdf
(I haven't tried it out so I don't know how good it sounds.)
There's also a master's (or phd?) thesis from DIKU (Datalogisk Institut ved Københavns Universitet) from 15-20 years back where a guy "rewired" sounds played on one instrument to sound like they were played on other instruments. I saw his presentation/demonstration back then, and it sounded pretty okay. It's in English and should be available somewhere on DIKU's website. Darned if I can recall the title or the author, though.