Avoiding glitches in AudioSampleBuffer::applyGain


#1

Is there a way to avoid audio glitches when calling AudioSampleBuffer::applyGain in an audio callback with the gain parameter changing quickly?
Maybe I’m missing something obvious :roll:


#2

Maybe the ramp version?  buffer 1 -> (start gain 0.5), (end gain 1.0), next buffer-> (startgain 1.0, end gain 0.2) etc

That way you'll get a smooth transition for every buffer and per sample adjustments.

Maybe the ramp version? buffer 1 -> (start gain 0.5), (end gain 1.0), next buffer-> (startgain 1.0, end gain 0.2) etc

That way you’ll get a smooth transition for every buffer and per sample adjustments.


#3

Yes, I was aware of applyGainRamp, but in that case I don’t understand how can I get 2 gain values, since I have just one gain value (the one coming from, let’s say, a slider)…

EDIT: (always think 3 times before posting) nevermind, I did it! Thank you :smiley:


#4

DSPFilters Demo has a perfect example of a volume control knob that smooths its parameter changes. Same with the playback speed control.


#5

You have the current gain value and a gain value from the past. I think the applyGainRamp function is a linear fade. You may wish to consider connecting the previous and current values with a one-pole lowpass filter. You can then just set the time constant of the filter to alter the sluggishness with which the internal gain value follows the slider value.