Audio · function

foaDecodeGain

How much of a field a speaker in a world direction should be given.

Explained in Your first game.

function foaDecodeGain(field: ArrayLike<number>, at: number, dirX: number, dirY: number, dirZ: number, speakers: number): number
import { foaDecodeGain } from '@driftengine/audio';

Parameters

ParameterTypeDescription
fieldArrayLike<number>
atnumber
dirXnumber
dirYnumber
dirZnumber
speakersnumber

In depth

The projection decode: a cardioid pointed at the speaker, (W + d · (X, Y, Z)) / speakers. For a field holding one source it is unity where the speaker faces the source, zero on the antipode, and the gains over an octahedron sum to exactly one — so a field is neither louder nor quieter for having been decoded.

dir is in world axes and is converted here. It need not be unit.