Hacker News new | ask | show | jobs
by Stenzel 2963 days ago
The distortion sounds like it is applied to individual strings, if it were applied after summing, it would not only resemble more a real electric guitar, but also sum- and difference frequencies of detuned strings would be audible much nicer as beating.

Furthermore, the intervals E-A/A-D/D-G and B-E are not exactly perfect fourths, they should be equal tempered. Luckily the difference is almost negligible for the fourth, the perfect interval would be 4/3 = 1.3333 versus 2^(5/12) = 1.3348 for equal temperament. The interval G-B however is a major third, here the perfect interval is 5/4 = 1.25 while equal tempered is 2^(4/12) = 1.26 Those minor errors accumulate if one string is tuned based on the preceding one, the interval from lowest to highest strings can be calculated:

(4/3)^4 * 5/4 = 3.95 for perfect intervals, 2^(4 * 5/12) * 2^(4/12) = 4 for equal temperament.

The highest string should be exactly two octaves (= a factor of 4) above the lowest one, so the equal temperament should be preferred. A practical result is that tuning a guitar using only intervals of adjacent strings will never really converge to the ideal result, so tuning (fretted) octaves and flageolets should be used in addition.

2 comments

The distortion sounds are being distorted on individual strings, as opposed to after summing. If you look at the credits, and follow the link to the sound sources, you can find the files used. If you listen, you'll be able to match them up. While I agree that the distortion should happen after summing, I suspect the playing and summing of individual already-distorted string sounds was done because that's what could be implemented simply and easily. Applying distortion after summing may well require more extensive coding, or stuff that's computationally intensive enough to slow down the browser (I don't know this for certain, I'm guessing).

I'm not faulting the author for this, I probably would have done the same.

Now that I type this out, I find myself curious just how much work it would take to implement a software-modelled distortion in the browser. I guess that's another entry for my list of "Hey, wouldn't it be neat if I could do $FOO" type projects.
Not actually that hard. You want a WaveShaperNode. Of course, tuning the curve and other parameters so it sounds _good_ is nontrivial.

[1]: https://developer.mozilla.org/en-US/docs/Web/API/WaveShaperN...

Thanks for this great feedback. I hadn't considered the difference between distortion in each of the strings vs applied overall, but that makes sense.

[edit] as korethr described above, I chose to implement it this way because of the samples that I was working with