The rolloffFactor
property of the PannerNode
interface is a double value describing how quickly the volume is reduced as the source moves away from the listener. This value is used by all distance models. The rolloffFactor
property's default value is 1
.
A number whose range depends on the distanceModel
of the panner as follows (negative values are not allowed):
-
"
linear
" -
The range is 0 to 1.
-
"
inverse
" -
The range is 0 to Infinity
.
-
"
exponential
" -
The range is 0 to Infinity
.
This example demonstrates how different rolloffFactor
values affect how the volume of the test tone decreases with increasing distance from the listener:
const context = new AudioContext();
const NOTE_LENGTH = 4;
const Z_DISTANCE = 20;
const scheduleTestTone = (rolloffFactor, startTime) => {
const osc = new OscillatorNode(context);
const panner = new PannerNode(context);
panner.rolloffFactor = rolloffFactor;
panner.positionZ.setValueAtTime(0, startTime);
panner.positionZ.linearRampToValueAtTime(Z_DISTANCE, startTime + NOTE_LENGTH);
osc.connect(panner).connect(context.destination);
osc.start(startTime);
osc.stop(startTime + NOTE_LENGTH);
};
scheduleTestTone(1, context.currentTime);
scheduleTestTone(0.5, context.currentTime + NOTE_LENGTH);
scheduleTestTone(0.1, context.currentTime + NOTE_LENGTH * 2);
After running this code, the resulting waveforms should look something like this: