Hush effect for guitar


#1

Hi All,
I’m implementing in my audio plugin an simple Hush effect for guitar (aka noise reduction).
I have this code:

void DigiFexAudioProcessor::applyHush(AudioSampleBuffer &buffer, int inputChannels)
{
    int numSamples = buffer.getNumSamples();
    const int db = 20 * log10(rmsValue);

    const float threshold = -48;
    const float timeSamples = 8820.0;
    
    hushTime = timeSamples;

    if (db < threshold)
    {
        if (hushTime > numSamples)
            hushTime -= numSamples;
        
        float blocks = hushTime / numSamples;
        float multiplier = inputGain / blocks;
        inputGain -= multiplier;
        
        buffer.applyGainRamp(0, numSamples, inputGain, multiplier);
    }
}

And it seem to work but when it start to reduce gai I ear some noise…
I’ve noticed that when I use stereo buffer output I have that noise…
Even on other effects…


#2

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)


#3

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 :slight_smile:

So, at least, have I to invert inputGain with multiplier in the applyGainRamp() ?


#4

So, I understand that this code is not yours for starter ? :slight_smile: 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 :wink: 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 ?


#5

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…

I this yes but how?


#6

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 :wink:

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…


#7

Thanks! It seem a good advice, but the input gain is not a constant, it can vary over time so I need to calculate it in the Hush function…


#8

Can you make me an example of the usage of LinearSmoothedValue plz?
I cannot initialize the initial value…


#9

See this thread

Rail