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): AudioBufferimport { metalBuffer } from '@driftengine/audio';Parameters
| Parameter | Type | Description |
|---|---|---|
ctx | BaseAudioContext | |
seconds | number | Total length. Metal rings on; too short and it is a click. |
baseHz | number | The fundamental the partials are built off. |
decay | number | How 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.