Audio · function

distanceGain

Level for a source distance away, reaching exactly zero at radius.

Explained in Your first game.

function distanceGain(distance: number, radius: number, curve?: number): number
import { distanceGain } from '@driftengine/audio';

Parameters

ParameterTypeDescription
distancenumber
radiusnumber
curve?number

In depth

Zero at the edge is the part that matters. Physical falloff is 1/d², which never quite arrives — and a route carrying a dozen braziers then sums into a permanent hiss the player can neither identify nor walk away from. A curve that ends is worth more here than one that is correct.

curve shapes the approach: 1 is linear, 2 concentrates the change near the source, which is where a player's own movement makes it legible.