Audio · function

metalBuffer

A struck metal ring: inharmonic partials over a bright transient.

Explained in Your first game.

function metalBuffer(ctx: BaseAudioContext, seconds: number, baseHz: number, decay: number): AudioBuffer
import { metalBuffer } from '@driftengine/audio';

Parameters

ParameterTypeDescription
ctxBaseAudioContext
secondsnumberTotal length. Metal rings on; too short and it is a click.
baseHznumberThe fundamental the partials are built off.
decaynumberHow fast the whole thing dies away.

In depth

The one thing that separates metal from every other synthesised hit is that its partials are not whole multiples of the fundamental. A harmonic stack reads as a bell at best and an organ at worst; detuning the partials by irrational-ish ratios is what makes the ear hear a struck bar. The ratios below are near a free bar's own modes rather than exact, which keeps it from ringing like a tuned instrument.

Each partial decays at its own rate, faster the higher it is, because that is what real metal does and it is most of why a synthesised clang usually sounds like a synthesiser: hold the top partials as long as the bottom and you get a chime.