AudioSources and threading (crashes)

Are there some caveats to dealing with AudioSources? I’m changing the source of an AutoTransportSource from a thread and getting crashes when I do, I suspect because it’s being accessed from the audio thread?

How do I avoid that without causing blocking between the threads? Is there a standard formula?

I would like to leave the sources connected and do some mixing, but that doesn’t seem trivial (on a timetable right now).

Bruce

Well, AutoTransportSource::setSource is designed to be thread-safe with respect to the audio thread, but if you’re calling it from another thread, maybe it’s some code in your prepareToPlay or releaseResources methods that’s causing the problem?

Those are both blank for me, I init the space I need in the constructor and destructor right now. I suspect it’s the prepare and release of the buffer and resampler that get created for me.

I really need to make a ‘channel remapping mixer’ or similar and leave the sources connected, so I’ll see what that entails. I just haven’t worked out the flow yet - I have 2+ videos with varying channel layouts feeding to a ‘master’ that will need to provide a stereo mix and distinct channels to a number of different callbacks.

What did you update when you put in multiple callbacks? If I need say, 16 outputs, some of which are the same thing, how would I deal with the distinct callbacks? What I mean is that if we’re at sample 1000, and I get a callback, then provide samples 1000-1500 to that callback, they won’t be available for the next callback, will they?

Bruce

OK, typical Juce experience. Gritted my teeth to do something that seemed tough and it took ten minutes :smiley:

So I moved to an AudioSourcePlayer, a MixerSource and then the rest, and instead of setting and unsetting sources, I’m using the gains to change between them. That works fine for now, and after some more experiments, it looks like I was calling setSource from different threads, since it’s also the way to change playback speed. I rationalized all my access into the one thread (except the callback, of course) and now it all seems good.

Will have to deal with channel remapping etc. another day.

Bruce