Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] "Real time safety" and inter-thread communication in Tonic. #270

Open
rvega opened this issue Nov 22, 2015 · 4 comments
Open

Comments

@rvega
Copy link

rvega commented Nov 22, 2015

Most of the literature I've read on real-time programming for audio shows that there should be some sort of lock-free data structure (usually a ring buffer) to pass control messages from the GUI to the audio thread and another one to pass audio samples from the audio thread to the GUI (if one needs to draw the audio wave in the GUI, for example). This is to prevent audio glitches and concurrency issues.

I can see that functions like synth.setParameter() are used, but, I can't figure out if this functions implement some sort of inter-thread communication similar to the one I described or if they use mutexes or something similar instead.

Can someone please explain how the communication between GUI and audio threads work in Tonic and/or the example apps? If a lock-free data structure scheme is not used, why?

@morganpackard
Copy link
Member

Tonic doesn't use any protection mechanism for the inter-thread
communication other than being careful not to modify anything other than
primitive values (generally floats) from anywhere but the audio thread. In
practice, this generally works fine, though is theoretically not safe.
Don't use it to launch a space ship or run power a medical device. But
generally, you can be confident that the inter-thread communication is
stable and works.

On Sat, Nov 21, 2015 at 8:27 PM, Rafael Vega [email protected]
wrote:

Most of the literature I've read on real-time programming for audio shows
that there should be some sort of lock-free data structure (usually a ring
buffer) to pass control messages from the GUI to the audio thread and
another one to pass audio samples from the audio thread to the GUI (if one
needs to draw the audio wave in the GUI, for example). This is to prevent
audio glitches and concurrency issues.

I can see that functions like synth.setParameter() are used, but, I can't
figure out if this functions implement some sort of inter-thread
communication similar to the one I described or if they use mutexes or
something similar instead.

Can someone please explain how the communication between GUI and audio
threads work in Tonic and/or the example apps? If a lock-free data
structure scheme is not used, why?


Reply to this email directly or view it on GitHub
#270.

Morgan Packard
cell: (720) 891-0122
twitter: @morganpackard

@aramazhari
Copy link

aramazhari commented Sep 16, 2017

I know this is an old thread but I also have trouble calling synth.setOutputGen() from another thread.
I'm using imgui (a famous GUI library) and change a generator value upon moving a slider around, which is a very practical purpose of using TonicAudio and that gives me exceptions in all places. I do see that there is a MutexLock / Unlock within setOutputGen() but that doesn't seem to help at all.

If there are any examples on best usage of the Tonic api + real-time gui I would appreciate it.

@morganpackard
Copy link
Member

morganpackard commented Sep 17, 2017 via email

@aramazhari
Copy link

There are so many. Mostly read access violations. Running the software multiple times you will see them in different locations. Simply put, Tonic internally seem to race its own stuff. Since the only call from outside that I make is synth.setOutputGen.

Here are some of them but these are mostly coincidental. Exception Screenshots

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants