Glitch is a great tool if you want to start with algorithmic music. It’s simple and straightforward. To master Glitch you only need to remember 15 functions.

But moving from bytebeat and oscillators to actual music might be difficult for newcomers. Let’s see how you can make synthesized kick drum, snare and hi-hats with just a few lines of Glitch.

Hi-hats

Hi-hats are probably the easiest ones to synthesize because they are basically white noise. It can be generated by the r() function (a random number generator). Adding an envelope to the white noise makes it sound more like a drum. But white noise contains some low frequencies in it, so to make our hats sound higher we will subtract a low-pass filter signal from it:

hat=env(r(128), (0.01, 1), (0.01, 0.1), (0.05, 0))

hpf(hat, 10000)

Here’s an example of playing some sequence of beats with hi-hats:

bpm = 120

hats = seq(bpm*4, 0.1, 0.2)

hat=env(r(128)*hats, (0.01, 0.1), (0.05, 0))

hpf(hat, 10000)

You can try it here.

Kick

Kick (bass drum) has a low pitch. Let’s start with sin(50) as a drum oscillator. Now let’s make a contour of the sound similar to a real kick drum. It should have a fast attack and a short release tail (click the link to play it in Glitch):

kickhz=50, env(sin(kickhz), (0.001, 1), (0.1, 0))

A slightly better sound can be achieved if we an envelope curved:

bpm=80,

kicks=seq(bpm*4, 1, 0, 0, 0.6),

kickhz=50,

kick=env(kicks*sin(kickhz), (0.1, 0.3), (0.1, 0)),

kick=lpf(kick, 250)

It wouldn’t hurt to add a low-pass filter to make our bass sound deeper. You can try it here.

Snare

It’s an interesting drum because it starts with a short clear pitch that is quickly mixed with some high-pitch noise. It’s loud and has staccato sound which means it’s short and sharp.

Let’s start with a tone, say 220 Hz. I picked it randomly, I think snares are tuned somewhere in the range 200..300 Hz.

snarehz=220

snaretone=env(sin(snarehz), (0.005, 1), (0.01, 0.2), (0.03, 0))

You’re right, it sounds more like kick (because we used a similar envelope and the same oscillator). Now let’s add some noise to it. Noise will have slower attack:

snarehz=220

snaretone=env(sin(snarehz), (0.005, 1), (0.01, 0.2), (0.03, 0))

snarenoise=env(r(), (0.02, 1), (0.03, 0.2), (0.04, 0))

(snaretone + snarenoise)/2

A better sound can be achieved by tweaking the envelope curve and filtering out the low frequencies from the noise:

bpm=120

snarehz=220

snares=seq(bpm*2, 0.5, 0.1, 0.5, 0.2)

snaretone=env(snares*sin(snarehz), (0.005, 1), (0.01, 0.2), (0.03, 0))

snarenoise=env(snares*r(), (0.001, 1), (0.02, 0.01), (0.01, 0))

snare = (snaretone + snarenoise)/2

The resulting drum can be heard here.

Example

Here I combined all three drums into a simple drum pattern used in many rock songs. It’s built upon the same formulas, just with slightly different coefficients:

bpm=80

kicks=seq(bpm*4, 1, 0, 0, 0.6, 1, 0, 0, 1, 0, 0, 0, 0.2, 1, 0, 0, 0)

kickhz=50

kick=env(kicks*sin(kickhz), (0.001, 1), (0.05, 0.3), (0.1, 0))

kick=lpf(kick, 150)

hats=seq(bpm*4, 0.7, 0.5, 1, 0.5, 0.7, 0.5, 1, 0.5, 0.7, 0.5, 1, 0.7, 0.7, 0.5, 0.7, 0.5)

hatfilters=seq(bpm*4, 1, 1, 2, 1, 1, 1, 2, 1, 1, 2, 2.5, 1, 1, 2, 1)

hat=env(r()*hats, (0.01, 1), (0.03, 0.2), (0.02, 0))

hat=hpf(hat, 1000*hatfilters)

snares=seq(bpm*4, 0, 0, 0.5, 0)

snarehz=220

snaretone=env(sin(snarehz)*snares, (0.005, 1), (0.01, 0.2), (0.03, 0))

snarenoise=env(r()*snares,(0.02, 1), (0.03, 0.2), (0.04, 0))

snare = (snaretone + snarenoise)/2

mix(kick, 0.3*hat, snare)

You can open it in Glitch and adjust to your own taste. Or would you like to build your own drum pattern with Glitch?

Glitch is a minimal open source algorithmic music composer that uses simple mathematical formulas. It’s easy to learn (it’s all just arithmetic expressions), easy to use (runs in your browser), easy to share (just send a link).