Dear all,
I have a pretty fundamental question about real-time audio, but I cannot find a proper answer. The context is low-level audio programming on mobile platforms, that is the programming my own audio modules with their own C/C++ audio render functions.
Consider the following case:
My audio graph (the API it is implemented in doesn’t matter really) contains several independent modules, whose render functions are called and audio outputs are mixed together at each audio render loop call.
At some point, for some reason (there can be plenty, but let’s say the order comes from outside the audio thread, which is generally the case), I need to free and reallocate the resources of one of the modules (some of these resources are accessed inside the render function), without disturbing the other modules.
- If the audio render loop is running precisely at the moment I receive the order to reallocate resources, I have to wait for the render function to finish to avoid freeing memory that it currently being read or written.
- I have to prevent the render function of this particular module, but not those of the other modules, from running while I’m doing memory free/alloc.
- As it is always the case within the audio thread, I shall not use any lock, or free/alloc inside the audio render function.
- I cannot stop the audio render loop, because the other modules are potentially running and producing audio output.
My question is then:
How can I SAFELY and PROPERLY free and reallocate some resources used inside the audio thread, without disturbing the audio render loop?
Thank you all for your input 🙂
Tom