Problem: Clicks and pops while moving a fader controlling the volume on a track playing back a sine wave. I have a solution that greatly reduces the problem, but the clicks can still be produced if the fader is moved fast enough.
Here’s the pre-solution setup: The faders are implemented as Sliders, the (stereo) track is derived from PositionableAudioSource, and the internal pan and volume members are protected by a CriticalSection. Here’s a snipped from getNextAudioBlock that renders volume and pan:
float gain = getGain(); float pan = getPan(); float left = 0.5f * gain * (1 - pan); float right = 0.5f * gain * (1 + pan); bufferToFill.buffer->applyGain(0,bufferToFill.startSample, bufferToFill.numSamples, left); bufferToFill.buffer->applyGain(1,bufferToFill.startSample, bufferToFill.numSamples, right);
My solution uses static floats to hold the previous setting and uses applyGainRamp to move from that setting to the new setting. The static float is a quick hack to test it out–although it allows the code to get the initial value of a control at start up, it doesn’t account for the case where the transport is stopped and the control moved. A better solution would replace the statics with variables that get updated if a control moves when the transport is off. Here’s the solution:
float gain = getGain();
float pan = getPan();
left = 0.5f * gain * (1 - pan);
right = 0.5f * gain * (1 + pan);
static float prevLeft = left;
static float prevRight = right;
bufferToFill.buffer->applyGainRamp(0, bufferToFill.startSample, bufferToFill.numSamples, prevLeft, left);
bufferToFill.buffer->applyGainRamp(1, bufferToFill.startSample, bufferToFill.numSamples, prevRight, right);
prevLeft = left;
prevRight = right;[/code]
I could probably improve it by using a high-order smoother, but I’m reluctant to wade through the math and experimentation just to find that performance sucks. As the defect was uncovered while trying to implement mix automation, it might make sense to filter the automation data after capture. My solution is good enough for most manual fader use–I didn’t even notice the problem until I started testing automation and then only on certain source material.
Any comments or ideas are welcome. I’m particularly interested in other folk’s solutions to what surely must be a common problem.