Hi-hats and clap: drums from noise
Make a closed hat, an open hat and a clap from filtered white noise, and program the classic trance drum pattern.
Goal
Closed hat, open hat and clap from one instrument, plus the drum pattern that sits on top of the kick.
The idea
A kick is a note. Hats and claps aren't: they're a dense splash of every frequency at once, with no pitch. That's White noise, so all three sounds are the same recipe:
white noise → filter → volume envelope
- Filter. A hat is the top of the noise: a High-pass filter at 7 kHz leaves only the hiss. A clap keeps more middle: high-pass at 800 Hz, and a Low-pass filter trims the top at 6 kHz.
- Envelope. Closed and open hats are the same sound with different Decay: 45 ms is a tight "tss", 220 ms rings.
- Clap. Real claps are several hands landing a few milliseconds apart. So we retrigger the envelope four times, 12 ms apart, and let the last one ring.
The filters are one line of code each. The simplest low-pass is y += a * (x - y): the output chases the input, and a small a makes it chase slowly, so fast wiggles (highs) get smoothed away. A high-pass is the input minus that: x - y, whatever the smoothing removed. Two stages of each for a steeper slope.
Note numbers and lengths are ignored, like the kick. There's also a Hold mode that keeps the sound going while the note is held; the riser uses it in Risers, fills and impacts.
Show the full code: trance_noise_drum.jsfx (110 lines)
desc:Trance Noise Drum
// Hi-hats, claps and risers from one idea:
// white noise -> high-pass filter -> low-pass filter -> volume envelope
// Every MIDI note-on triggers it; the note number is ignored.
// All "times" are the time the sound takes to fall by 60 dB.
slider1:7000<200,16000,1:log=2500>High-pass cutoff (Hz)
slider2:18000<1000,20000,1:log=6000>Low-pass cutoff (Hz)
slider3:1<0.5,3000,0.5:log=30>Attack (ms)
slider4:60<5,4000,1:log=200>Decay (ms)
slider5:0<0,1,1{One-shot,Hold while note is held}>Mode
slider6:1<1,6,1>Bursts (1 = hat, 3-4 = clap)
slider7:12<4,40,0.5>Burst spacing (ms)
slider8:0.5<0,1,0.01>Stereo width
slider9:0<-36,12,0.5>Output (dB)
in_pin:none
out_pin:Left
out_pin:Right
@init
// Runs once when the effect loads: set up variables and helper functions.
// A band of noise: two 6 dB/oct high-pass stages, then two low-pass stages.
// Each stage is a one-pole low-pass "y += a*(x-y)"; subtracting it from the
// input gives the matching high-pass.
function band_set(hpf, lpf) instance(ha, la) (
ha = 1 - exp(-2 * $pi * hpf / srate);
la = 1 - exp(-2 * $pi * min(lpf, srate * 0.45) / srate);
);
function band(x) instance(a1, a2, b1, b2, ha, la) (
a1 += ha * (x - a1); x -= a1;
a2 += ha * (x - a2); x -= a2;
b1 += la * (x - b1);
b2 += la * (b1 - b2);
b2;
);
ev_off = 0; // event queue: up to 16 events per audio block
ev_kind = 16;
ev_vel = 32;
stage = 0; // 0 = silent, 1 = attack, 2 = decay / hold
env = 0;
held = 0;
@slider
// Runs whenever a slider moves: turn slider values into ready-to-use numbers.
nl.band_set(slider1, slider2);
nr.band_set(slider1, slider2);
att_inc = 1 / (slider3 * 0.001 * srate);
dm_full = exp(-6.9 / (slider4 * 0.001 * srate));
dm_burst = exp(-6.9 / (slider7 * 0.001 * 2.4 * srate)); // dips ~25 dB between claps
spacing = max(1, floor(slider7 * 0.001 * srate));
gain = 10 ^ (slider9 / 20);
@block
// Runs before each chunk of audio: read the incoming MIDI notes here.
blk_pos = 0;
ev_n = 0;
ev_i = 0;
while (midirecv(offs, m1, m2, m3)) (
st = m1 & 0xF0;
ev_n < 16 ? (
st == 0x90 && m3 > 0 ? ( ev_off[ev_n] = offs; ev_kind[ev_n] = 1; ev_vel[ev_n] = m3 / 127; ev_n += 1; )
: (st == 0x80 || st == 0x90) ? ( ev_off[ev_n] = offs; ev_kind[ev_n] = 0; ev_n += 1; );
);
);
@sample
// Runs once for EVERY audio sample (44,100+ times a second): make the sound here.
while (ev_i < ev_n && ev_off[ev_i] <= blk_pos) (
ev_kind[ev_i] ? (
vel = ev_vel[ev_i];
held = 1;
stage = 1;
bursts_left = slider6 - 1;
timer = spacing;
) : (
held = 0;
);
ev_i += 1;
);
// extra bursts (claps): re-open the envelope every `spacing` samples
bursts_left > 0 ? (
timer -= 1;
timer <= 0 ? ( stage = 1; bursts_left -= 1; timer = spacing; );
);
stage == 1 ? (
env += att_inc;
env >= 1 ? ( env = 1; stage = 2; );
) : stage == 2 ? (
slider5 == 1 && held ? (
env = 1; // hold mode: stay open
) : (
env *= (bursts_left > 0 ? dm_burst : dm_full);
env < 0.0001 ? ( env = 0; stage = 0; );
);
);
stage ? (
n1 = rand(2) - 1;
n2 = rand(2) - 1;
n2 = n1 + (n2 - n1) * slider8; // width 0 = same noise both sides
spl0 = nl.band(n1) * env * vel * gain;
spl1 = nr.band(n2) * env * vel * gain;
) : (
spl0 = spl1 = 0;
);
blk_pos += 1;
Download trance_noise_drum.jsfx
Build it
- Three tracks:
Hat Closed,Hat Open,Clap. Trance Noise Drum on each. - Sliders (anything not listed stays default):
| Slider | Hat Closed | Hat Open | Clap |
|---|---|---|---|
| High-pass cutoff (Hz) | 7000 | 6000 | 800 |
| Low-pass cutoff (Hz) | 18000 | 18000 | 6000 |
| Attack (ms) | 1 | 1 | 1 |
| Decay (ms) | 45 | 220 | 150 |
| Mode | One-shot | One-shot | One-shot |
| Bursts | 1 | 1 | 4 |
| Burst spacing (ms) | 12 | 12 | 12 |
| Stereo width | 0.5 | 0.6 | 0.6 |
| Output (dB) | 0 | 0 | 0 |
- A one-bar MIDI item on each, grid 1/16, notes as below. The open hat's 220 ms ring ends as the next beat arrives (two sixteenths at this tempo).
Step: 1 . . . 2 . . . 3 . . . 4 . . .
Kick: X . . . X . . . X . . . X . . .
Hat Open: . . X . . . X . . . X . . . X .
Hat Closed: . X . X . X . X . X . X . X . X
Clap: . . . . X . . . . . . . X . . .
- Velocities: open hat about 100, closed hat about 70, clap about 110. Different velocities are half of what makes a groove feel played.
- Stretch each item to the end of bar 16. We place them properly in Arrangement: putting the whole song together.
- Loop bars 1 to 4 and play.
- trance_hat_open.mid Open hat, 1 bar, offbeats
- trance_hat_closed.mid Closed hat, 1 bar
- trance_clap.mid Clap, 1 bar, beats 2 and 4
Drag a file onto the track at the bar where it starts. How: using the MIDI files.
Listen for
- The open hat on the "and" between kicks. That off-beat hat is the bounce in trance.
- Closed hats ticking softly in between.
- A clap that sounds like hands, not a machine gun. Too gappy? Lower Burst spacing.
Try this
- Sweep the closed hat's High-pass cutoff from 200 to 12000: snare wash at the bottom, thin sizzle at the top.
- Clap Bursts at 1, 2, 4, 6: one "tch" turns into a crowd.
- Stereo width 0 vs 1: the same noise in both ears, then independent noise in each (wide).
- On a copy: Attack 400 ms, Decay 20 ms. A reverse cymbal, and the seed of a riser.
Why is white noise the raw material for hats and claps?
It has every frequency at once and no pitch, like a cymbal or a clap.
What's the difference between the closed and open hat here?
Decay (45 vs 220 ms) and a slightly lower high-pass on the open one.
How does the instrument make a high-pass from a low-pass?
Subtracts the low-passed signal from the original, leaving the highs.
How is a clap made from one noise generator?
Retrigger the envelope a few times, milliseconds apart, and let the last one ring.