Class PannerNode

java.lang.Object
com.codename1.media.audio.AudioNode
com.codename1.media.audio.PannerNode

public final class PannerNode extends AudioNode

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 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

      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: the model
    • getDistanceModel

      public DistanceModelType getDistanceModel()

      The distance model.

      Returns

      the model

    • setDistanceModel

      public void setDistanceModel(DistanceModelType model)

      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