The scope function is in a JUCE component, and is called from PluginEditor via a Timer 30 times a second.
So my questions is; how do I access the AudioBuffer data in another JUCE component? I think I have to make a global pointer, or at least one that is accessible both in my Scope component and PluginProcessor, but don’t know how.
Sounds tempting, but don’t ever do that!
a) the referenced buffer is owned by the processor, which may move, dispose or recreate it in the background without your knowledge
b) the buffer would then be accessed by two threads, which is undefined behaviour, unless you add a lock, and that is not ok in the audio thread.
Usually you have an extra buffer allocated in prepareToPlay that acts as FIFO, where the audio thread can always push its samples and the displaying thread fetches them for displaying.
All right thanks. What I have right now, the above code, which is actually inside PluginProcessor - processBlock, works fine.
Only problem is that the sample data is usually copied to my plot array to slow or too often due to different sizes of the audio buffer and how often my Timer is called. I guess I can just use a test flag in above code, to check whether it is time to copy samples when paint() is about to do its work in my component.
The problem is, if you are writing into outputWaveBuffer, while the component is reading from it. It will probably just be a little visual glitch, but it is undefined behaviour and can bite you in the backside…
That’s not the greatest idea, you should not really wait for anything in the GUI thread. You may get away with it if the wait times are “short” but can you guarantee that is always going to be the case? Remember also that your plugin is sharing the GUI thread with the host application and all other plugins running in it. If your plugin spins around waiting, you are stealing CPU time from the host and the other plugins.
Thank you very much for pointing that out. I must have had a brain fart, as I can’t remember last doing this I now reworked my code to this, with a much decreased CPU usage, and now also if no sound is played, CPU usage is virtually nil.
In the PluginProcessor - processBlock I got, and note the change that I check for “Magnitude”;
Ok I watched both videos, very interesting stuff. But as you probably imagine I have absolutely no experience with this stuff (atomic, mutex, wait etc), so if you or anyone else can offer a quick example to get me started, of how I could better do the above, getting plot data from audio bufer, I would sure appreciate it, thanks!
Thanks for that, however I fail to understand why my code above is not good enough as I only collect the data after renderNextBlock is done, or in-between rather. That data should then be totally independent as it is used in my other component being accessed via Timer and Paint(), and Paint() only being called if data is collected.
I tried to use RealtimeMutatable the other day and ran into some issues, which I logged on the farbot repo. Is the library still in active development? In its current state, the RealtimeMutatable class doesn’t seem to be usable.