Everytime I mes with juce audio, I seem to come up against the lack of a ring buffer, either in juce, or fairly easy to use with juce, and ideally non-blocking.
My current situation is that I have a bunch of samples in memory, already pulled from a file, about a second ahead. They are currently in AudioSampleBuffer subclasses, with the sample times. Now I need to make the correct ‘range’ of samples available for audio callbacks to access (using a position to see what samples to get). Obviously, I don’t want them to have to search through all the potential buffers, especially since the reading thread could be trying to deposit newly read ones. So my idea is to keep a ring buffer with the min/max the audio callback should need.
I seem to remember there’s been various ‘just use a ring buffer’ comments, and a recent discussion where Jules noted that even the examples have potential threading problems in the audio area.
Has anyone solved this and can shed some light? Possibly a ring buffer plus juce atomics or similar, so it’s non-blocking, or at least lock-free?