Package com.jme3.audio
Class AudioNode
java.lang.Object
com.jme3.scene.Spatial
com.jme3.scene.Node
com.jme3.audio.AudioNode
- All Implemented Interfaces:
HasLocalTransform
,CloneableSmartAsset
,AudioSource
,Collidable
,Savable
,JmeCloneable
,Cloneable
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)
.-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
Deprecated.- use AudioSource.Status insteadNested classes/interfaces inherited from class com.jme3.scene.Spatial
Spatial.BatchHint, Spatial.CullHint, Spatial.DFSMode
-
Field Summary
Modifier and TypeFieldDescriptionprotected AudioKey
protected int
protected AudioData
protected Vector3f
protected Filter
protected float
protected float
protected boolean
protected float
protected float
protected float
protected boolean
protected Vector3f
protected float
protected boolean
protected Filter
static final int
protected AudioSource.Status
protected float
protected Vector3f
protected boolean
protected float
Fields inherited from class com.jme3.scene.Spatial
batchHint, controls, cullHint, frustrumIntersects, key, localLights, localOverrides, localTransform, name, parent, queueBucket, queueDistance, refreshFlags, RF_BOUND, RF_CHILD_LIGHTLIST, RF_LIGHTLIST, RF_MATPARAM_OVERRIDE, RF_TRANSFORM, shadowMode, userData, worldBound, worldLights, worldOverrides, worldTransform
-
Constructor Summary
ConstructorDescriptionCreates a newAudioNode
without any audio data set.AudioNode
(AssetManager assetManager, String name) Deprecated.AudioNode
(AssetManager assetManager, String name, boolean stream) Deprecated.AudioNode
(AssetManager assetManager, String name, boolean stream, boolean streamCache) Deprecated.AudioNode
(AssetManager assetManager, String name, AudioData.DataType type) Creates a newAudioNode
with the given audio file.Creates a newAudioNode
with the given data and key.AudioNode
(AudioRenderer audioRenderer, AssetManager assetManager, String name) Deprecated.AudioRenderer parameter is ignored. -
Method Summary
Modifier and TypeMethodDescriptionclone()
Creates a clone of the asset.void
cloneFields
(Cloner cloner, Object original) Called internally by com.jme3.util.clone.Cloner.int
Do not use.float
float
float
float
getPitch()
float
float
protected AudioRenderer
float
getType()
Get the Type of the underlying AudioData to see if it's streamed or buffered.float
boolean
boolean
boolean
boolean
boolean
void
pause()
Pause the audio that was started withplay()
.void
play()
Start playing the audio.void
Start playing an instance of this audio.void
read
(JmeImporter im) void
setAudioData
(AudioData audioData, AudioKey audioKey) Set the audio data to use for the audio.final void
setChannel
(int channel) Do not use.void
setDirection
(Vector3f direction) Set the direction of this audio node.void
setDirectional
(boolean directional) Set the audio node to be directional.void
setDryFilter
(Filter dryFilter) Set the dry filter to use for this audio node.void
setInnerAngle
(float innerAngle) Set the directional audio node cone inner angle.void
setLooping
(boolean loop) Set the looping mode for the audio node.void
setMaxDistance
(float maxDistance) Set the maximum distance for the attenuation of the audio node.void
setOuterAngle
(float outerAngle) Set the directional audio node cone outer angle.void
setPitch
(float pitch) Set the pitch of the audio, also the speed of playback.void
setPositional
(boolean positional) Set the audio node as positional.void
setRefDistance
(float refDistance) Set the reference playing distance for the audio node.void
setReverbEnabled
(boolean reverbEnabled) Set to true to enable reverberation effects for this audio node.void
setReverbFilter
(Filter reverbFilter) Set the reverb filter for this audio node.final void
setStatus
(AudioSource.Status status) Do not use.void
setTimeOffset
(float timeOffset) Set the time offset in the sound sample when to start playing.void
setVelocity
(Vector3f velocity) Set the velocity of the audio node.void
setVelocityFromTranslation
(boolean velocityFromTranslation) void
setVolume
(float volume) Set the volume of this audio node.void
stop()
Stop playing the audio that was started withplay()
.toString()
Returns the Spatial's name followed by the class of the spatial
Example: "MyNode (com.jme3.scene.Spatial)"void
updateGeometricState
updates the light list, computes the world transforms, and computes the world bounds for this Spatial.void
updateLogicalState
(float tpf) updateLogicalState
calls theupdate()
method for all controls attached to this Spatial.void
write
(JmeExporter ex) Methods inherited from class com.jme3.scene.Node
attachChild, attachChildAt, breadthFirstTraversal, clone, collideWith, deepClone, depthFirstTraversal, descendantMatches, descendantMatches, descendantMatches, detachAllChildren, detachChild, detachChildAt, detachChildNamed, getChild, getChild, getChildIndex, getChildren, getQuantity, getTriangleCount, getVertexCount, hasChild, oldDeepClone, setLightListRefresh, setLodLevel, setMaterial, setMatParamOverrideRefresh, setModelBound, setParent, setTransformRefresh, swapChildren, updateModelBound, updateWorldBound
Methods inherited from class com.jme3.scene.Spatial
addControl, addControlAt, addLight, addMatParamOverride, breadthFirstTraversal, center, checkCulling, clearMatParamOverrides, depthFirstTraversal, forceRefresh, getBatchHint, getControl, getControl, getCullHint, getKey, getLastFrustumIntersection, getLocalBatchHint, getLocalCullHint, getLocalLightList, getLocalMatParamOverrides, getLocalQueueBucket, getLocalRotation, getLocalScale, getLocalShadowMode, getLocalToWorldMatrix, getLocalTransform, getLocalTranslation, getName, getNumControls, getParent, getQueueBucket, getShadowMode, getUserData, getUserDataKeys, getWorldBound, getWorldLightList, getWorldMatParamOverrides, getWorldRotation, getWorldScale, getWorldTransform, getWorldTranslation, hasAncestor, jmeClone, localToWorld, lookAt, matches, move, move, oldClone, removeControl, removeControl, removeFromParent, removeLight, removeMatParamOverride, rotate, rotate, rotateUpTo, runControlRender, scale, scale, setBatchHint, setBoundRefresh, setCullHint, setKey, setLastFrustumIntersection, setLocalRotation, setLocalRotation, setLocalScale, setLocalScale, setLocalScale, setLocalTransform, setLocalTranslation, setLocalTranslation, setName, setQueueBucket, setRequiresUpdates, setShadowMode, setUserData, updateMatParamOverrides, updateWorldLightList, updateWorldTransforms, worldToLocal
-
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
-
audioKey
-
data
-
status
-
channel
protected transient volatile int channel -
previousWorldTranslation
-
velocity
-
reverbEnabled
protected boolean reverbEnabled -
maxDistance
protected float maxDistance -
refDistance
protected float refDistance -
reverbFilter
-
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 newAudioNode
without any audio data set. -
AudioNode
Creates a newAudioNode
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
Creates a newAudioNode
with the given audio file.- Parameters:
assetManager
- The asset manager to use to load the audio filename
- The filename of the audio filetype
- The type. If
, the audio will be streamed gradually from disk, otherwise it will be buffered (AudioData.DataType
.Stream
)AudioData.DataType
.Buffer
-
AudioNode
@Deprecated public AudioNode(AssetManager assetManager, String name, boolean stream, boolean streamCache) Deprecated.Creates a newAudioNode
with the given audio file.- Parameters:
assetManager
- The asset manager to use to load the audio filename
- The filename of the audio filestream
- 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.Creates a newAudioNode
with the given audio file.- Parameters:
assetManager
- The asset manager to use to load the audio filename
- The filename of the audio filestream
- If true, the audio will be streamed gradually from disk, otherwise, it will be buffered.
-
AudioNode
Deprecated.AudioRenderer parameter is ignored.Creates a newAudioNode
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 filename
- The filename of the audio file
-
AudioNode
Deprecated.Creates a newAudioNode
with the given audio file.- Parameters:
assetManager
- The asset manager to use to load the audio filename
- The filename of the audio file
-
-
Method Details
-
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 sameAudioNode
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 withplay()
. -
pause
public void pause()Pause the audio that was started withplay()
. -
setChannel
public final void setChannel(int channel) Do not use.- Specified by:
setChannel
in interfaceAudioSource
- Parameters:
channel
- the desired channel index, or -1 if stopped
-
getChannel
public int getChannel()Do not use.- Specified by:
getChannel
in interfaceAudioSource
- Returns:
- the channel index, or -1 if stopped
-
getDryFilter
- Specified by:
getDryFilter
in interfaceAudioSource
- Returns:
- The {#link Filter dry filter} that is set.
- See Also:
-
setDryFilter
Set the dry filter to use for this audio node. Whenreverb
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 theFilter
to determine the effect.- Parameters:
dryFilter
- The filter to set, or null to disable dry filter.
-
setAudioData
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 anAudioData
.- Parameters:
audioData
- The audio data contains the audio track to play.audioKey
- The audio key that was used to load the AudioData
-
getAudioData
- Specified by:
getAudioData
in interfaceAudioSource
- Returns:
- The
AudioData
set previously withsetAudioData(com.jme3.audio.AudioData, com.jme3.audio.AudioKey)
or any of the constructors that initialize the audio data.
-
getStatus
- Specified by:
getStatus
in interfaceAudioSource
- Returns:
- The
AudioNode.Status
of the audio node. The status will be changed when either theplay()
orstop()
methods are called.
-
setStatus
Do not use.- Specified by:
setStatus
in interfaceAudioSource
- Parameters:
status
- the desired status
-
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 interfaceAudioSource
- 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 interfaceAudioSource
- 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 interfaceAudioSource
- 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 interfaceAudioSource
- 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 interfaceAudioSource
- Returns:
- the current playback position of the source in seconds.
-
getPosition
- Specified by:
getPosition
in interfaceAudioSource
- Returns:
- The position of the audio source.
-
getVelocity
- Specified by:
getVelocity
in interfaceAudioSource
- Returns:
- The velocity of the audio node.
- See Also:
-
setVelocity
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 interfaceAudioSource
- 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 withAudioRenderer.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
- Specified by:
getReverbFilter
in interfaceAudioSource
- Returns:
- Filter for the reverberations of this audio node.
- See Also:
-
setReverbFilter
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 interfaceAudioSource
- 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 interfaceAudioSource
- 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 interfaceAudioSource
- 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 callsetDirection(com.jme3.math.Vector3f)
to set the audio node's direction.- Parameters:
directional
- If the audio node is directional
-
getDirection
- Specified by:
getDirection
in interfaceAudioSource
- Returns:
- The direction of this audio node.
- See Also:
-
setDirection
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 interfaceAudioSource
- 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 interfaceAudioSource
- 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 interfaceAudioSource
- 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 theupdate()
method for all controls attached to this Spatial.- Overrides:
updateLogicalState
in classNode
- 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 classNode
- See Also:
-
clone
Description copied from interface:CloneableSmartAsset
Creates a clone of the asset. Please seeObject.clone()
for more info on how this method should be implemented.- Specified by:
clone
in interfaceCloneableSmartAsset
- Overrides:
clone
in classSpatial
- 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
Called internally by com.jme3.util.clone.Cloner. Do not call directly.- Specified by:
cloneFields
in interfaceJmeCloneable
- Overrides:
cloneFields
in classNode
- 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
- Specified by:
write
in interfaceSavable
- Overrides:
write
in classNode
- Throws:
IOException
-
read
- Specified by:
read
in interfaceSavable
- Overrides:
read
in classNode
- Throws:
IOException
-
toString
Description copied from class:Spatial
Returns the Spatial's name followed by the class of the spatial
Example: "MyNode (com.jme3.scene.Spatial)"
-