[LAD] Realtime inter-thread communication

Robin Gareus robin at gareus.org
Mon Feb 29 14:45:14 UTC 2016


On 02/29/2016 03:38 PM, Sebastian Gesemann wrote:
> Hello fellow audio developers,
> 
> I've started writing a software synthesizer in C++ (using SDL2 for
> now) for kicks and giggles and ran into the problem of having the
> event loop thread that listens for keyboard events communicate with
> the audio callback.
> 
> Are there any recommendations for how to pass real-time events (note
> on, note off, etc) to such an audio callback? I figured, this is
> already a solved problem and that I could benefit from your
> experiences. Maybe you know of some nice open-source C++ queue
> implementation that is suitable in such a situation.
> 
> I could use some kind of "channel" (thread-safe bounded buffer
> implemented using mutexes and condition variables) but I'm not sure
> whether this is a good idea in this situation since the audio callback
> function should avoid unnecessary delays.

Mutexes are not a good idea.
http://www.rossbencina.com/code/real-time-audio-programming-101-time-waits-for-nothing

The generic solution for cases like this is a lock-free ringbuffer.

Then again, ideally you'll get both Audio and MIDI in the same callback
to begin with. JACK provides this for example.


> 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

HTH,
robin



More information about the Linux-audio-dev mailing list