Client API. The Codename One framework your app is built on: this runs on the device, not in a backend.

public final class PannerNode

  1. Object
  2. AudioNode
  3. 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.

Methods

public void setPosition(float x, float y, float z)Moves the source now.
public void setOrientation(float x, float y, float z)Points the source now; only matters with a cone narrower than 360 degrees.
public AudioParam getPositionX()Position on X, 0 by default.
public AudioParam getPositionY()Position on Y, 0 by default.
public AudioParam getPositionZ()Position on Z, 0 by default.
public AudioParam getOrientationX()X of the direction the source faces, 1 by default.
public AudioParam getOrientationY()Y of the direction the source faces, 0 by default.
public AudioParam getOrientationZ()Z of the direction the source faces, 0 by default.
public PanningModel getPanningModel()The panning model.
public void setPanningModel(PanningModel model)Sets the panning model.
public DistanceModelType getDistanceModel()The distance model.
public void setDistanceModel(DistanceModelType model)Sets the distance model.
public double getRefDistance()The distance at which attenuation starts, 1 by default.
public void setRefDistance(double refDistance)Sets the distance at which attenuation starts.
public double getMaxDistance()The distance past which the linear model attenuates no further, 10000 by default.
public void setMaxDistance(double maxDistance)Sets the distance past which the linear model attenuates no further.
public double getRolloffFactor()How fast the volume falls with distance, 1 by default.
public void setRolloffFactor(double rolloffFactor)Sets how fast the volume falls with distance.
public double getConeInnerAngle()The angle, in degrees, of the cone inside which there is no cone attenuation; 360 by default.
public void setConeInnerAngle(double angle)Sets the inner cone angle.
public double getConeOuterAngle()The angle, in degrees, outside which the gain is getConeOuterGain(); 360 by default.
public void setConeOuterAngle(double angle)Sets the outer cone angle.
public double getConeOuterGain()The gain outside the outer cone, 0 by default.
public void setConeOuterGain(double gain)Sets the gain outside the outer cone.

Inherited methods

Method details

setPosition

public void setPosition(float x, float y, float z)
Moves the source now.

Parameters

x float
position on X
y float
position on Y
z float
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 float
direction X
y float
direction Y
z float
direction Z

getPositionX

public AudioParam getPositionX()
Position on X, 0 by default.

Returns

the parameter

getPositionY

public AudioParam getPositionY()
Position on Y, 0 by default.

Returns

the parameter

getPositionZ

public AudioParam getPositionZ()
Position on Z, 0 by default.

Returns

the parameter

getOrientationX

public AudioParam getOrientationX()
X of the direction the source faces, 1 by default.

Returns

the parameter

getOrientationY

public AudioParam getOrientationY()
Y of the direction the source faces, 0 by default.

Returns

the parameter

getOrientationZ

public AudioParam getOrientationZ()
Z of the direction the source faces, 0 by default.

Returns

the parameter

getPanningModel

public PanningModel getPanningModel()
The panning model.

Returns

the model

setPanningModel

public void setPanningModel(PanningModel model)
Sets the panning model.

Parameters

model PanningModel
the model

getDistanceModel

public DistanceModelType getDistanceModel()
The distance model.

Returns

the model

setDistanceModel

public void setDistanceModel(DistanceModelType model)
Sets the distance model.

Parameters

model DistanceModelType
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 double
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 double
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 double
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 double
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 double
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 double
0 to 1