# Build Random Filter Keys in SuperCollider

A stock-unit SuperCollider interpretation of [the Ableton sound](/tutorials/random-filter-keys/) and its [Csound version](/tutorials/random-filter-keys/csound/). Each stage changes the source or its effect chain; oscillator, filter, modal and room algorithms differ across platforms.

[Starting settings](STARTING_STATE.md) · [Complete settings](ALL_PARAMETERS.md). The full runnable script ends this guide.

## Step 1 — Build the two-octave resonant body

Select `~soundStage = 1` and evaluate the full script at the end of this guide. Wait for the instrument-ready message before playing.

Set `~soundStage = 1` in the full script. Blend two saws at −6 dB each: one at the note plus two cents, the other an octave down. Add an octave-down sine at −15 dB. A 300 Hz tracked ladder lowpass uses resonance 0.67 and +3 dB smooth drive. The amplitude has 57 ms attack, decay and release with −2.3 dB sustain; instrument gain is −19 dB with 50% touch response.

| SuperCollider control | Value |
| --- | --- |
| Saw / sub | −6/−6 dB saws; octave-down sine −15 dB |
| Filter | 300 Hz, full tracking, 0.67 resonance, +3 dB drive |
| Amplitude | 57 ms / 57 ms / −2.3 dB / 57 ms |
| Instrument | −19 dB |

For `MoogFF`, multiply the stated source resonance amount by four to obtain its 0–4 gain argument (limited to 3.95). The complete script gives this gain expression beside each cutoff.

<audio controls preload="none" aria-label="SuperCollider Random Filter Keys after step 1"><source src="audio/steps/step-01.webm" type="audio/webm"></audio>

[Sound after step 1 — WebM/Opus](audio/steps/step-01.webm)

## Step 2 — Jump between random filter states

Set `~soundStage = 2` in the full script. A sample-and-hold random value changes at 2.67 Hz. Use it for ±1 octave of cutoff and ±3 dB of input drive. Positive values brighten and push the resonant filter, while negative values darken it. Each note has its own random generator; the exact source noise waveform and modulation scale differ.

| SuperCollider control | Value |
| --- | --- |
| Random rate | 2.67 Hz |
| Cutoff / drive movement | ±1 octave / ±3 dB |

For `MoogFF`, multiply the stated source resonance amount by four to obtain its 0–4 gain argument (limited to 3.95). The complete script gives this gain expression beside each cutoff.

<audio controls preload="none" aria-label="SuperCollider Random Filter Keys after step 2"><source src="audio/steps/step-02.webm" type="audio/webm"></audio>

[Sound after step 2 — WebM/Opus](audio/steps/step-02.webm)

## Step 3 — Add filtered stereo echoes

Set `~soundStage = 3` in the full script. Use 750 ms left and 775 ms right, 25% feedback and 30% wet. Feed each channel back into itself, keeping the unequal timing paths independent. Filter each echo around 900 Hz, with a 7-octave interval between highpass and lowpass cutoffs. Feedback values are updated once per server processing block, adding that small delay to the recirculating path. Held notes leave older colors behind the current tone.

| SuperCollider control | Value |
| --- | --- |
| Times | 750 / 775 ms |
| Feedback / wet | 25% / 30% |
| Routing | Independent channels |
| Filter center / width | 900 Hz / 7 octaves |
| Time LFO | 0 Hz, ±0% |

<audio controls preload="none" aria-label="SuperCollider Random Filter Keys after step 3"><source src="audio/steps/step-03.webm" type="audio/webm"></audio>

[Sound after step 3 — WebM/Opus](audio/steps/step-03.webm)

## Step 4 — Surround the tone with a damped room

Set `~soundStage = 4` and evaluate the full block. Feed the preceding signal into `FreeVerb2`, using its fully wet output and the dry/wet routing shown in the script. The room continues after individual note envelopes release. Predelay separates the initial articulation from the diffuse tail; the external wet mix controls how far that tail moves forward.

The SuperCollider room value is 0.96 and damping is 0.8875. These dimensionless settings are choices for this algorithm, rather than equivalent values for Ableton decay or Csound feedback and damping. More damping darkens the circulating highs. Any input filters and mid/side width changes in this stage retain their own explicit settings in the full script.

| SuperCollider room control | Value |
| --- | --- |
| FreeVerb2 internal mix | 1, wet output only |
| Room | 0.96 |
| Damping | 0.8875 |
| Predelay | 5 ms |
| External room wet | 15% |

| SuperCollider control | Value |
| --- | --- |
| Room side multiplier | 1 |
| Room input cuts | Off |

<audio controls preload="none" aria-label="SuperCollider Random Filter Keys after step 4"><source src="audio/steps/step-04.webm" type="audio/webm"></audio>

[Sound after step 4 — WebM/Opus](audio/steps/step-04.webm)

## Downloads and settings

[Finished sound — WebM/Opus](audio/Random-Filter-Keys.webm) · [Complete settings](ALL_PARAMETERS.md) · [Ableton version](/tutorials/random-filter-keys/) · [Csound version](/tutorials/random-filter-keys/csound/)

## Full SuperCollider script

The complete Random Filter Keys instrument uses stock SuperCollider units. Set `~soundStage` from 1 to 4 and evaluate the entire block again to select a cumulative stage. Wait for the ready message; `~soundNote.(60, 0.8, 1)` plays MIDI 60 at velocity 0.8 with a one-second held duration. Held duration controls when release begins, while each source's decay and modulation continue independently. `~soundStop.()` frees the active instrument and its effects. This block replaces the previously installed PlayGrid instrument in the same interpreter.

```supercollider
(
~soundStage = 4;
~soundOutputScale = 6.744405;
~soundRelease = 0.057;
~soundNames = (motion: \pgRandomFilterKeysMotion, voice: \pgRandomFilterKeysVoice, effects: \pgRandomFilterKeysEffects);

~soundDefs = [
    SynthDef(\pgRandomFilterKeysMotion, { |out=0| Out.kr(out, DC.kr(0)) }),
    SynthDef(\pgRandomFilterKeysVoice, { |out=0, midi=60, velocity=0.8, gate=1, startMidi=60|
        var stage = ~soundStage;
    var aDrive = 0, aL = 0, aR = 0, aSaw1 = 0, aSaw2 = 0, aSource = 0, aSub = 0, iHz = 0;
    var iVelocity = 0, kAmp = 0, kCut = 0, kNew = 0, kRandom = 0;
    iHz = (midi).midicps;
    iVelocity = (velocity).clip(0, 1);
    aSaw1 = (Saw.ar((iHz * (2 ** (2 / 1200)))) * ((0 - 6)).dbamp);
    aSaw2 = (Saw.ar((iHz * 0.5)) * ((0 - 6)).dbamp);
    aSub = (SinOsc.ar((iHz * 0.5), 0 * 2pi) * ((0 - 15)).dbamp);
    aSource = ((aSaw1 + aSaw2) + aSub);
    kRandom = 0;
    if((stage >= 2)) {
    kNew = LFNoise0.kr(2.67).range((0 - 1), 1);
    kRandom = kNew;
    };
    kCut = ((300 * (2 ** (((midi - 60) / 12) + kRandom)))).clip(30, 18000);
    aDrive = ((aSource * ((3 + (3 * kRandom))).dbamp)).tanh;
    aSource = MoogFF.ar(aDrive, (kCut).clip(20, 18000), (0.67 * 4).clip(0, 3.95));
    kAmp = EnvGen.kr(Env([0, 1, 0.7673614893618189, 0], [0.057, 0.057, 0.057], \lin, releaseNode: 2), gate);
    aL = (((aSource * kAmp) * ((0 - 19)).dbamp) * (0.5 + (0.5 * iVelocity)));
    aR = aL;
    Out.ar(out, [aL, aR]);
        EnvGen.kr(Env.asr(0.0001, 1, 0.057), gate, doneAction: 2);
    }),
    SynthDef(\pgRandomFilterKeysEffects, { |in=0, out=0|
        var stage = ~soundStage;
        var outputScale = ~soundOutputScale;
        var input = In.ar(in, 2);
    var feedback = LocalIn.ar(2);
    var aDelFbL = 0, aDelFbR = 0, aDelSendL = 0, aDelSendR = 0, aDelTimeL = 0, aDelTimeR = 0, aEchoL = 0, aEchoR = 0;
    var aL = 0, aR = 0, aRoomInL = 0, aRoomInR = 0, aRoomL = 0, aRoomMid = 0, aRoomPreL = 0, aRoomPreR = 0;
    var aRoomR = 0, aRoomSide = 0, kDelCenter = 0, kDelMotion = 0, room27 = 0;
    aL = input[0];
    aR = input[1];
    if((stage >= 3)) {
    aDelFbL = feedback[0];
    aDelFbR = feedback[1];
    kDelMotion = 0;
    aDelTimeL = K2A.ar((750.0 * (1 + (0 * kDelMotion))));
    aDelTimeR = K2A.ar((775.0 * (1 - (0 * kDelMotion))));
    aDelSendL = aL;
    aDelSendR = aR;
    aEchoL = DelayC.ar((aDelSendL + (aDelFbL * 0.25)), 2200 / 1000, (aDelTimeL / 1000).clip(0.00002, 2200 / 1000));
    aEchoR = DelayC.ar((aDelSendR + (aDelFbR * 0.25)), 2200 / 1000, (aDelTimeR / 1000).clip(0.00002, 2200 / 1000));
    kDelCenter = (900 * (2 ** (0 * kDelMotion)));
    aEchoL = HPF.ar(aEchoL, ((kDelCenter / (2 ** 3.5))).clip(20, 18000));
    aEchoL = LPF.ar(aEchoL, ((18000).min((kDelCenter * (2 ** 3.5)))).clip(20, 18000));
    aEchoR = HPF.ar(aEchoR, ((kDelCenter / (2 ** 3.5))).clip(20, 18000));
    aEchoR = LPF.ar(aEchoR, ((18000).min((kDelCenter * (2 ** 3.5)))).clip(20, 18000));
    aDelFbL = aEchoL;
    aDelFbR = aEchoR;
    aL = ((aL * 0.7) + (aEchoL * 0.3));
    aR = ((aR * 0.7) + (aEchoR * 0.3));
    };
    if((stage >= 4)) {
    aRoomInL = aL;
    aRoomPreL = DelayN.ar(aRoomInL, 0.005, 0.005);
    aRoomInR = aR;
    aRoomPreR = DelayN.ar(aRoomInR, 0.005, 0.005);
    room27 = FreeVerb2.ar(aRoomPreL, aRoomPreR, 1, 0.96, 0.8875);
    aRoomL = room27[0];
    aRoomR = room27[1];
    aRoomMid = ((aRoomL + aRoomR) * 0.5);
    aRoomSide = (((aRoomL - aRoomR) * 0.5) * 1);
    aL = ((aL * 0.85) + ((aRoomMid + aRoomSide) * 0.15));
    aR = ((aR * 0.85) + ((aRoomMid - aRoomSide) * 0.15));
    };
    LocalOut.ar([aDelFbL, aDelFbR].collect { |channel| channel + DC.ar(0) });
    Out.ar(out, [((aL * 1) * outputScale), ((aR * 1) * outputScale)]);
    })
];
~soundStop = {
    if(~cirrusGroup.notNil) { ~cirrusGroup.free; ~cirrusGroup = nil };
    if(~cirrusAudio.notNil) { ~cirrusAudio.free; ~cirrusAudio = nil };
    if(~cirrusMotion.notNil) { ~cirrusMotion.free; ~cirrusMotion = nil };
    if(~pgGroup.notNil) { ~pgGroup.free; ~pgGroup = nil };
    if(~pgAudio.notNil) { ~pgAudio.free; ~pgAudio = nil };
    if(~pgMotion.notNil) { ~pgMotion.free; ~pgMotion = nil };
};
~soundInstall = {
    s.waitForBoot {
        ~soundStop.();
        ~soundDefs.do { |definition| definition.add };
        s.sync;
        ~pgAudio = Bus.audio(s, 2);
        ~pgMotion = Bus.control(s, 1);
        ~pgGroup = Group.head(s);
        ~pgLastMidi = 60;
        Synth.head(~pgGroup, ~soundNames.motion, [\out, ~pgMotion]);
        ~pgVoices = Group.tail(~pgGroup);
        Synth.tail(~pgGroup, ~soundNames.effects, [\in, ~pgAudio]);
        "Random Filter Keys ready".postln;
    };
};
~soundNote = { |midi=60, velocity=0.8, hold=1|
    var note = Synth.head(~pgVoices, ~soundNames.voice, [
        \out, ~pgAudio, \midi, midi, \velocity, velocity.clip(0, 1),
        \startMidi, ~pgLastMidi
    ]);
    ~pgLastMidi = midi;
    SystemClock.sched(hold, { note.set(\gate, 0); nil });
    note;
};
if(~soundOffline != true) { ~soundInstall.() };
)
```

[Read on playgrid.cc](https://playgrid.cc/tutorials/random-filter-keys/supercollider/)
