Skip to content

dbap

Distance-Based Amplitude Panning for arbitrary 2D and 3D loudspeaker layouts.

Implements the Distance-Based Amplitude Panning (DBAP) algorithm as described by Lossius and Baltazar.
The opcode is particularly suitable for irregular loudspeaker arrangements in both two- and three-dimensional configurations. A soft-limiting spread control is included to focus or defocus the spatial image by attenuating distant loudspeakers exponentially.

Syntax

    var:a[] = dbap(sig:a, mode:i, src:k[], lpos:i[][], sprd:k, rloff:i [, wgts:i[]])
    var:a[] = dbap(sig:a, mode:i, src:k[], ldim:i, lpos:i, sprd:k, rloff:i [, wgts:i[]])
    avar[] dbap asig, imode, ksrc[], ilpos[][], ksprd, irloff [, iwgts[]]
    avar[] dbap asig, imode, ksrc[], ildim, ilpos, ksprd, irloff [, iwgts[]]

Initialization

mode -- Coordinate interpretation mode. Specifies how loudspeaker coordinates are interpreted: 0 = cartesian coordinates (x, y, z); 1 = polar coordinates in degrees (rho, phi, theta or phi, theta); 2 = polar coordinates in radians (rho, phi, theta or phi, theta).

ldim -- Dimension of loudspeaker position (2 or 3). This argument is only required when a function table is used to define the loudspeaker positions, indicating whether the data represents a 2D or 3D layout.

lpos:i[][]/lpos:i -- Loudspeaker position definition. Defines the loudspeaker layout. It can be either: a 2D i-rate array of size n x 2 or n 3 (where n is the number of loudspeakers), or a function table containing the same data sequentially. Depending on coordinate mode arg, each loudspeaker can be defines in two- (x, y or phi, theta) or three-dimension (x, y, z or rho, phi, theta).

rloff -- rolloff coefficient controlling amplitude decay as a function of distance. Higher values produce a steeper attenuation with distance, increasing localization sharpness, while lower values result in a more diffuse spatial distribution.

wgts -- (optional, default to 1) per-loudspeaker weighting factors. If provided, the array must contain one value per loudspeaker. Each weight w_i scales the corresponding gain.

Performance

asig -- input signal

sprd:k -- spread factor (>= 0) controlling spatial focus. The gain for each loudspeaker is computed as

g_i = (k * w_i * b_i) / (d_i^a) * exp(-beta d_i)
where
beta = spread / (mean_distance + 1e-6)
The exponential term introduces a soft decay:
gain *= exp(-beta * distance)
Increasing sprd results in tighter spatial focus.
When sprd = 0, the algorithm reduces to the classical DBAP formulation.

Examples

Here is an example of the dbap opcode. It uses the file dbap.csd.

Example of the dbap opcode.
<CsoundSynthesizer>
<CsOptions>
-odac     // realtime audio out
</CsOptions>
<CsInstruments>

sr = 44100
ksmps = 1
nchnls = 8
0dbfs  = 1

/*
In instrument #1, a simple example of spatialization is applied to
a sinusoidal signal with a virtual source moving along the azimuth,
sequentially traversing all eight channels.
*/

instr 1
    asig = poscil(expseg:k(0.001, p3/2, 0.7, p3/2, .0001), 440) // test signal

    // define source
    source:k[] = [phasor:k(0.3) * 360, 0.0] // source position in degree with variable azimuth

    // set loudspeker positions
    lpos:i[][] = init(8, 2) // 8 channels 2D
    lpos = [0, 0, 45, 0, 90, 0, 135, 0, 180, 0, 225, 0, 270, 0, 315, 0]

    // define array of out channels
    smooth_decay:k = 3 // variable smooth_decay
    rolloff:i = 24.0 // rolloff
    dbap_sig:a[] = init(8) // out 8 channels
    dbap_sig = dbap(asig, 1, source, lpos, smooth_decay, rolloff) // process with

    out(dbap_sig)
endin
</CsInstruments>
<CsScore>

i 1 0 10

</CsScore>
</CsoundSynthesizer>

See also

Panning and Spatialization: Distance Based Amplitude Panning

Credits

Author: Pasquale Mainolfi
Italy
New in Csound version 7.0 February 2026.