The kick: a sine wave with a falling pitch
Build the trance kick from first principles, tune it to the key, and program four-on-the-floor.
Goal
A punchy kick on every beat, tuned to the song's key, built from nothing but a sine wave.
The idea
Hit a real kick drum and the skin starts off moving fast and tight, then relaxes into its natural low note. So its pitch starts high and falls quickly. That downward sweep is the thump you feel in your chest. Two ingredients copy it:
- A sine whose frequency falls, from about 150 Hz to about 55 Hz in a few tens of milliseconds. The fast drop is the punch; the resting pitch is the weight.
- A volume that decays over a few hundred milliseconds. Long decay, boomy kick. Short decay, tight kick.
Optionally a soft clipper (drive) squashes the peaks. That adds harmonics, so the kick survives on laptop speakers that can't play 55 Hz at all.
The resting pitch is a real note. Our track is in A, and 55 Hz is A1, the same note as the bass root (MIDI 33), so End pitch goes to exactly 55. A kick on the wrong note fights the bass all song long.
The maths per sample is tiny: a pitch that decays exponentially, a sine of the accumulated phase, a falling level. Here's the whole instrument:
Show the full code: trance_kick.jsfx (77 lines)
desc:Trance Kick
// A kick drum from first principles:
// 1. a sine wave whose PITCH starts high and falls fast (the "thump")
// 2. multiplied by a VOLUME envelope that decays away
// 3. optionally squashed by a soft clipper for extra harmonics
// Every incoming MIDI note-on triggers the drum; the note number is ignored.
slider1:150<40,400,1>Start pitch (Hz)
slider2:55<30,80,0.5>End pitch (Hz)
slider3:35<5,200,1>Pitch fall time (ms)
slider4:300<80,800,1>Decay time (ms)
slider5:6<0,24,0.5>Drive (dB)
slider6:-3<-24,0,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.
ev_off = 0; // event queue: up to 16 note-ons per audio block
ev_vel = 16;
function tanh_(x) local(e) (
x = min(max(x, -20), 20);
e = exp(2 * x);
(e - 1) / (e + 1);
);
playing = 0;
t = 0;
phase = 0;
@slider
// Runs whenever a slider moves: turn slider values into ready-to-use numbers.
pitch_tau = slider3 * 0.001;
amp_tau = slider4 * 0.001 / 6.9; // 6.9 time-constants = 60 dB drop
drive = 10 ^ (slider5 / 20);
outgain = 10 ^ (slider6 / 20);
drive_norm = 1 / tanh_(drive);
@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)) (
(m1 & 0xF0) == 0x90 && m3 > 0 && ev_n < 16 ? (
ev_off[ev_n] = offs;
ev_vel[ev_n] = m3 / 127;
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) (
vel = ev_vel[ev_i];
playing = 1;
t = 0;
phase = 0;
ev_i += 1;
);
s = 0;
playing ? (
freq = slider2 + (slider1 - slider2) * exp(-t / pitch_tau);
phase += 2 * $pi * freq / srate;
phase > 2 * $pi ? phase -= 2 * $pi;
s = sin(phase) * exp(-t / amp_tau);
s = tanh_(s * drive) * drive_norm;
s *= vel * outgain;
t += 1 / srate;
t > slider4 * 0.001 * 1.5 ? playing = 0;
);
spl0 = s;
spl1 = s;
blk_pos += 1;
Reading it:
@initruns once;@sliderruns when a slider moves and turns slider values into ready-to-use numbers.@blockruns before each chunk of audio. It reads incoming MIDI notes and queues them with their exact offsets, so the kick starts on the right sample, not at the start of a buffer.@sampleruns for every single sample: work out the current frequency, advance the phase, multiply by the decaying level, squash throughtanh_.
Build it
- Open the project from Project setup and installing the instruments. The
Kicktrack already has Trance Kick and a one-bar item. - Set the sliders:
| Slider | Value | Why |
|---|---|---|
| Start pitch (Hz) | 150 | where the punch starts |
| End pitch (Hz) | 55 | the A of our key |
| Pitch fall time (ms) | 35 | how fast it drops |
| Decay time (ms) | 300 | time to fall 60 dB |
| Drive (dB) | 6 | a few extra harmonics |
| Output (dB) | -3 | headroom |
- Put one note on each beat, velocity about 110. Any pitch, any length: the kick only cares when a note starts.
Step: 1 . . . 2 . . . 3 . . . 4 . . . (16th-note steps; 1 2 3 4 are the beats)
Kick: X . . . X . . . X . . . X . . .
- Drag the item's right edge out to the end of bar 16. New MIDI items loop, so the bar repeats. (Or Ctrl-drag to copy it.)
- Loop the first four bars and play.
- trance_kick.mid Kick, 1 bar, four on the floor
Drag a file onto the track at the bar where it starts. How: using the MIDI files.
Listen for
- A steady thump with a clear click-then-boom.
- No distortion, no rattle, and each tail gone before the next kick.
Try this
One slider at a time, while it loops:
- Start pitch at 300+: a clicky beater. At 80: a soft thud.
- Pitch fall time at 10 ms: snappy. At 120 ms: a laser "pew".
- Decay time at 600 ms: boomy, runs into the bass. At 150 ms: tight.
- Drive at 0: a clean sub. At 18: gritty and loud.
- End pitch at 60: hear it clash with an A in the bass. Put it back to 55.
Why does a kick sound thumpy?
Its pitch starts high and falls fast to a low resting note.
Why is End pitch set to 55 Hz here?
55 Hz is A1, the key and the bass root. A kick on the same note doesn't clash.
What's the drive control for?
Soft clipping adds harmonics, so the kick is audible on speakers that can't play the lowest notes.
Why read MIDI in @block but start the sound in @sample?
So the kick starts on the exact sample where the note begins, not at the start of a buffer.