playgrid.ccRead tutorial

Tutorial 106 / SuperCollider

Build Polar Beacon in SuperCollider

Build Polar Beacon in SuperCollider with triangle swarm, explicit envelopes and the sound-shaping chain explained in the guide.

5 stepsTriangle SwarmSuperCollider

Listen to the finished sound

Download WEBM ↓

Follow the synthesis steps in order. Use the audio examples and device settings alongside the instructions.

Step 01 / 5

Build the drifting triangle cluster

Select ~soundStage = 1 and evaluate the full script at the end of this guide. Wait for the instrument-ready message before playing. The triangle source is an explicit odd-harmonic sine sum through partial 31, with components at or above 22 kHz muted.

Set ~soundStage = 1 in the full script. Use five triangle voices spread across ±24 cents, with independent sine drift of ±2.8 cents. Their different phases and slow rates make the held spectrum beat. Use engine gain −10 dB, amplitude attack 0.65 s, decay 3.2 s to −4 dB and release 1.9 s. A −8 dB instrument gain and 50% velocity response follow mild smooth drive. Spacing and motion are explicit SuperCollider choices for the source macros.

SuperCollider control Value
Triangle offsets −24, −12, 0, +12, +24 cents
Drift ±2.8 cents; 0.12 + abs(offset) × 0.005 Hz
A contour 0.65 / 3.2 / −4 dB / 1.9 s
Engine / instrument gain −10 / −8 dB

Sound after step 1 — WebM/Opus

Next: Add the slower octave and stereo filtering →

Step 02 / 5

Add the slower octave and stereo filtering

Set ~soundStage = 2 in the full script. Enable the octave-up sine at −22 dB and +3.125 cents. Give it an independent 1.10 s attack, 4 s decay to −6 dB and 2.20 s release. Filter the triangle channels at 2600 Hz with Q 1.2; reverse the voice weights across the channels, bias A slightly left and B right. The octave enters later than the main cluster and can remain after its release. This interprets Basic Shapes and SVF rather than scanning the original engines.

SuperCollider control Value
A lowpass 2600 Hz, Q 1.2
B pitch / level 2 × note frequency, +3.125 cents / −22 dB
B contour 1.10 / 4.00 / −6 dB / 2.20 s
Stereo voice weights 0.8/0.7/0.5/0.3/0.2, reversed right; sum / 2.5

Sound after step 2 — WebM/Opus

Next: Add filtered stereo echoes →

Step 03 / 5

Add filtered stereo echoes

Set ~soundStage = 3 in the full script. Use 340 ms left and 470 ms right, 30% feedback and 22% wet. Inject the centered input on the left and cross-feed the filtered echoes so later repeats alternate sides. Filter each echo around 1700 Hz, with a 3-octave interval between highpass and lowpass cutoffs. A shared 0.18 Hz sine moves times by ±2% and the filter center by ±0.04 octaves. 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 340 / 470 ms
Feedback / wet 30% / 22%
Routing Crossed, left input
Filter center / width 1700 Hz / 3 octaves
Time LFO 0.18 Hz, ±2%

Sound after step 3 — WebM/Opus

Next: Surround the tone with a damped room →

Step 04 / 5

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.752295 and damping is 0.8. 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.752295
Damping 0.8
Predelay 30 ms
External room wet 20%
SuperCollider control Value
Room side multiplier 1
Room input cuts Off

Sound after step 4 — WebM/Opus

Next: Set the final width and gain →

Step 05 / 5

Set the final width and gain

Set ~soundStage = 5 in the full script. Use 16.5 dB gain after the effects. Scale the side signal by 1, preserving the center. Highpass only the side at 160 Hz to focus the lowest frequencies. Apply LeakDC DC removal with coefficient 0.995. The fixed ~soundOutputScale gain follows the complete effect chain at every stage. The effects Synth reads the stereo bus after the note group, and continues through note releases.

SuperCollider control Value
Final gain 16.5 dB
Width 1 × side
Bass side cutoff 160 Hz
DC removal LeakDC, coefficient 0.995

Sound after step 5 — WebM/Opus

Audio & settings ↓

Audio & settings

Audio recordings and settings for this tutorial.

Full SuperCollider script

The complete Polar Beacon instrument uses stock SuperCollider units. Set ~soundStage from 1 to 5 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.

(
~soundStage = 5;
~soundOutputScale = 0.4205338;
~soundRelease = 2.2;
~soundNames = (motion: \pgPolarBeaconMotion, voice: \pgPolarBeaconVoice, effects: \pgPolarBeaconEffects);
~pgWave = { |freq, amplitude=1, phase=0, partials=#[1]|
    Mix(partials.collect { |weight, i|
        var harmonic = freq * (i + 1);
        SinOsc.ar(harmonic.clip(0.01, 22000), phase * 2pi * (i + 1)) * weight * (harmonic < 22000)
    }) * amplitude;
};
~pgTriangle = { |freq, phase=0|
    var partials = Array.fill(31, { |i|
        var n = i + 1;
        if(n.odd) { ((-1) ** ((n - 1) / 2)) * 8 / (pi.squared * n.squared) } { 0 }
    });
    ~pgWave.(freq, 1, phase, partials);
};
~soundDefs = [
    SynthDef(\pgPolarBeaconMotion, { |out=0| Out.kr(out, DC.kr(0)) }),
    SynthDef(\pgPolarBeaconVoice, { |out=0, midi=60, velocity=0.8, gate=1, startMidi=60|
        var stage = ~soundStage;
    var aB = 0, aL = 0, aR = 0, aV0 = 0, aV1 = 0, aV2 = 0, aV3 = 0, aV4 = 0;
    var iHz = 0, iVelocity = 0, kA = 0, kB = 0, kDrift0 = 0, kDrift1 = 0, kDrift2 = 0, kDrift3 = 0;
    var kDrift4 = 0;
    iHz = (midi).midicps;
    iVelocity = (velocity).clip(0, 1);
    kDrift0 = (SinOsc.kr(0.24, 0.0 * 2pi) * 2.8);
    aV0 = (~pgTriangle.((iHz * (2 ** (((0 - 24.0) + kDrift0) / 1200))), 0.0) * ((0 - 10)).dbamp);
    kDrift1 = (SinOsc.kr(0.18, 0.18 * 2pi) * 2.8);
    aV1 = (~pgTriangle.((iHz * (2 ** (((0 - 12.0) + kDrift1) / 1200))), 0.18) * ((0 - 10)).dbamp);
    kDrift2 = (SinOsc.kr(0.12, 0.36 * 2pi) * 2.8);
    aV2 = (~pgTriangle.((iHz * (2 ** ((0 + kDrift2) / 1200))), 0.36) * ((0 - 10)).dbamp);
    kDrift3 = (SinOsc.kr(0.18, 0.54 * 2pi) * 2.8);
    aV3 = (~pgTriangle.((iHz * (2 ** ((12.0 + kDrift3) / 1200))), 0.54) * ((0 - 10)).dbamp);
    kDrift4 = (SinOsc.kr(0.24, 0.72 * 2pi) * 2.8);
    aV4 = (~pgTriangle.((iHz * (2 ** ((24.0 + kDrift4) / 1200))), 0.72) * ((0 - 10)).dbamp);
    kA = EnvGen.kr(Env([0, 1, 0.6309573444801932, 0], [0.65, 3.2, 1.9], \lin, releaseNode: 2), gate);
    aL = ((((((aV0 + aV1) + aV2) + aV3) + aV4) / 5) * kA);
    aR = aL;
    if((stage >= 2)) {
    kB = EnvGen.kr(Env([0, 1, 0.5011872336272722, 0], [1.1, 4, 2.2], \lin, releaseNode: 2), gate);
    aB = (SinOsc.ar(((iHz * 2) * (2 ** (3.125 / 1200))), 0 * 2pi) * ((0 - 22)).dbamp);
    aB = (aB * kB);
    aL = (((((((aV0 * 0.8) + (aV1 * 0.7)) + (aV2 * 0.5)) + (aV3 * 0.3)) + (aV4 * 0.2)) / 2.5) * kA);
    aR = (((((((aV0 * 0.2) + (aV1 * 0.3)) + (aV2 * 0.5)) + (aV3 * 0.7)) + (aV4 * 0.8)) / 2.5) * kA);
    aL = RLPF.ar(aL, (2600.0).clip(20, 18000), (1 / 1.2).clip(0.05, 2));
    aR = RLPF.ar(aR, (2600.0).clip(20, 18000), (1 / 1.2).clip(0.05, 2));
    aL = (aL + (aB * 0.6));
    aR = ((aR * 0.85) + (aB * 0.8));
    };
    aL = (((((aL * 1.1)).tanh / 1.1) * ((0 - 8)).dbamp) * (0.5 + (0.5 * iVelocity)));
    aR = (((((aR * 1.1)).tanh / 1.1) * ((0 - 8)).dbamp) * (0.5 + (0.5 * iVelocity)));
    Out.ar(out, [aL, aR]);
        EnvGen.kr(Env.asr(0.0001, 1, 2.2), gate, doneAction: 2);
    }),
    SynthDef(\pgPolarBeaconEffects, { |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 aEndMid = 0, aEndSide = 0, aL = 0, aR = 0, aRoomInL = 0, aRoomInR = 0, aRoomL = 0, aRoomMid = 0;
    var aRoomPreL = 0, aRoomPreR = 0, 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 = (SinOsc.kr(0.18, 0 * 2pi) * 1);
    aDelTimeL = K2A.ar((340.0 * (1 + (0.02 * kDelMotion))));
    aDelTimeR = K2A.ar((470.0 * (1 - (0.02 * kDelMotion))));
    aDelSendL = ((aL + aR) * 0.5);
    aDelSendR = 0;
    aEchoL = DelayC.ar((aDelSendL + (aDelFbR * 0.3)), 2200 / 1000, (aDelTimeL / 1000).clip(0.00002, 2200 / 1000));
    aEchoR = DelayC.ar((aDelSendR + (aDelFbL * 0.3)), 2200 / 1000, (aDelTimeR / 1000).clip(0.00002, 2200 / 1000));
    kDelCenter = (1700.0 * (2 ** (0.04 * kDelMotion)));
    aEchoL = HPF.ar(aEchoL, ((kDelCenter / (2 ** 1.5))).clip(20, 18000));
    aEchoL = LPF.ar(aEchoL, ((18000).min((kDelCenter * (2 ** 1.5)))).clip(20, 18000));
    aEchoR = HPF.ar(aEchoR, ((kDelCenter / (2 ** 1.5))).clip(20, 18000));
    aEchoR = LPF.ar(aEchoR, ((18000).min((kDelCenter * (2 ** 1.5)))).clip(20, 18000));
    aDelFbL = aEchoL;
    aDelFbR = aEchoR;
    aL = ((aL * 0.78) + (aEchoL * 0.22));
    aR = ((aR * 0.78) + (aEchoR * 0.22));
    };
    if((stage >= 4)) {
    aRoomInL = aL;
    aRoomPreL = DelayN.ar(aRoomInL, 0.03, 0.03);
    aRoomInR = aR;
    aRoomPreR = DelayN.ar(aRoomInR, 0.03, 0.03);
    room27 = FreeVerb2.ar(aRoomPreL, aRoomPreR, 1, 0.752295, 0.8);
    aRoomL = room27[0];
    aRoomR = room27[1];
    aRoomMid = ((aRoomL + aRoomR) * 0.5);
    aRoomSide = (((aRoomL - aRoomR) * 0.5) * 1);
    aL = ((aL * 0.8) + ((aRoomMid + aRoomSide) * 0.2));
    aR = ((aR * 0.8) + ((aRoomMid - aRoomSide) * 0.2));
    };
    if((stage >= 5)) {
    aEndMid = ((aL + aR) * 0.5);
    aEndSide = (((aL - aR) * 0.5) * 1.0);
    aEndSide = HPF.ar(aEndSide, (160.0).clip(20, 18000));
    aL = ((aEndMid + aEndSide) * (16.5).dbamp);
    aL = LeakDC.ar(aL, 0.995);
    aR = ((aEndMid - aEndSide) * (16.5).dbamp);
    aR = LeakDC.ar(aR, 0.995);
    };
    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]);
        "Polar Beacon 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.() };
)