Class AudioNode

All Implemented Interfaces:
HasLocalTransform, CloneableSmartAsset, AudioSource, Collidable, Savable, JmeCloneable, Cloneable

public class AudioNode extends Node implements AudioSource
An AudioNode is a scene Node which can play audio assets. An AudioNode is either positional or ambient, with positional being the default. Once a positional node is attached to the scene, its location and velocity relative to the Listener affect how it sounds when played. Positional nodes can only play monaural (single-channel) assets, not stereo ones. An ambient AudioNode plays in "headspace", meaning that the node's location and velocity do not affect how it sounds when played. Ambient audio nodes can play stereo assets. The "positional" property of an AudioNode can be set via setPositional(boolean).
  • Field Details

    • SAVABLE_VERSION

      public static final int SAVABLE_VERSION
      See Also:
    • loop

      protected boolean loop
    • volume

      protected float volume
    • pitch

      protected float pitch
    • timeOffset

      protected float timeOffset
    • dryFilter

      protected Filter dryFilter
    • audioKey

      protected AudioKey audioKey
    • data

      protected transient AudioData data
    • status

      protected transient volatile AudioSource.Status status
    • channel

      protected transient volatile int channel
    • previousWorldTranslation

      protected Vector3f previousWorldTranslation
    • velocity

      protected Vector3f velocity
    • reverbEnabled

      protected boolean reverbEnabled
    • maxDistance

      protected float maxDistance
    • refDistance

      protected float refDistance
    • reverbFilter

      protected Filter reverbFilter
    • direction

      protected Vector3f direction
    • innerAngle

      protected float innerAngle
    • outerAngle

      protected float outerAngle
    • positional

      protected boolean positional
    • velocityFromTranslation

      protected boolean velocityFromTranslation
    • lastTpf

      protected float lastTpf
  • Constructor Details

    • AudioNode

      public AudioNode()
      Creates a new AudioNode without any audio data set.
    • AudioNode

      public AudioNode(AudioData audioData, AudioKey audioKey)
      Creates a new AudioNode with the given data and key.
      Parameters:
      audioData - The audio data contains the audio track to play.
      audioKey - The audio key that was used to load the AudioData
    • AudioNode

      public AudioNode(AssetManager assetManager, String name, AudioData.DataType type)
      Creates a new AudioNode with the given audio file.
      Parameters:
      assetManager - The asset manager to use to load the audio file
      name - The filename of the audio file
      type - The type. If AudioData.DataType.Stream, the audio will be streamed gradually from disk, otherwise it will be buffered (AudioData.DataType.Buffer)
    • AudioNode

      @Deprecated public AudioNode(AssetManager assetManager, String name, boolean stream, boolean streamCache)
      Creates a new AudioNode with the given audio file.
      Parameters:
      assetManager - The asset manager to use to load the audio file
      name - The filename of the audio file
      stream - If true, the audio will be streamed gradually from disk, otherwise, it will be buffered.
      streamCache - If stream is also true, then this specifies if the stream cache is used. When enabled, the audio stream will be read entirely but not decoded, allowing features such as seeking, looping and determining duration.
    • AudioNode

      @Deprecated public AudioNode(AssetManager assetManager, String name, boolean stream)
      Creates a new AudioNode with the given audio file.
      Parameters:
      assetManager - The asset manager to use to load the audio file
      name - The filename of the audio file
      stream - If true, the audio will be streamed gradually from disk, otherwise, it will be buffered.
    • AudioNode

      @Deprecated public AudioNode(AudioRenderer audioRenderer, AssetManager assetManager, String name)
      Deprecated.
      AudioRenderer parameter is ignored.
      Creates a new AudioNode with the given audio file.
      Parameters:
      audioRenderer - The audio renderer to use for playing. Cannot be null.
      assetManager - The asset manager to use to load the audio file
      name - The filename of the audio file
    • AudioNode

      @Deprecated public AudioNode(AssetManager assetManager, String name)
      Creates a new AudioNode with the given audio file.
      Parameters:
      assetManager - The asset manager to use to load the audio file
      name - The filename of the audio file
  • Method Details

    • getRenderer

      protected AudioRenderer getRenderer()
    • play

      public void play()
      Start playing the audio.
    • playInstance

      public void playInstance()
      Start playing an instance of this audio. This method can be used to play the same AudioNode multiple times. Note that changes to the parameters of this AudioNode will not affect the instances already playing.
    • stop

      public void stop()
      Stop playing the audio that was started with play().
    • pause

      public void pause()
      Pause the audio that was started with play().
    • setChannel

      public final void setChannel(int channel)
      Do not use.
      Specified by:
      setChannel in interface AudioSource
      Parameters:
      channel - the desired channel index, or -1 if stopped
    • getChannel

      public int getChannel()
      Do not use.
      Specified by:
      getChannel in interface AudioSource
      Returns:
      the channel index, or -1 if stopped
    • getDryFilter

      public Filter getDryFilter()
      Specified by:
      getDryFilter in interface AudioSource
      Returns:
      The {#link Filter dry filter} that is set.
      See Also:
    • setDryFilter

      public void setDryFilter(Filter dryFilter)
      Set the dry filter to use for this audio node. When reverb is used, the dry filter will only influence the "dry" portion of the audio, e.g. not the reverberated parts of the AudioNode playing. See the relevant documentation for the Filter to determine the effect.
      Parameters:
      dryFilter - The filter to set, or null to disable dry filter.
    • setAudioData

      public void setAudioData(AudioData audioData, AudioKey audioKey)
      Set the audio data to use for the audio. Note that this method can only be called once, if for example the audio node was initialized without an AudioData.
      Parameters:
      audioData - The audio data contains the audio track to play.
      audioKey - The audio key that was used to load the AudioData
    • getAudioData

      public AudioData getAudioData()
      Specified by:
      getAudioData in interface AudioSource
      Returns:
      The AudioData set previously with setAudioData(com.jme3.audio.AudioData, com.jme3.audio.AudioKey) or any of the constructors that initialize the audio data.
    • getStatus

      public AudioSource.Status getStatus()
      Specified by:
      getStatus in interface AudioSource
      Returns:
      The AudioNode.Status of the audio node. The status will be changed when either the play() or stop() methods are called.
    • setStatus

      public final void setStatus(AudioSource.Status status)
      Do not use.
      Specified by:
      setStatus in interface AudioSource
      Parameters:
      status - the desired status
    • getType

      public AudioData.DataType getType()
      Get the Type of the underlying AudioData to see if it's streamed or buffered. This is a shortcut to getAudioData().getType() Warning: Can return null!
      Returns:
      The AudioData.DataType of the audio node.
    • isLooping

      public boolean isLooping()
      Specified by:
      isLooping in interface AudioSource
      Returns:
      True if the audio will keep looping after it is done playing, otherwise, false.
      See Also:
    • setLooping

      public void setLooping(boolean loop)
      Set the looping mode for the audio node. The default is false.
      Parameters:
      loop - True if the audio should keep looping after it is done playing.
    • getPitch

      public float getPitch()
      Specified by:
      getPitch in interface AudioSource
      Returns:
      The pitch of the audio, also the speed of playback.
      See Also:
    • setPitch

      public void setPitch(float pitch)
      Set the pitch of the audio, also the speed of playback. The value must be between 0.5 and 2.0.
      Parameters:
      pitch - The pitch to set.
      Throws:
      IllegalArgumentException - If pitch is not between 0.5 and 2.0.
    • getVolume

      public float getVolume()
      Specified by:
      getVolume in interface AudioSource
      Returns:
      The volume of this audio node.
      See Also:
    • setVolume

      public void setVolume(float volume)
      Set the volume of this audio node. The volume is specified as gain. 1.0 is the default.
      Parameters:
      volume - The volume to set.
      Throws:
      IllegalArgumentException - If volume is negative
    • getTimeOffset

      public float getTimeOffset()
      Specified by:
      getTimeOffset in interface AudioSource
      Returns:
      the time offset in the sound sample when to start playing.
    • setTimeOffset

      public void setTimeOffset(float timeOffset)
      Set the time offset in the sound sample when to start playing.
      Parameters:
      timeOffset - The time offset
      Throws:
      IllegalArgumentException - If timeOffset is negative
    • getPlaybackTime

      public float getPlaybackTime()
      Specified by:
      getPlaybackTime in interface AudioSource
      Returns:
      the current playback position of the source in seconds.
    • getPosition

      public Vector3f getPosition()
      Specified by:
      getPosition in interface AudioSource
      Returns:
      The position of the audio source.
    • getVelocity

      public Vector3f getVelocity()
      Specified by:
      getVelocity in interface AudioSource
      Returns:
      The velocity of the audio node.
      See Also:
    • setVelocity

      public void setVelocity(Vector3f velocity)
      Set the velocity of the audio node. The velocity is expected to be in meters. Does nothing if the audio node is not positional.
      Parameters:
      velocity - The velocity to set.
      See Also:
    • isReverbEnabled

      public boolean isReverbEnabled()
      Specified by:
      isReverbEnabled in interface AudioSource
      Returns:
      True if reverb is enabled, otherwise false.
      See Also:
    • setReverbEnabled

      public void setReverbEnabled(boolean reverbEnabled)
      Set to true to enable reverberation effects for this audio node. Does nothing if the audio node is not positional.
      When enabled, the audio environment set with AudioRenderer.setEnvironment(com.jme3.audio.Environment) will apply a reverb effect to the audio playing from this audio node.
      Parameters:
      reverbEnabled - True to enable reverb.
    • getReverbFilter

      public Filter getReverbFilter()
      Specified by:
      getReverbFilter in interface AudioSource
      Returns:
      Filter for the reverberations of this audio node.
      See Also:
    • setReverbFilter

      public void setReverbFilter(Filter reverbFilter)
      Set the reverb filter for this audio node.
      The reverb filter will influence the reverberations of the audio node playing. This only has an effect if reverb is enabled.
      Parameters:
      reverbFilter - The reverb filter to set.
      See Also:
    • getMaxDistance

      public float getMaxDistance()
      Specified by:
      getMaxDistance in interface AudioSource
      Returns:
      Maximum distance for this audio node.
      See Also:
    • setMaxDistance

      public void setMaxDistance(float maxDistance)
      Set the maximum distance for the attenuation of the audio node. Does nothing if the audio node is not positional.
      The maximum distance is the distance beyond which the audio node will no longer be attenuated. Normal attenuation is logarithmic from refDistance (it reduces by half when the distance doubles). Max distance sets where this fall-off stops and the sound will never get any quieter than at that distance. If you want a sound to fall-off very quickly then set ref distance very short and leave this distance very long.
      Parameters:
      maxDistance - The maximum playing distance.
      Throws:
      IllegalArgumentException - If maxDistance is negative
    • getRefDistance

      public float getRefDistance()
      Specified by:
      getRefDistance in interface AudioSource
      Returns:
      The reference playing distance for the audio node.
      See Also:
    • setRefDistance

      public void setRefDistance(float refDistance)
      Set the reference playing distance for the audio node. Does nothing if the audio node is not positional.
      The reference playing distance is the distance at which the audio node will be exactly half of its volume.
      Parameters:
      refDistance - The reference playing distance.
      Throws:
      IllegalArgumentException - If refDistance is negative
    • isDirectional

      public boolean isDirectional()
      Specified by:
      isDirectional in interface AudioSource
      Returns:
      True if the audio node is directional
      See Also:
    • setDirectional

      public void setDirectional(boolean directional)
      Set the audio node to be directional. Does nothing if the audio node is not positional.
      After setting directional, you should call setDirection(com.jme3.math.Vector3f) to set the audio node's direction.
      Parameters:
      directional - If the audio node is directional
    • getDirection

      public Vector3f getDirection()
      Specified by:
      getDirection in interface AudioSource
      Returns:
      The direction of this audio node.
      See Also:
    • setDirection

      public void setDirection(Vector3f direction)
      Set the direction of this audio node. Does nothing if the audio node is not directional.
      Parameters:
      direction - a direction vector (alias created)
      See Also:
    • getInnerAngle

      public float getInnerAngle()
      Specified by:
      getInnerAngle in interface AudioSource
      Returns:
      The directional audio node, cone inner angle.
      See Also:
    • setInnerAngle

      public void setInnerAngle(float innerAngle)
      Set the directional audio node cone inner angle. Does nothing if the audio node is not directional.
      Parameters:
      innerAngle - The cone inner angle.
    • getOuterAngle

      public float getOuterAngle()
      Specified by:
      getOuterAngle in interface AudioSource
      Returns:
      The directional audio node, cone outer angle.
      See Also:
    • setOuterAngle

      public void setOuterAngle(float outerAngle)
      Set the directional audio node cone outer angle. Does nothing if the audio node is not directional.
      Parameters:
      outerAngle - The cone outer angle.
    • isPositional

      public boolean isPositional()
      Specified by:
      isPositional in interface AudioSource
      Returns:
      True if the audio node is positional.
      See Also:
    • setPositional

      public void setPositional(boolean positional)
      Set the audio node as positional. The position, velocity, and distance parameters affect positional audio nodes. Set to false if the audio node should play in "headspace".
      Parameters:
      positional - True if the audio node should be positional, otherwise false if it should be headspace.
    • isVelocityFromTranslation

      public boolean isVelocityFromTranslation()
    • setVelocityFromTranslation

      public void setVelocityFromTranslation(boolean velocityFromTranslation)
    • updateLogicalState

      public void updateLogicalState(float tpf)
      Description copied from class: Spatial
      updateLogicalState calls the update() method for all controls attached to this Spatial.
      Overrides:
      updateLogicalState in class Node
      Parameters:
      tpf - Time per frame.
      See Also:
    • updateGeometricState

      public void updateGeometricState()
      Description copied from class: Spatial
      updateGeometricState updates the light list, computes the world transforms, and computes the world bounds for this Spatial. Calling this when the Spatial is attached to a node will cause undefined results. User code should only call this method on Spatials having no parent.
      Overrides:
      updateGeometricState in class Node
      See Also:
    • clone

      public AudioNode clone()
      Description copied from interface: CloneableSmartAsset
      Creates a clone of the asset. Please see Object.clone() for more info on how this method should be implemented.
      Specified by:
      clone in interface CloneableSmartAsset
      Overrides:
      clone in class Spatial
      Returns:
      A clone of this Spatial, the scene graph in its entirety is cloned and can be altered independently of the original scene graph. Note that meshes of geometries are not cloned explicitly, they are shared if static, or specially cloned if animated.
      See Also:
    • cloneFields

      public void cloneFields(Cloner cloner, Object original)
      Called internally by com.jme3.util.clone.Cloner. Do not call directly.
      Specified by:
      cloneFields in interface JmeCloneable
      Overrides:
      cloneFields in class Node
      Parameters:
      cloner - The cloner that is performing the cloning operation. The cloneFields method can call back into the cloner to make clones of its subordinate fields.
      original - The original object from which this object was cloned. This is provided for the very rare case that this object needs to refer to its original for some reason. In general, all of the relevant values should have been transferred during the shallow clone, and this object need only clone what it wants.
    • write

      public void write(JmeExporter ex) throws IOException
      Specified by:
      write in interface Savable
      Overrides:
      write in class Node
      Throws:
      IOException
    • read

      public void read(JmeImporter im) throws IOException
      Specified by:
      read in interface Savable
      Overrides:
      read in class Node
      Throws:
      IOException
    • toString

      public String toString()
      Description copied from class: Spatial
      Returns the Spatial's name followed by the class of the spatial
      Example: "MyNode (com.jme3.scene.Spatial)"
      Overrides:
      toString in class Spatial
      Returns:
      Spatial's name followed by the class of the Spatial