BEEP BOOP

How Beep Boop makes a sound

Beep Boop's kits are not recordings. Every drum hit and every synth note is worked out sample by sample as it plays, in C, on the audio thread, from a few numbers a sound. This is the whole path, from a step to the speaker.

Fig. 1
How a sound is made. A drum voice: a sine tone that falls in pitch, and noise through a filter set between 40 and 8,000 hertz, summed, then TEAR, then the voice's level and its mix level. A synth voice: two oscillators and a sine sub an octave down, through a low-pass filter with its own envelope, then the note's envelope, attack, decay, sustain and release, then TEAR. Every voice, the pads and the loop are summed, and the whole mix passes one soft clip with a ceiling 1 dB under full scale before the output.A DRUM VOICETONEFALLING SINENOISEFILTER40 TO 8,000 HZTEARLEVELVOICE AND MIXA SYNTH VOICEOSC 1OSC 2SUBOCTAVE DOWNLOW-PASSITS OWN ENVELOPEENVELOPEADSRTEARMIXPADS AND LOOP TOOSOFT CLIPCEILING -1 DBOUT
Two voices, one path out. Nothing in either is a recording: every sound is worked out, sample by sample, as it plays. TEAR is skipped entirely while it is at 0.

A drum voice

A drum is two sources. A tone, a sine wave that starts high and falls to its own pitch, gives a kick or a tom its body. Noise, through a filter, gives a snare its rattle and a hat its hiss. The noise is a fast pseudo-random sequence, and the filter is a state-variable design that can take the low, the middle or the high of it, held between 40 and 8,000 hertz so that no setting can run it out of bounds. A clap is the same noise struck again, in bursts 10 milliseconds apart.

Each part fades by multiplying itself by one number every sample, so a fade costs one multiplication. A drum sound is the list of those numbers: fifteen of them, twelve for the tone, the noise and their fades, and three more for sounds that move. A kick drum is twelve numbers goes through one of them.

DRUMS turns each voice two ways. TONE moves the filter up to an octave and a half brighter or darker, and the pitch by up to half an octave. DECAY makes the fades a quarter as long, up to four times as long. Both are worked out once, as the hit begins, so the next hit sounds the change. A closed hat cuts off an open one, as on a real kit, with a short fade so that it does not click. A step held to accent is struck 1.35 times as hard.

A synth voice

A synth note is three oscillators summed: two that can each be a sine, a triangle, a saw or a square, and a sine an octave below them. A saw or a square has a hard edge, which on a computer folds back into the sound as harsh tones that were never played. A small correction at each edge, PolyBLEP, takes them out.

The sum goes through a low-pass filter with resonance, built so that it stays stable at any setting, and that filter opens and closes on an envelope of its own. Then the note's envelope shapes its loudness: attack, decay, sustain and release. On an accented note the sound is driven into the filter a little harder, so it brightens as well as gets louder.

Each note is tuned a hair off, at random by up to 3 cents either way, so that a chord breathes instead of standing still. SYNTH sounds up to eight notes at once, and each of the twelve pads has a voice of its own. On SYNTH, TONE moves the filter up to three octaves either way, DECAY scales the envelopes from a quarter to four times, and GLIDE slides one note into the next over up to a quarter of a second.

TEAR

SOUNDS has one knob that takes a sound from clean to destroyed. It is five processes laid along one number, each fading in over its own part of the turn.

Fig. 2
TEAR, from clean at 0 to 100, with the span over which each of its five stages fades in: fold from 5 to 60, a wavefolder, drive to 7 times; bits from 15 to 100, 16 bits down to 3; hold from 30 to 100, each sample held for up to 40; ring from 45 to 100, a ring, 60 hz to about 2.5 khz; fragments from 65 to 100, slices of the last 40 ms, repeated.CLEAN255075100FOLDA WAVEFOLDER, DRIVE TO 7 TIMESBITS16 BITS DOWN TO 3HOLDEACH SAMPLE HELD FOR UP TO 40RINGA RING, 60 HZ TO ABOUT 2.5 KHZFRAGMENTSSLICES OF THE LAST 40 MS, REPEATED
TEAR's one knob, to scale. Each bar is where a stage fades in. Low on the knob is grit; the top is abstract. At 0 the stage is not run at all, so a clean sound plays sample for sample.

The fold bends the wave back on itself, so a sine grows edges. The bits cut its resolution until a quiet tail falls to nothing. The hold repeats each sample for longer, so the sound loses its top. The ring multiplies it by a second tone, which makes it metallic. At the top, fragments of the last 40 milliseconds are frozen and repeated, with holes in them. Each voice carries its own 2,048 samples of memory for that, set aside before it plays, so tearing a sound allocates nothing.

At 0 TEAR is not run at all. A sound with no tear plays sample for sample as it did before TEAR existed, which a test holds the engine to.

The mix

Every drum voice is multiplied by its own level and its mix level. SYNTH, the pads and the loop are added. The sum is turned down 2 dB and passes one soft clip, a curve that rounds a peak instead of cutting it, with a ceiling 1 dB under full scale. Nothing leaves the engine louder than that.

The 2 dB was measured. At full level the first beat drove the clip to 2.6 times full scale and rounded off 14.6 percent of its samples by more than 1 dB. At 2 dB down that is 7.0 percent, and every kick keeps about 1 dB more front.

What it costs

With every voice playing at once, eight drums on every step, eight synth notes and twelve pads, the engine used 3.38 percent of real time on a Mac, and 4.80 percent with every one of them torn at full. That is a measurement on a Mac. The same number on a phone is still owed, and so is a run of every voice at once on the phone itself.

Sources

More sheets

  1. An instrument in SwiftUIOne accent, a key lit from inside, nothing unneeded.
  2. Every note in keyEight rows, one scale, no wrong notes.
  3. A kick drum is twelve numbersHow a drum machine's kit is built.
  4. The audio thread never waitsNo allocation, no lock, one queue.
  5. PatternsDrum patterns drawn on sixteen steps.
  6. Tempo by genreBPM for twelve genres, on one scale.