
Libfmsynth: a C library which implements an FM synthesizer - vmorgulis
https://github.com/Themaister/libfmsynth
======
exDM69
Just as a point of comparison, here's an FM/AM modulated synth I wrote some
years ago [0]. The version linked here is written in 250 lines of plain old C
code with floating point arithmetic and not a single thought has given to
performance (but it runs fast enough).

Originally, this synth was designed for a demoscene 4k intro, which was never
finished. It was originally implemented with 16.16 fixed point arithmetic
using legacy x86 assembly abusing one byte instruction encodings (e.g. using
the AX part of RAX as the .16 fractional part). Some of the design decisions
of the size-optimized hand-written assembly synth are still visible in the
original code.

The original assembly implementation is buried somewhere deep in my hard disk.

[0]
[https://github.com/rikusalminen/jamtoysynth/blob/master/src/...](https://github.com/rikusalminen/jamtoysynth/blob/master/src/instrument.c)

~~~
thedjinn
Always interesting to see this. Looks a lot like a 4k synth I did myself many
years ago. It also amuses me to see that almost everybody was using those RBJ
biquad filters.

~~~
exDM69
I have to confess that I have pretty much no idea how the filter works or the
math behind it. I wrote that part with a friend who has some DSP background
but it was essentially copied from a signal processing book :)

But it sounds alright and was easy to implement, I can see why it's popular.

------
w0utert
Pretty awesome, I've always wanted to make something like this myself, but
listening to the demo on SoundCloud I don't think I would never even get close
to this :-)

One question I have is how difficult it would be to adapt a soft synth like
this to also be able to produce the kinds of sounds you would get from a SID
(from the C64 etc). My understanding of waveform synth is very limited, but it
has always struck me how different all synthesizers (hardware and software)
always sounded so different from SID chiptunes. Probably there's some analog
effects going on there that are hard to reproduce mathematically?

~~~
exDM69
> Probably there's some analog effects going on there that are hard to
> reproduce mathematically?

Yes, exactly. The SID chip is a pretty complex analog synthesizer and it was
made using less-than-perfect manufacturing processes, making some chips sound
better than others. The SID has very nice analog filters that are not trivial
to emulate with digital signal processing. Additionally, there were lots of
ugly tricks that abused the SID chip, such as making sounds by emitting a "all
ones" full-blast signal and then cranking the volume of the mixer circuit up
and down to produce a fake pcm sound.

My best understanding is that a "normal" audio synthesizer (such as this one I
believe) is doing computation at the same rate as audio output rate (typically
44 or 48 kHz). SID software emulators run internally at a much higher sample
rate (hundreds of kHz) in order to emulate the analog circuitry.

~~~
iammyIP
The sid is not a complex analog synth, it's a digital 3 poly 8 bit synth with
a single analog Filter at the end of the chain. As of synthesizer architecture
the sid is extremely simple and genius in design, like a skateboard many
tricks are possible with a simple thing.

~~~
exDM69
The complexity (emulation-wise) comes from the fact that it has analog
circuitry and has manufacturing imperfections. It's not complex compared to a
analog modular synth setup, of course.

Emulating it digitally is not just a matter of replicating the functionality
of the circuitry, but also taking in account all the analog phenomena. It's
much easier to model something like a Yamaha-style FM chip you can find in
AdLib or early SoundBlaster cards.

~~~
iammyIP
yes of course, to approximate the analog filter in digital you need to
calculate some nonlinearities, and could aswell go so far as simulate electric
circuitry to such detail that you would need a supercomputer to run it. But
that's not the complexity of the synth architecture (which is low on the sid),
but the default complexity of simulating anything analog.

------
raphlinus
Very cool, looks like clean code. Have you compared performance against
[https://github.com/google/music-synthesizer-for-
android/tree...](https://github.com/google/music-synthesizer-for-
android/tree/master/app/src/main/jni) ? I obsessed quite a bit over the NEON
in that.

------
tunesmith
Interesting, does anyone have an idea how to start where the instructions
leave off, and actually hook it up to a midi controller? What do you have to
do to get it working?

~~~
wingless
If LV2 plugins are anything like VSTs, you'll need to load the plugin in your
audio application and route your MIDI input through that plugin. In most DAWs
this is done by creating a track then assigning MIDI input and the VSTi to the
track.

------
seertaak
This is really impressive. Thanks for sharing.

