Re:Show HN: Koelsynth – a simple FM synthesis library
by atoav on Monday November 13, 2023 @02:25AM
(#38247827)
The typical way FM synths (and for example function generators) generate a sine wave would be DDS (Direct digital synthesis).
You basically just have an array with all the values of a sine inside (or a quarter of a sine if you want to save memory) and then you jump through that array based on a phase accumulator (basically a counter). The amount by which you increment that phase accumulator (=phase step) determines the pitch of the resulting sine wave that this lookup gives you.
This operation is quite cheap, I once made a osciallator with 9 of these on an Arduino Nano.
Now the clou is that you could just add some amount of the result of another of those sine lookups to the phase accumulator, which results in the typical FM sound.
You basically just have an array with all the values of a sine inside (or a quarter of a sine if you want to save memory) and then you jump through that array based on a phase accumulator (basically a counter). The amount by which you increment that phase accumulator (=phase step) determines the pitch of the resulting sine wave that this lookup gives you.
This operation is quite cheap, I once made a osciallator with 9 of these on an Arduino Nano.
Now the clou is that you could just add some amount of the result of another of those sine lookups to the phase accumulator, which results in the typical FM sound.