# Build Hammered Room Keys in SuperCollider

A stock-unit SuperCollider interpretation of [the Ableton sound](/tutorials/hammered-room-keys/) and its [Csound version](/tutorials/hammered-room-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 struck three-register body

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 a pulse one octave above the note at −7 cents/−6 dB, a triangle two octaves above at −15 dB, and a quiet pulse at the played pitch at −27 dB. These fixed shapes interpret Basic Shapes positions and the colored sub rather than scan the original tables. The amplitude rises in 1 ms, decays over 1.4 s to −42 dB and releases over 250 ms.

| SuperCollider control | Value |
| --- | --- |
| Main source | Pulse, octave up, −7 cents, −6 dB |
| Upper / low layer | Triangle +24 st at −15 dB / pulse at −27 dB |
| Amplitude | 1 ms / 1.4 s / −42 dB / 250 ms |
| Instrument / touch | −3 dB / 50% |

<audio controls preload="none" aria-label="SuperCollider Hammered Room 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 — Close the strike filter quickly

Set `~soundStage = 2` in the full script. Apply a 1100 Hz ladder lowpass with +3 dB input drive and 0.062 resonance. Track pitch fully and open cutoff by 0.5 octaves under a 1 ms / 250 ms / zero / 100 ms contour. The fast spectral fall is independent of the longer amplitude decay.

| SuperCollider control | Value |
| --- | --- |
| Cutoff / resonance | 1100 Hz base / 0.062 |
| Envelope / key tracking | 0.5 octaves / full |
| Filter contour | 1 ms / 250 ms / zero / 100 ms |

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 Hammered Room 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 — Round the signal with saturation

Set `~soundStage = 3` in the full script. Use +22 dB drive with 50% shaped signal and -21 dB output trim. The smooth curve is `tanh(input × 3 × drive.dbamp) / 3`; the other portion stays clean. Louder peaks enter its curved region more strongly, adding harmonics and rounding the envelope. This interprets the source saturation curve rather than implementing its proprietary transfer function. A final tanh stage also interprets Soft Clip on the output.

| SuperCollider control | Value |
| --- | --- |
| Drive / output | 22 / -21 dB |
| Shaped mix | 50% |
| Input DC removal | Off |
| Post clip | tanh |

<audio controls preload="none" aria-label="SuperCollider Hammered Room 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.935902 and damping is 0.8125. 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.935902 |
| Damping | 0.8125 |
| Predelay | 8 ms |
| External room wet | 22% |

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

<audio controls preload="none" aria-label="SuperCollider Hammered Room 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/Hammered-Room-Keys.webm) · [Complete settings](ALL_PARAMETERS.md) · [Ableton version](/tutorials/hammered-room-keys/) · [Csound version](/tutorials/hammered-room-keys/csound/)

## Full SuperCollider script

The complete Hammered Room 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 = 1.428573;
~soundRelease = 0.25;
~soundNames = (motion: \pgHammeredRoomKeysMotion, voice: \pgHammeredRoomKeysVoice, effects: \pgHammeredRoomKeysEffects);
~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(\pgHammeredRoomKeysMotion, { |out=0| Out.kr(out, DC.kr(0)) }),
    SynthDef(\pgHammeredRoomKeysVoice, { |out=0, midi=60, velocity=0.8, gate=1, startMidi=60|
        var stage = ~soundStage;
    var aA = 0, aB = 0, aL = 0, aR = 0, aSource = 0, aSub = 0, iHz = 0, iVelocity = 0;
    var kAmp = 0, kCut = 0, kFilter = 0;
    iHz = (midi).midicps;
    iVelocity = (velocity).clip(0, 1);
    aA = (Pulse.ar((iHz * (2 ** (1 - (7 / 1200)))), 0.5) * ((0 - 6)).dbamp);
    aB = (~pgTriangle.((iHz * 4), 0) * ((0 - 15)).dbamp);
    aSub = (Pulse.ar(iHz, 0.5) * ((0 - 27)).dbamp);
    aSource = ((aA + aB) + aSub);
    if((stage >= 2)) {
    kFilter = EnvGen.kr(Env([0, 1, 0, 0], [0.001, 0.25, 0.1], \lin, releaseNode: 2), gate);
    kCut = ((1100 * (2 ** ((0.5 * kFilter) + ((midi - 60) / 12))))).clip(30, 18000);
    aSource = MoogFF.ar((aSource * (3).dbamp), (kCut).clip(20, 18000), (0.062 * 4).clip(0, 3.95));
    };
    kAmp = EnvGen.kr(Env([0, 1, 0.007943282347242814, 0], [0.001, 1.4, 0.25], \lin, releaseNode: 2), gate);
    aL = (((aSource * kAmp) * ((0 - 3)).dbamp) * (0.5 + (0.5 * iVelocity)));
    aR = aL;
    Out.ar(out, [aL, aR]);
        EnvGen.kr(Env.asr(0.0001, 1, 0.25), gate, doneAction: 2);
    }),
    SynthDef(\pgHammeredRoomKeysEffects, { |in=0, out=0|
        var stage = ~soundStage;
        var outputScale = ~soundOutputScale;
        var input = In.ar(in, 2);
    var aCleanL = 0, aCleanR = 0, aL = 0, aR = 0, aRoomInL = 0, aRoomInR = 0, aRoomL = 0, aRoomMid = 0;
    var aRoomPreL = 0, aRoomPreR = 0, aRoomR = 0, aRoomSide = 0, aShapeL = 0, aShapeR = 0, room17 = 0;
    aL = input[0];
    aR = input[1];
    if((stage >= 3)) {
    aCleanL = aL;
    aShapeL = ((((aCleanL * 3) * (22).dbamp)).tanh / 3);
    aL = (((aCleanL * 0.5) + (aShapeL * 0.5)) * ((0 - 21)).dbamp);
    aCleanR = aR;
    aShapeR = ((((aCleanR * 3) * (22).dbamp)).tanh / 3);
    aR = (((aCleanR * 0.5) + (aShapeR * 0.5)) * ((0 - 21)).dbamp);
    aL = (aL).tanh;
    aR = (aR).tanh;
    };
    if((stage >= 4)) {
    aRoomInL = aL;
    aRoomPreL = DelayN.ar(aRoomInL, 0.008, 0.008);
    aRoomInR = aR;
    aRoomPreR = DelayN.ar(aRoomInR, 0.008, 0.008);
    room17 = FreeVerb2.ar(aRoomPreL, aRoomPreR, 1, 0.935902, 0.8125);
    aRoomL = room17[0];
    aRoomR = room17[1];
    aRoomMid = ((aRoomL + aRoomR) * 0.5);
    aRoomSide = (((aRoomL - aRoomR) * 0.5) * 0.8);
    aL = ((aL * 0.78) + ((aRoomMid + aRoomSide) * 0.22));
    aR = ((aR * 0.78) + ((aRoomMid - aRoomSide) * 0.22));
    };
    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]);
        "Hammered Room 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/hammered-room-keys/supercollider/)
