Fundamental DSP and Multithreading question
I have sampled audio allocated in memory represented as simple array of floats. Sample count is known and stored in another variable.
In my audio thread I read through and interpolate this audio, even allowing for pitch shifting to occur mid buffer. In other words, I get up close and personal with each discrete sample frame while in the audio thread.
In my main thread, if I want to replace my sampled audio with different audio of different length does anyone have ideas for the best way to handle this, considering my audio thread may still be trying to read the original audio?
AEManagedValue is for you
So Michael, anyway to explain it in short? "Sophisticated" orchestration of proxy objects and flags maybe? Any other secret magic than that?
It's actually pretty basic, and relies on the atomicity of pointer variable assignment. You allocate a new value/buffer every time, so that you're not touching the same data as the realtime thread; when you're done setting up the new value, you're just updating the pointer.
The old value is freed at a later point automatically; the realtime thread basically marks it as ready for deletion, and the main thread takes care of it afterwards.
You can also provide a custom release implementation, so you can also do things like buffer swapping, rather than allocating memory each time, but it's easier to just allocate memory, of course,
Check out the source for implementation details.