The generic solution for cases like this is a
lock-free ringbuffer.
I've also used the jack ringbuffer for this and it was easy enough.
Not that my work is a reference implementation but you can see how I
take it from a usb callback to the jack process thread here:
https://github.com/rbdrum2midi/rbdrum2midi/blob/dev/src/jackdriver.c#L281
(The process code is above at line 198, note that most of this was
lifted from the jack_keyboard source)
I've also
looked into LV2. If I implemented the synthesizer as LV2
plugin, I would get around having to solve the inter-thread
communication problem because it's the plugin host's responsibility.
But to be honest I've found this API to be a bit intimidating and I'm
not familiar with any LV2 host that would allow me to test such a
plugin. Any recommendations? Ardour?
jalv, Carla, QTractor, Ardour..
A LV2 simple synth example can be found at
http://lv2plug.in/book/#_sampler
I like jalv for debugging because its quite simple and quick to load.
I can run it with gdb and valgrind/callgrind without any trouble. I've
found it important to test in other hosts too though but only once its
working in jalv.
FWIW I hope you do make an LV2 plugin version as I rarely use
standalone synths these days. Again perhaps not the best
implementation but it is a fully independently coded one for an LV2
synth:
https://github.com/ssj71/infamousPlugins/blob/master/src/casynth/casynth.c#…
It always helps me to have several references to understand
implementation details.
If you have any questions about my code I've linked you are welcome to
ask. Also, LV2 has a ML and IRC channel and I'll be happy to offer any
advice or support there that I can too.
Good luck
_Spencer