Audio drops while loading

I have a problem I am wondering about.  I am building a mixer for live use.  I have a few things that cause serious audio dropouts that are not related directly to my code.

1.  I have a help tab in the toolbar that simply opens and html doc.  While loading, audio stops (max headroom effect) somethimes for several seconds.

2. Same effect is I load a vst plugin.

I assume it is related to file reads interupting the windows message loop.  I tried to simple create a new thread so I could set low priority and do the load in that thread.  But I get an error about having to do it in the message thread (something like that.  This was a while ago).


What is the correct approach to aviod this king of problem.


Thanks.  Mark

If you have interactions with the message-Thread inside the audio callback, avoid them.

If you share Critical Sections between the audio callback and other threads do not do any message-thread related stuff, or memory allocations (or free) inside the locks, and hold them as short as possible. Or better use non blocking communication technics.



I am using multiple threads for the mixing.  The only think I do is use a waitable event on each thread.  When the audio call back occurs, that call back thread signals the threads.  When they complete processing, they wait again.  No critical secctions or IO or anything in these threads.  I usee InterlockedIncrement and InterlockedDecrement to control what each thread does.

Again, I assume the message thread is used for the waitable event.  If this is the reason I have my problem, how do get around this?  Is there an alternative way to get all threads working at the same time?  I tried lots of things and this method worked best for me.

Maybe you could try to use in the audio-callback a real spin-lock, to wait for the finished threads

while (!allThreadsHaveFinished) {};


and maybe you can try to use simple bool flags (when possible) instead of atomic operations for signaling that all threads has finished. 


Again, I assume the message thread is used for the waitable event


And I certainly wouldn't recommend writing your own spinlocks, or using bools instead of atomics. There are classes SpinLock and Atomic which do all these things for you BTW, no need to go to the win32 function calls!

If threads are getting blocked for multiple seconds, it's most likely that you're doing something silly without realising it, but would have thought that if you catch it in the debugger when it's stuck, it'd be easy to see what's going on.

i disagree,

the juce spin Look isn't a pure spin lock, because it interacts with the scheduler, of cause spin-locks are only useful on multi core machines.

yes, maybe the waste CPU-time, but the first problem is the  thread synchronization with will cause crackles, and not the "not enough cpu-power".

i don't avoid any atomic operations, but any atomic operation will force to sync the memory between all cpu-cores!, from a logical view that must have an perfomance impact on ALL threads!

And if non atomic bool fits (even when we waste some cpu-cycles) why don't use it


thats my experience when i wrote a multicore version of audioprocessorgraph ( for processig over 100 channels parallel on a 12 core processor)

I actually didn't mean to sound like I'm encouraging spin-locks at all - I think they're rarely a good thing to use. I just meant that if you're going to use them, then use a class that's designed for the job rather than spinning on a raw boolean and risking the compiler optimising it out or having strange performance characteristics based on the cache behaviour it causes.

Tracktion's multi-CPU mixer also does this kind of thing. It uses WaitableEvents, atomics and CriticalSections (originally used spin-locks but had strange performance problems with them and found CriticalSections to actually work better).

1 Like