That code seems incomplete to say the least… How do you calculate rmsValue ? How do you initialize inputGain ?
Moreover, inputGain seems to be < multiplier in some cases, so the last instruction should have the order of them inversed, shouldn’t it ?
Last thing, why db is integer instead of float ? You should use the JUCE Decibels::gainToDecibels function to do the calculation instead of the 20 * log10, because it handles automatically the case of the input being zero (log10(0) = -infinite)
rmsValue is a public float of Processor.h and I get its value in the processBlock(); method of Processor.cpp. Input gain is a public float in Processor.h end its value changes in a SliderListener of Editor.cpp.
I don’t know… I asked here for that reason…
In that case I’ll use the gainToDecibels(): method
So, at least, have I to invert inputGain with multiplier in the applyGainRamp() ?
So, I understand that this code is not yours for starter ? That’s really really bad practice to copy and paste dsp code without having a look to what it does…
You should try to understand by yourself for example what happens with multiplier and inputGain, and since the ramp function is supposed to apply a gain that is decreasing at each call… well it would be wrong if the ramp is acting the other way Use a debugger for example to see what happens there !
About that inputGain thing, shouldn’t it be reinitialized every time the rms value is higher than the threshold, so that the next noise gating processing starts from the right volume decrease ?
No, this code is mine… but I know that it’s bad, the real noise gate algorithms are more complicated…and are to apply every single sample…I found a topic in which there is an example but I can’t understand how I can implement this in JUCE.
I’ve tried also applyGain(multiplier).
The problem is that the buffer is a 256 sample block, and the time to do the reduction is (in samples) 8820 (200 milliseconds) so if I apply gainRamp, it exceeded the size of the buffer…
Sincerely, I think the best tip I can give you is to find good sources of information about how a noise gate really works, such as the DAFX book, or some scientific articles on the internet.
I think your inputGain should be set to 1 every time dB >= threshold, and also in the initialisation section of your code
Another tip would be to use the LinearSmoothedValue class from JUCE instead of the manual ramping. At startup, you can set the ramping time (say 200 ms) and the initial value (say 1). Then, when your rmsValue is below the threshold, you set the target value to zero. And whatever happens, you muliply the value of all your samples with the current value of the LinearSmoothedValue class, which will advance to the target value automatically at each call. That’s not the best way to do such a thing, but that will be a little better…