Control Filters#

Control filters are UGens that process control rate signals. They can perform various functions, such as smoothing a control signal, downsampling an audio signal to a control signal, or performing mathematical operations on control signals.

To use a control filter, you need to create an instance of the control filter UGen, connect a control signal to its input, and then connect the output of the control filter to the parameter you want to control. The control filter will process the control signal and the resulting signal will control the parameter.

Lag#

The Lag unit generator is a simple control filter that’s very useful for smoothing rapid changes in a control signal. This is often used to avoid clicks or pops that might occur when a parameter changes suddenly.

It is similar to OnePole but it has a more meaningful parameter, called lagTime which is the time it takes for the output value to reach 63.2% of the way towards the target value after the input changes. The higher the lagTime, the slower the output will respond to changes in the input, and the smoother the transition will be.

The following code plots a the signal of a noise generator which generates a random value every 1/freq seconds. We smoothen the noise by a OnePole and by Lag. Our frequency is 10 Hz and our lagTime is 0.1 seconds.

({
    var freq = 10;
    var noise = LFNoise0.ar(freq);
    [noise, OnePole.ar(noise, coef: 0.999), Lag.ar(noise, lagTime: freq.reciprocal)];
}.plot(2.0))

This gives us the following plot.

../../../_images/lag-and-onepole.png

Fig. 57 A filtered random signal. First we apply OnePole and Lag which gives us roughly the same result.#

Since Lag is often used to smoothen changing parameters, for example in a performance, SuperCollider offers us a syntactical shorthand:

LFNoise0.ar(freq).lag(0.1);

Let us try to lag a signal consisting of 440 and 40 Hz. As we increase the lagTime we have to boost the amplitude of the signal.

{SinOsc.ar(440)+SinOsc.ar(40) * 0.25;}.plot(2/40);

({
3.8 * Lag.ar(
    SinOsc.ar(440)+SinOsc.ar(40), 
    lagTime: 300/440
) * 0.25;
}.plot(2/40);
)
../../../_images/lag-filtering.png

Fig. 58 A signal consisting of 440 HZ and 40 Hz partial (left) filtered by Lag (right).#

VarLag#

VarLag is similar to Lag but with other curve shapes than exponential. However VarLag only works at control rate kr! Compare the different shapes of the lag:

({
    var freq = 10;
    var noise = LFNoise0.kr(freq);
    [
        noise, 
        VarLag.kr(noise, time: freq.reciprocal, warp: \sine), 
        VarLag.kr(noise, time: freq.reciprocal, warp: \linear), 
        Lag.kr(noise, lagTime: freq.reciprocal)
    ];
}.plot(2.0))
../../../_images/var-lag.png

Fig. 59 A filtered random signal. First we apply no filter at all, then VarLag with different curve shapes.#