PannerNode
The PannerNode interface positions an audio source in 3D space relative to the context's AudioListener.
Constructor
constructor(context: BaseAudioContext, options?: PannerOptions)
PannerOptions
Inherits all properties from AudioNodeOptions.
| Parameter | Type | Default | |
|---|---|---|---|
panningModel Optional | 'equalpower' | 'equalpower' | Spatialization algorithm (equal-power only). |
distanceModel Optional | 'linear' | 'inverse' | 'exponential' | 'inverse' | Distance attenuation model. |
positionX … positionZ Optional | number | (0, 0, 0) | Initial source position. |
orientationX … orientationZ Optional | number | (1, 0, 0) | Initial source orientation. |
refDistance Optional | number | 1 | Reference distance for attenuation. |
maxDistance Optional | number | 10000 | Maximum distance for the linear model. |
rolloffFactor Optional | number | 1 | Rolloff for distance models. |
coneInnerAngle / coneOuterAngle Optional | number | 360 | Directional cone angles (degrees). |
coneOuterGain Optional | number | 0 | Gain outside the outer cone. |
You can also create a PannerNode via BaseAudioContext.createPanner().
Example
Position a tone to the listener's left. Use headphones to hear the pan clearly. The default listener faces -Z.
import { AudioContext } from 'react-native-audio-api';
const ctx = new AudioContext();
const osc = ctx.createOscillator();
const panner = ctx.createPanner();
panner.panningModel = 'equalpower';
panner.positionX.value = -3;
panner.positionY.value = 0;
panner.positionZ.value = -1;
osc.connect(panner);
panner.connect(ctx.destination);
osc.start();
To move the listener instead of the source, set ctx.listener position params the same way.
Properties
Inherits all properties from AudioNode.
AudioNodeproperties| Name | Type | Description |
|---|---|---|
positionX, positionY, positionZ | AudioParam | Source position in 3D space. |
orientationX, orientationY, orientationZ | AudioParam | Source orientation vector. |
panningModel | PanningModelType | 'equalpower' only. |
distanceModel | DistanceModelType | 'linear', 'inverse', or 'exponential'. |
refDistance, maxDistance, rolloffFactor | number | Distance model parameters. |
coneInnerAngle, coneOuterAngle, coneOuterGain | number | Directional cone. |
Methods
Inherits all methods from AudioNode.
AudioNodemethodsPannerNode does not define any additional methods.
Remarks
- Output is always stereo (2 channels), like
StereoPannerNode. - Spatialization uses the context's
listenerposition and orientation. panningModelsupports'equalpower'only.