0
$\begingroup$

I'm trying to build a web app which plays a sequence of notes. The notes should have a timbre of different instruments. For now I only concentrate on a guitar synthesis. I'm using Web Audio API for this task, since I want to do it in a browser.
I have all of the notes beforehand, so translating that into a standalone frequency is not a problem, I then generate samples as a sine wave for that frequency, add N number of harmonics to it and add LFM for a little bit of "wavy" effect to the amplitude of the sound.
The filters I've tried to add to make the sound more "natural" are: ADSR, a little compression and a low pass filter, but the sound does not resemble any instrument, it still sounds like a cheap synthesizer from 20-30 years back and it sounds very "plastic".
I do not need the sound to be exactly as the real guitar, that's probably not possible anyway.
What steps would you suggest to take in order to get close to a real guitar sound given only the duration of the specific fundamental frequency? Would it be easier to start from FFT components rather than samples, for example somehow generating real and imaginary numbers, apply some function to it and then reverse them back to samples to play them?

$\endgroup$
1
$\begingroup$

In essence you are trying to build an audio synthesizer that creates sounds with a given pitch. Over the last 50 years there have been dozens of technologies developed to do this: you can start here with an overviews: https://en.wikipedia.org/wiki/Synthesizer

To get reasonably natural sounding instrument sound, your best bet is probably to build a sample player. These are based on sampling the actual instrument (typically at a few different pitches and/or play modes) and then creating the notes by pitch shifting, looping and dynamic filtering, etc. of the samples.

$\endgroup$
7
  • $\begingroup$ looks like Karplus-Strong synthesis is what I am looking for, I've found an implementation of it in JS as well github.com/mrahtz/javascript-karplus-strong , I'll try it out and maybe apply some wave shapers for effects like distortion, thanks. If you edit you answer to include references to physical modelling synthesis and Karplus–Strong string synthesis I'll mark this answer as the accepted one. $\endgroup$ Aug 27 at 12:56
  • $\begingroup$ you might get a "plucked string" sound with Karplus-Strong, but i wouldn't necessarily call it a "guitar". now, like sampling keyboards have done since the 1980s, you can also record guitar notes at different pitches and, for each recorded note, define loop points and from that get a sampled guitar sound. it will still sound like a keyboard, not guitar, when it is played. $\endgroup$ Aug 27 at 13:51
  • $\begingroup$ @robertbristow-johnson, as I mentioned, I do not need an "ideal" guitar sound, plucked string will suffice. As for recording, I would like to stick to pure synthesis, due to a couple of reasons: it's fun, it's unexplored (there's a lot of sites which use presampled sounds), downloading samples from the network is slower than generating them on a client size (the browser) + I plan to expand it by adding other instruments, which I do not physically possess. $\endgroup$ Aug 27 at 14:58
  • $\begingroup$ Whatever works for you. It's certainly NOT unexplored, people have tried for the last 40 years , it's just difficult and doesn't sound particularly good unless you put a lot of work into it. $\endgroup$
    – Hilmar
    Aug 27 at 15:10
  • $\begingroup$ Okay @IO, the two things you need to cook up will be a good random number generator to fill the delay buffer with, and then you need to understand how to use a first-order APF to realize a fractional delay. Also you need to account for the delay of your feedback LPF (which will cause the higher harmonics to decay at a faster rate than the lower harmonics). The entire loop delay is the reciprocal of your fundamental frequency. $\endgroup$ Aug 27 at 16:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.