public class AudioNode extends Node implements AudioSource
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)
.Modifier and Type | Class and Description |
---|---|
static class |
AudioNode.Status
Deprecated.
- use AudioSource.Status instead
|
Spatial.BatchHint, Spatial.CullHint, Spatial.DFSMode
Modifier and Type | Field and Description |
---|---|
protected AudioKey |
audioKey |
protected int |
channel |
protected AudioData |
data |
protected Vector3f |
direction |
protected Filter |
dryFilter |
protected float |
innerAngle |
protected float |
lastTpf |
protected boolean |
loop |
protected float |
maxDistance |
protected float |
outerAngle |
protected float |
pitch |
protected boolean |
positional |
protected Vector3f |
previousWorldTranslation |
protected float |
refDistance |
protected boolean |
reverbEnabled |
protected Filter |
reverbFilter |
static int |
SAVABLE_VERSION |
protected AudioSource.Status |
status |
protected float |
timeOffset |
protected Vector3f |
velocity |
protected boolean |
velocityFromTranslation |
protected float |
volume |
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 and Description |
---|
AudioNode()
Creates a new
AudioNode without any audio data set. |
AudioNode(AssetManager assetManager,
java.lang.String name)
Deprecated.
|
AudioNode(AssetManager assetManager,
java.lang.String name,
AudioData.DataType type)
Creates a new
AudioNode with the given audio file. |
AudioNode(AssetManager assetManager,
java.lang.String name,
boolean stream)
Deprecated.
|
AudioNode(AssetManager assetManager,
java.lang.String name,
boolean stream,
boolean streamCache)
Deprecated.
|
AudioNode(AudioData audioData,
AudioKey audioKey)
Creates a new
AudioNode with the given data and key. |
AudioNode(AudioRenderer audioRenderer,
AssetManager assetManager,
java.lang.String name)
Deprecated.
AudioRenderer parameter is ignored.
|
Modifier and Type | Method and Description |
---|---|
AudioNode |
clone()
Creates a clone of the asset.
|
void |
cloneFields(Cloner cloner,
java.lang.Object original)
Called internally by com.jme3.util.clone.Cloner.
|
AudioData |
getAudioData() |
int |
getChannel()
Do not use.
|
Vector3f |
getDirection() |
Filter |
getDryFilter() |
float |
getInnerAngle() |
float |
getMaxDistance() |
float |
getOuterAngle() |
float |
getPitch() |
float |
getPlaybackTime() |
Vector3f |
getPosition() |
float |
getRefDistance() |
protected AudioRenderer |
getRenderer() |
Filter |
getReverbFilter() |
AudioSource.Status |
getStatus() |
float |
getTimeOffset() |
AudioData.DataType |
getType()
Get the Type of the underlying AudioData to see if it's streamed or buffered.
|
Vector3f |
getVelocity() |
float |
getVolume() |
boolean |
isDirectional() |
boolean |
isLooping() |
boolean |
isPositional() |
boolean |
isReverbEnabled() |
boolean |
isVelocityFromTranslation() |
void |
pause()
Pause the audio that was started with
play() . |
void |
play()
Start playing the audio.
|
void |
playInstance()
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.
|
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.
|
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 with
play() . |
java.lang.String |
toString()
Returns the Spatial's name followed by the class of the spatial
Example: "MyNode (com.jme3.scene.Spatial)" |
void |
updateGeometricState()
updateGeometricState updates the light list,
computes the world transforms, and computes the world bounds
for this Spatial. |
void |
updateLogicalState(float tpf)
updateLogicalState calls the update() method
for all controls attached to this Spatial. |
void |
write(JmeExporter ex) |
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
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
public static final int SAVABLE_VERSION
protected boolean loop
protected float volume
protected float pitch
protected float timeOffset
protected Filter dryFilter
protected AudioKey audioKey
protected transient AudioData data
protected transient volatile AudioSource.Status status
protected transient volatile int channel
protected Vector3f previousWorldTranslation
protected Vector3f velocity
protected boolean reverbEnabled
protected float maxDistance
protected float refDistance
protected Filter reverbFilter
protected Vector3f direction
protected float innerAngle
protected float outerAngle
protected boolean positional
protected boolean velocityFromTranslation
protected float lastTpf
public AudioNode()
AudioNode
without any audio data set.public AudioNode(AudioData audioData, AudioKey audioKey)
AudioNode
with the given data and key.audioData
- The audio data contains the audio track to play.audioKey
- The audio key that was used to load the AudioDatapublic AudioNode(AssetManager assetManager, java.lang.String name, AudioData.DataType type)
AudioNode
with the given audio file.assetManager
- The asset manager to use to load the audio filename
- The filename of the audio filetype
- The type. If AudioData.DataType
.Stream
,
the audio will be streamed gradually from disk,
otherwise it will be buffered (AudioData.DataType
.Buffer
)@Deprecated public AudioNode(AssetManager assetManager, java.lang.String name, boolean stream, boolean streamCache)
AudioNode(com.jme3.asset.AssetManager, java.lang.String,
com.jme3.audio.AudioData.DataType)
insteadAudioNode
with the given audio file.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.@Deprecated public AudioNode(AssetManager assetManager, java.lang.String name, boolean stream)
AudioNode(com.jme3.asset.AssetManager, java.lang.String,
com.jme3.audio.AudioData.DataType)
insteadAudioNode
with the given audio file.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.@Deprecated public AudioNode(AudioRenderer audioRenderer, AssetManager assetManager, java.lang.String name)
AudioNode
with the given audio file.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@Deprecated public AudioNode(AssetManager assetManager, java.lang.String name)
AudioNode(com.jme3.asset.AssetManager, java.lang.String,
com.jme3.audio.AudioData.DataType)
insteadAudioNode
with the given audio file.assetManager
- The asset manager to use to load the audio filename
- The filename of the audio fileprotected AudioRenderer getRenderer()
public void play()
public void playInstance()
AudioNode
multiple times. Note
that changes to the parameters of this AudioNode will not affect the
instances already playing.public void stop()
play()
.public void pause()
play()
.public final void setChannel(int channel)
setChannel
in interface AudioSource
channel
- the desired channel index, or -1 if stoppedpublic int getChannel()
getChannel
in interface AudioSource
public Filter getDryFilter()
getDryFilter
in interface AudioSource
setDryFilter(com.jme3.audio.Filter)
public void setDryFilter(Filter dryFilter)
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.dryFilter
- The filter to set, or null to disable dry filter.public void setAudioData(AudioData audioData, AudioKey audioKey)
AudioData
.audioData
- The audio data contains the audio track to play.audioKey
- The audio key that was used to load the AudioDatapublic AudioData getAudioData()
getAudioData
in interface AudioSource
AudioData
set previously with
setAudioData(com.jme3.audio.AudioData, com.jme3.audio.AudioKey)
or any of the constructors that initialize the audio data.public AudioSource.Status getStatus()
getStatus
in interface AudioSource
AudioNode.Status
of the audio node.
The status will be changed when either the play()
or stop()
methods are called.public final void setStatus(AudioSource.Status status)
setStatus
in interface AudioSource
status
- the desired statuspublic AudioData.DataType getType()
AudioData.DataType
of the audio node.public boolean isLooping()
isLooping
in interface AudioSource
setLooping(boolean)
public void setLooping(boolean loop)
loop
- True if the audio should keep looping after it is done playing.public float getPitch()
getPitch
in interface AudioSource
setPitch(float)
public void setPitch(float pitch)
pitch
- The pitch to set.java.lang.IllegalArgumentException
- If pitch is not between 0.5 and 2.0.public float getVolume()
getVolume
in interface AudioSource
setVolume(float)
public void setVolume(float volume)
volume
- The volume to set.java.lang.IllegalArgumentException
- If volume is negativepublic float getTimeOffset()
getTimeOffset
in interface AudioSource
public void setTimeOffset(float timeOffset)
timeOffset
- The time offsetjava.lang.IllegalArgumentException
- If timeOffset is negativepublic float getPlaybackTime()
getPlaybackTime
in interface AudioSource
public Vector3f getPosition()
getPosition
in interface AudioSource
public Vector3f getVelocity()
getVelocity
in interface AudioSource
setVelocity(com.jme3.math.Vector3f)
public void setVelocity(Vector3f velocity)
velocity
- The velocity to set.setPositional(boolean)
public boolean isReverbEnabled()
isReverbEnabled
in interface AudioSource
setReverbEnabled(boolean)
public void setReverbEnabled(boolean reverbEnabled)
AudioRenderer.setEnvironment(com.jme3.audio.Environment)
will apply a reverb effect to the audio playing from this audio node.reverbEnabled
- True to enable reverb.public Filter getReverbFilter()
getReverbFilter
in interface AudioSource
setReverbFilter(com.jme3.audio.Filter)
public void setReverbFilter(Filter reverbFilter)
reverbFilter
- The reverb filter to set.setDryFilter(com.jme3.audio.Filter)
public float getMaxDistance()
getMaxDistance
in interface AudioSource
setMaxDistance(float)
public void setMaxDistance(float maxDistance)
maxDistance
- The maximum playing distance.java.lang.IllegalArgumentException
- If maxDistance is negativepublic float getRefDistance()
getRefDistance
in interface AudioSource
setRefDistance(float)
public void setRefDistance(float refDistance)
refDistance
- The reference playing distance.java.lang.IllegalArgumentException
- If refDistance is negativepublic boolean isDirectional()
isDirectional
in interface AudioSource
setDirectional(boolean)
public void setDirectional(boolean directional)
setDirection(com.jme3.math.Vector3f)
to set the audio node's direction.directional
- If the audio node is directionalpublic Vector3f getDirection()
getDirection
in interface AudioSource
setDirection(com.jme3.math.Vector3f)
public void setDirection(Vector3f direction)
direction
- a direction vector (alias created)setDirectional(boolean)
public float getInnerAngle()
getInnerAngle
in interface AudioSource
setInnerAngle(float)
public void setInnerAngle(float innerAngle)
innerAngle
- The cone inner angle.public float getOuterAngle()
getOuterAngle
in interface AudioSource
setOuterAngle(float)
public void setOuterAngle(float outerAngle)
outerAngle
- The cone outer angle.public boolean isPositional()
isPositional
in interface AudioSource
setPositional(boolean)
public void setPositional(boolean positional)
positional
- True if the audio node should be positional, otherwise
false if it should be headspace.public boolean isVelocityFromTranslation()
public void setVelocityFromTranslation(boolean velocityFromTranslation)
public void updateLogicalState(float tpf)
Spatial
updateLogicalState
calls the update()
method
for all controls attached to this Spatial.updateLogicalState
in class Node
tpf
- Time per frame.Spatial.addControl(com.jme3.scene.control.Control)
public void updateGeometricState()
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.updateGeometricState
in class Node
Spatial.getWorldLightList()
,
Spatial.getWorldTransform()
,
Spatial.getWorldBound()
public AudioNode clone()
CloneableSmartAsset
Object.clone()
for more info on how this method
should be implemented.clone
in interface CloneableSmartAsset
clone
in class Spatial
Mesh.cloneForAnim()
public void cloneFields(Cloner cloner, java.lang.Object original)
cloneFields
in interface JmeCloneable
cloneFields
in class Node
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.public void write(JmeExporter ex) throws java.io.IOException
public void read(JmeImporter im) throws java.io.IOException