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
Nested ClassesModifier and TypeClassDescriptionstatic enumDeprecated.- use AudioSource.Status insteadNested classes/interfaces inherited from class com.jme3.scene.Spatial
Spatial.BatchHint, Spatial.CullHint, Spatial.DFSMode -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected AudioKeyprotected intprotected AudioDataprotected Vector3fprotected Filterprotected floatprotected floatprotected booleanprotected floatprotected floatprotected floatprotected booleanprotected Vector3fprotected floatprotected booleanprotected Filterstatic final intprotected AudioSource.Statusprotected floatprotected Vector3fprotected booleanprotected floatFields 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
ConstructorsConstructorDescriptionCreates a newAudioNodewithout 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 newAudioNodewith the given audio file.Creates a newAudioNodewith 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.voidcloneFields(Cloner cloner, Object original) Called internally by com.jme3.util.clone.Cloner.intDo not use.floatfloatfloatfloatgetPitch()floatfloatprotected AudioRendererfloatgetType()Get the Type of the underlying AudioData to see if it's streamed or buffered.floatbooleanbooleanbooleanbooleanbooleanvoidpause()Pause the audio that was started withplay().voidplay()Start playing the audio.voidStart playing an instance of this audio.voidread(JmeImporter im) voidsetAudioData(AudioData audioData, AudioKey audioKey) Set the audio data to use for the audio.final voidsetChannel(int channel) Do not use.voidsetDirection(Vector3f direction) Set the direction of this audio node.voidsetDirectional(boolean directional) Set the audio node to be directional.voidsetDryFilter(Filter dryFilter) Set the dry filter to use for this audio node.voidsetInnerAngle(float innerAngle) Set the directional audio node cone inner angle.voidsetLooping(boolean loop) Set the looping mode for the audio node.voidsetMaxDistance(float maxDistance) Set the maximum distance for the attenuation of the audio node.voidsetOuterAngle(float outerAngle) Set the directional audio node cone outer angle.voidsetPitch(float pitch) Set the pitch of the audio, also the speed of playback.voidsetPositional(boolean positional) Set the audio node as positional.voidsetRefDistance(float refDistance) Set the reference playing distance for the audio node.voidsetReverbEnabled(boolean reverbEnabled) Set to true to enable reverberation effects for this audio node.voidsetReverbFilter(Filter reverbFilter) Set the reverb filter for this audio node.final voidsetStatus(AudioSource.Status status) Do not use.voidsetTimeOffset(float timeOffset) Set the time offset in the sound sample when to start playing.voidsetVelocity(Vector3f velocity) Set the velocity of the audio node.voidsetVelocityFromTranslation(boolean velocityFromTranslation) voidsetVolume(float volume) Set the volume of this audio node.voidstop()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)"voidupdateGeometricStateupdates the light list, computes the world transforms, and computes the world bounds for this Spatial.voidupdateLogicalState(float tpf) updateLogicalStatecalls theupdate()method for all controls attached to this Spatial.voidwrite(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, updateWorldBoundMethods 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 newAudioNodewithout any audio data set. -
AudioNode
Creates a newAudioNodewith 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 newAudioNodewith 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 newAudioNodewith 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 newAudioNodewith 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 newAudioNodewith 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 newAudioNodewith 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 sameAudioNodemultiple 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:
setChannelin interfaceAudioSource- Parameters:
channel- the desired channel index, or -1 if stopped
-
getChannel
public int getChannel()Do not use.- Specified by:
getChannelin interfaceAudioSource- Returns:
- the channel index, or -1 if stopped
-
getDryFilter
- Specified by:
getDryFilterin interfaceAudioSource- Returns:
- The {#link Filter dry filter} that is set.
- See Also:
-
setDryFilter
Set the dry filter to use for this audio node. Whenreverbis 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 theFilterto 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:
getAudioDatain interfaceAudioSource- Returns:
- The
AudioDataset previously withsetAudioData(com.jme3.audio.AudioData, com.jme3.audio.AudioKey)or any of the constructors that initialize the audio data.
-
getStatus
- Specified by:
getStatusin interfaceAudioSource- Returns:
- The
AudioNode.Statusof the audio node. The status will be changed when either theplay()orstop()methods are called.
-
setStatus
Do not use.- Specified by:
setStatusin 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.DataTypeof the audio node.
-
isLooping
public boolean isLooping()- Specified by:
isLoopingin 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:
getPitchin 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:
getVolumein 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:
getTimeOffsetin 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:
getPlaybackTimein interfaceAudioSource- Returns:
- the current playback position of the source in seconds.
-
getPosition
- Specified by:
getPositionin interfaceAudioSource- Returns:
- The position of the audio source.
-
getVelocity
- Specified by:
getVelocityin 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:
isReverbEnabledin 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:
getReverbFilterin 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:
getMaxDistancein 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:
getRefDistancein 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:
isDirectionalin 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:
getDirectionin 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:
getInnerAnglein 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:
getOuterAnglein 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:
isPositionalin 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:SpatialupdateLogicalStatecalls theupdate()method for all controls attached to this Spatial.- Overrides:
updateLogicalStatein classNode- Parameters:
tpf- Time per frame.- See Also:
-
updateGeometricState
public void updateGeometricState()Description copied from class:SpatialupdateGeometricStateupdates 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:
updateGeometricStatein classNode- See Also:
-
clone
Description copied from interface:CloneableSmartAssetCreates a clone of the asset. Please seeObject.clone()for more info on how this method should be implemented.- Specified by:
clonein interfaceCloneableSmartAsset- Overrides:
clonein 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:
cloneFieldsin interfaceJmeCloneable- Overrides:
cloneFieldsin 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:
writein interfaceSavable- Overrides:
writein classNode- Throws:
IOException
-
read
- Specified by:
readin interfaceSavable- Overrides:
readin classNode- Throws:
IOException
-
toString
Description copied from class:SpatialReturns the Spatial's name followed by the class of the spatial
Example: "MyNode (com.jme3.scene.Spatial)"
-