There is a command-line piano app in the examples directory if you want to play with it. Here is the link: https://github.com/charstorm/koelsynth/tree/main/examples/si...
My next target is to attach this to some kind of physics simulation - like a bunch of balls moving around in a box with some internal walls. When the ball hits certain trigger points, it produces the sound.
Have you tried to port it to WASM?
Python can also call the wasm with wasmer
I ported https://github.com/chaosprint/glicol for my Python audio project using the same method
for your physics idea, with wasm, perhaps it can be something like this?
I am thinking of moving the core to WASM. But I may have to drop the python part and make the calls directly from javascript.
Glicol looks impressive. I will try it out.
I added a music block to Goober Dash level editor:
https//gooberdash.winterpixel.io/
When your Goober, or a physics crate, hits the music block, it plays a note. I didn't release this branch yet. Can I use the piano notes from this lib in our game? I wouldn't be adding the generator code to the game, I just need sound files.
Only the code has license, but I have no intention to enforce it.
I am playing gooberdash now.
However, Wikipedia has a better diagram and explanation of ADSR:
I needed that image to explain the parameters in the ADSR configuration I used in the project. Mainly the slevel1 and slevel2 which captures the slow decay during sustain. Most ADSR diagrams show sustain as a constant which didn't really sound that natural when I tested for my projects.
Does that also make for relatively simple software FM 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. So you basically add that phase step repeatedly and read out the current sine value at the current phase accumulator/index with a timer interrupt. Th
This operation is quite cheap, I once made a osciallator with 9 of these on an Arduino Nano (fixed point numbers tho).
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. Technically this is actually phase modulation, but hey technically the most famous FM synth uses also phase modulation.
In the DX7 it was done on custom digital circuitry, but modern CPUs are just as happy to do a few additions and a table lookup once in a while.
In the github section the author somewhat alludes to this : "Next, there is "subtractive" synthesis (not really a surprise after "additive" synthesis, is it?). It involves taking a waveform with many harmonics (triangular wave, sawtooth wave, etc) and using a time-varying filter to remove the higher harmonics. I tried that too once, but it wasn't great either, at least for the effort involved in coding and tweaking the parameters."
Subtractive synthesis is still musically useful, because most musical instruments are harmonic or almost harmonic, but tuned percussion is a notable exception. It's very difficult to get a good bell sound out of subtractive synthesis. FM can produce inharmonic sounds, where the higher harmonics are at non-integer multiples of the fundamental. It's much easier to get good bell/chime sounds out of FM synthesis.
And the "almost harmonic" instruments are very popular (all plucked or hammered string instruments, with the inharmonicity more pronounced with thicker strings, so especially bass and piano). By adding a little inharmonicity, FM synthesis can produce more realistic versions of these sounds than subtractive synthesis.
Additive synthesis can also produce inharmonic sounds, but this requires an oscillator for each harmonic, so back when FM synthesis first hit the market this was unreasonably expensive.
Just filtering frequencies isn't that difficult, but to get a digital filter sounding equivalent to a specific analog audio filter is an art. There's an entire industry trying to recreate the 'character' of certain imperfections found in old synthesizers. Some FM synthesizers also have subtractive filters. There are even analog synthesizers with FM so it's not an either/or.
Subtractive synthesis didn't work that well for me either. I believe my implementation of the variable cut off lowpass filter had something to do with it.
FM Synthesis worked reasonably well without much effort. Implementation was rather straightforward.