How to check in processorBlock if is there any signal?

Hello,
I use juce example Plugin Host for debuging my plugin.
I have some another plugin that generates wave form (some kind of oscillator). And I use it as an input to my plugin which I debug. And in that generator I have button “mute” which mute signal. And in my debuging plugin I want to be able to get some flag or get some ‘bool’ with info that “mute” is clicked in another plugin, or just that there is no signal.

Of course I can make loop through the whole buffer and check if each one sample is equal zero. But isn’t there any easier method?

Thanks for any help.

It clearly needs to involve looping over the samples, how else could it work? If you don’t want to loop over the samples in your own code, you could use the AudioBuffer methods like getMagnitude(). (hasBeenCleared() is not going to work though, that doesn’t measure the audio signal itself.)

But what is advantage in use getMagnitude? I still need make it for each sample in the buffer. So I still need loop. Am I right?

No, getMagnitude itself loops over the samples in the buffer and returns you the highest absolute sample value found. So if you check if that is zero or “very near to zero” you will know that the buffer is silent.

Great I will try it. Thanks.

The buffer isn’t very big, and your computer is very very fast, so I wouldn’t worry about it :slight_smile:

Some plugin formats (e.g. VST3) have the concept of a “silence flag”, the idea is that for example when the Oscillator is muted it would set the “silence flag” and the receiver of that audio would then know (without any expensive looping over the sample buffer) that it’s input is silent.
This technique can support further optimizations such as avoiding the need to call a plugin’s Render method altogether (because it’s input signal is silent). I’m unsure if JUCE supports this yet.