Class PannerNode
Positions a source in 3D space relative to the context's AudioListener,
the Web Audio PannerNode. The output is stereo.
Azimuth and elevation, distance attenuation and the sound cone follow the
specification's algorithms exactly. PanningModel.EQUALPOWER (the default)
pans by azimuth; PanningModel.HRTF renders binaurally for headphones.
OfflineAudioContext audio = new OfflineAudioContext(2, 44100, 44100);
OscillatorNode footsteps = audio.createOscillator();
PannerNode p = audio.createPanner();
p.setPanningModel(PanningModel.HRTF);
p.setDistanceModel(DistanceModelType.INVERSE);
p.setRefDistance(1);
p.setPosition(3, 0, -2); // ahead and to the right
footsteps.connect(p).connect(audio.getDestination());
audio.getListener().setPosition(0, 0, 0);
Positions and orientation are audio rate AudioParams and can be
automated: p.getPositionX().linearRampToValueAtTime(-3, now + 4) moves the
source across the listener. Attributes such as the distance model are
applied from the next render quantum.
-
Method Summary
Modifier and TypeMethodDescriptiondoubleThe angle, in degrees, of the cone inside which there is no cone attenuation; 360 by default.doubleThe angle, in degrees, outside which the gain isgetConeOuterGain(); 360 by default.doubleThe gain outside the outer cone, 0 by default.The distance model.doubleThe distance past which the linear model attenuates no further, 10000 by default.X of the direction the source faces, 1 by default.Y of the direction the source faces, 0 by default.Z of the direction the source faces, 0 by default.The panning model.Position on X, 0 by default.Position on Y, 0 by default.Position on Z, 0 by default.doubleThe distance at which attenuation starts, 1 by default.doubleHow fast the volume falls with distance, 1 by default.voidsetConeInnerAngle(double angle) Sets the inner cone angle.voidsetConeOuterAngle(double angle) Sets the outer cone angle.voidsetConeOuterGain(double gain) Sets the gain outside the outer cone.voidSets the distance model.voidsetMaxDistance(double maxDistance) Sets the distance past which the linear model attenuates no further.voidsetOrientation(float x, float y, float z) Points the source now; only matters with a cone narrower than 360 degrees.voidsetPanningModel(PanningModel model) Sets the panning model.voidsetPosition(float x, float y, float z) Moves the source now.voidsetRefDistance(double refDistance) Sets the distance at which attenuation starts.voidsetRolloffFactor(double rolloffFactor) Sets how fast the volume falls with distance.Methods inherited from class AudioNode
connect, connect, connect, connect, disconnect, disconnect, disconnect, disconnect, disconnect, getChannelCount, getChannelCountMode, getChannelInterpretation, getContext, getNumberOfInputs, getNumberOfOutputs, setChannelCount, setChannelCountMode, setChannelInterpretation
-
Method Details
-
setPosition
public void setPosition(float x, float y, float z) Moves the source now.
Parameters
-
x: position on X -
y: position on Y -
z: position on Z
-
-
setOrientation
public void setOrientation(float x, float y, float z) Points the source now; only matters with a cone narrower than 360 degrees.
Parameters
-
x: direction X -
y: direction Y -
z: direction Z
-
-
getPositionX
Position on X, 0 by default.
Returns
the parameter
-
getPositionY
Position on Y, 0 by default.
Returns
the parameter
-
getPositionZ
Position on Z, 0 by default.
Returns
the parameter
-
getOrientationX
X of the direction the source faces, 1 by default.
Returns
the parameter
-
getOrientationY
Y of the direction the source faces, 0 by default.
Returns
the parameter
-
getOrientationZ
Z of the direction the source faces, 0 by default.
Returns
the parameter
-
getPanningModel
The panning model.
Returns
the model
-
setPanningModel
Sets the panning model.
Parameters
model: the model
-
getDistanceModel
The distance model.
Returns
the model
-
setDistanceModel
Sets the distance model.
Parameters
model: the model
-
getRefDistance
public double getRefDistance()The distance at which attenuation starts, 1 by default.
Returns
the distance
-
setRefDistance
public void setRefDistance(double refDistance) Sets the distance at which attenuation starts.
Parameters
refDistance: 0 or more
-
getMaxDistance
public double getMaxDistance()The distance past which the linear model attenuates no further, 10000 by default.
Returns
the distance
-
setMaxDistance
public void setMaxDistance(double maxDistance) Sets the distance past which the linear model attenuates no further.
Parameters
maxDistance: more than 0
-
getRolloffFactor
public double getRolloffFactor()How fast the volume falls with distance, 1 by default.
Returns
the factor
-
setRolloffFactor
public void setRolloffFactor(double rolloffFactor) Sets how fast the volume falls with distance.
Parameters
rolloffFactor: 0 or more; the linear model clamps it to 1
-
getConeInnerAngle
public double getConeInnerAngle()The angle, in degrees, of the cone inside which there is no cone attenuation; 360 by default.
Returns
degrees
-
setConeInnerAngle
public void setConeInnerAngle(double angle) Sets the inner cone angle.
Parameters
angle: degrees
-
getConeOuterAngle
public double getConeOuterAngle()The angle, in degrees, outside which the gain is
getConeOuterGain(); 360 by default.Returns
degrees
-
setConeOuterAngle
public void setConeOuterAngle(double angle) Sets the outer cone angle.
Parameters
angle: degrees
-
getConeOuterGain
public double getConeOuterGain()The gain outside the outer cone, 0 by default.
Returns
the gain
-
setConeOuterGain
public void setConeOuterGain(double gain) Sets the gain outside the outer cone.
Parameters
gain: 0 to 1
-