Hello guys and @timur !
Something has been bothering me for a while, and I told that to a few guys who have not been able to answer my questions. I think that the lock-free queue isn’t the best structure for doing basic communication between an audio thread and the UI.
In the past, I did code a meter for JUCE, and also a spectrum analyzer. In both cases, they work thanks to a buffer, which is shared by the audio + UI threads. The audio thread put the data inside in the processBlock functions as usual, and the UI thread is reading that data from time to time thanks to a Timer / HighResTimer / TimeSliceClient or whatever.
The thing is, a meter is supposed to work by reading the last 100-200 ms of the data for example for a RMS meter.
Tell me if I’m wrong, the very principle of the AbstractFIFO in JUCE (and of std::queues I guess) is that every sample that is put inside the structure with a write/push, is supposed to be read/popped once. Not twice, not zero time, otherwise it’s no more a queue.
However, every time I need to refresh the data displayed on the UI in my RMS meter, I need to get the last N samples that are inside the buffer. Depending on the Timer callback rate, that means that some given audio samples, at given time, might not be read even once (if the timer is called every 1 second for example), or it might be read twice or more (if the timer is called every 20 ms for example). Which means, that the lock-free queue can’t be used directly, or can’t be used at all.
That’s why I came up with an idea, having something equivalent to the AbstractFiFo class, but which always returns the last N given samples : Concurrency, meters, JUCE classes. In fact, that thinking follows the one I did in this thread…
So, I would like to ask everybody in the forum who have already some skills about the use of lock-free queues to tell me : are they really that useful ? Isn’t it an error to use queues instead of something like my data structure ? Or is it more efficient, even possible, to solve that issue using only lock-free queues, that is getting the last N samples of a buffer without compromising the behaviour of the queue ?
Thanks in advance !