Class AudioSource
Represents a source for emitting audio. Audio can be played spatially (gun shot), or normally (music). Each audio source must have an AudioClip to play - back, and it can also have a position in the case of spatial (3D) audio.
Whether or not an audio source is spatial is controlled by the assigned AudioClip.The volume and the pitch of a spatial audio source is controlled by its position and the AudioListener's position/direction/velocity.
Inherited Members
Assembly: FlaxEngine.dll
File: Engine/Audio/AudioSource.h
Syntax
public class AudioSource : public Actor, public IAssetReference
Constructors
DEPRECATED("Use IsActuallyPlaying instead.") bool IsActuallyPlayingSth()
Determines whether this audio source started playing audio via audio backend. After audio play it may wait for audio clip data to be loaded or streamed. [Deprecated in v1.9]
Declaration
public DEPRECATED("Use IsActuallyPlaying instead.") bool IsActuallyPlayingSth() const
Parameters
|
"Use IsActuallyPlaying instead."
AudioSource_DEPRECATED__Use_IsActuallyPlaying_instead___
|
Fields
Clip
The audio clip asset used as a source of the sound.
Declaration
public AssetReference<AudioClip> Clip
Field Value
|
AssetReference<AudioClip>
|
ClipFinished
Event fired when the audio clip finishes.
Declaration
public Action ClipFinished
Field Value
|
Action
|
ClipStarted
Event fired when the audio clip starts.
Declaration
public Action ClipStarted
Field Value
|
Action
|
SourceID
The internal ID of this audio source used by the audio backend. Empty if 0.
Declaration
public uint32 SourceID = 0
Field Value
|
uint32
|
Methods
BeginPlay(SceneBeginData* data)
Called when adding object to the game.
Declaration
protected virtual void BeginPlay(SceneBeginData* data) override
Parameters
|
SceneBeginData
data
The initialization data (e.g. used to collect joints to link after begin). |
Overrides
Deserialize(DeserializeStream& stream, ISerializeModifier* modifier)
Deserializes object from the input stream.
Declaration
public virtual void Deserialize(DeserializeStream& stream, ISerializeModifier* modifier) override
Parameters
|
DeserializeStream
stream
The input stream. |
|
ISerializeModifier
modifier
The deserialization modifier object. Always valid. |
Overrides
GetAllowSpatialization()
If checked, source can play spatial 3d audio (when audio clip supports it), otherwise will always play as 2d sound.
Declaration
public bool GetAllowSpatialization() const
Returns
|
bool
|
GetAttenuation()
Gets the attenuation that controls how quickly does audio volume drop off as the listener moves further from the source.
Declaration
public float GetAttenuation() const
Returns
|
float
|
GetDopplerFactor()
Gets the doppler effect factor. Scale for source velocity. Default is 1.
Declaration
public float GetDopplerFactor() const
Returns
|
float
|
GetEditorBox()
Gets actor bounding box (single actor, no children included) for editor tools.
Declaration
public virtual BoundingBox GetEditorBox() const override
Returns
|
BoundingBox
|
Overrides
GetIsLooping()
Determines whether the audio clip should loop when it finishes playing.
Declaration
public bool GetIsLooping() const
Returns
|
bool
|
GetMinDistance()
Gets the minimum distance at which audio attenuation starts. When the listener is closer to the source than this value, audio is heard at full volume. Once farther away the audio starts attenuating.
Declaration
public float GetMinDistance() const
Returns
|
float
|
GetPan()
Gets the stereo pan of the played audio (-1 is left speaker, 1 is right speaker, 0 is balanced). The default is 1. Used by non-spatial audio only.
Declaration
public float GetPan() const
Returns
|
float
|
GetPitch()
Gets the pitch of the played audio. The default is 1.
Declaration
public float GetPitch() const
Returns
|
float
|
GetPlayOnStart()
Determines whether the audio clip should autoplay on level start.
Declaration
public bool GetPlayOnStart() const
Returns
|
bool
|
GetStartTime()
Determines the time (in seconds) at which the audio clip starts playing if Play On Start is enabled.
Declaration
public float GetStartTime() const
Returns
|
float
|
GetState()
Gets the current state of the audio playback (playing/paused/stopped).
Declaration
public AudioSource::States GetState() const
Returns
|
AudioSource::States
|
GetTime()
Gets the current time of playback. If playback has not yet started, it specifies the time at which playback will start at. The time is in seconds, in range [0, ClipLength].
Declaration
public float GetTime() const
Returns
|
float
|
GetVelocity()
Gets the velocity of the source. Determines pitch in relation to AudioListener's position. Only relevant for spatial (3D) sources.
Declaration
public Vector3 GetVelocity() const
Returns
|
Vector3
|
GetVolume()
Gets the volume of the audio played from this source, in [0, 1] range.
Declaration
public float GetVolume() const
Returns
|
float
|
HasContentLoaded()
Returns true if actor has loaded content.
Declaration
public virtual bool HasContentLoaded() const override
Returns
|
bool
|
Overrides
IntersectsItself(const Ray& ray, Real& distance, Vector3& normal)
Determines if there is an intersection between the current object and a ray.
Declaration
public virtual bool IntersectsItself(const Ray& ray, Real& distance, Vector3& normal) override
Parameters
|
Ray
ray
The ray to test. |
|
Real
distance
When the method completes, contains the distance of the intersection (if any valid). |
|
Vector3
normal
When the method completes, contains the intersection surface normal vector (if any valid). |
Returns
|
bool
True whether the two objects intersected, otherwise false. |
Overrides
Is3D()
Returns true if the sound source is three-dimensional (volume and pitch varies based on listener distance and velocity).
Declaration
public bool Is3D() const
Returns
|
bool
|
IsActuallyPlaying()
Determines whether this audio source started playing audio via audio backend. After audio play it may wait for audio clip data to be loaded or streamed.
Declaration
public bool IsActuallyPlaying() const
Returns
|
bool
|
OnDebugDrawSelected()
Draws debug shapes for the selected actor and all child scripts.
Declaration
public virtual void OnDebugDrawSelected() override
Overrides
OnDisable()
Called when actor gets removed from game systems. Occurs on EndPlay event or when actor gets inactivated in hierarchy. Use this event to unregister object from other game system (eg. audio).
Declaration
protected virtual void OnDisable() override
Overrides
OnEnable()
Called when actor gets added to game systems. Occurs on BeginPlay event or when actor gets activated in hierarchy. Use this event to register object to other game system (eg. audio).
Declaration
protected virtual void OnEnable() override
Overrides
OnTransformChanged()
Called when actor transform gets changed.
Declaration
protected virtual void OnTransformChanged() override
Overrides
Pause()
Pauses the audio playback.
Declaration
public void Pause()
Play()
Starts playing the currently assigned audio clip.
Declaration
public void Play()
RequestStreamingBuffersUpdate()
Requests the audio streaming buffers update. Rises tha flag to synchronize audio backend buffers of the emitter during next game logic update.
Declaration
public void RequestStreamingBuffersUpdate()
Serialize(SerializeStream& stream, const void* otherObj)
Serializes object to the output stream compared to the values of the other object instance (eg. default class object). If other object is null then serialize all properties.
Declaration
public virtual void Serialize(SerializeStream& stream, const void* otherObj) override
Parameters
|
SerializeStream
stream
The output stream. |
|
void
otherObj
The instance of the object to compare with and serialize only the modified properties. If null, then serialize all properties. |
Overrides
SetAllowSpatialization(bool value)
If checked, source can play spatial 3d audio (when audio clip supports it), otherwise will always play as 2d sound.
Declaration
public void SetAllowSpatialization(bool value)
Parameters
|
bool
value
|
SetAttenuation(float value)
Sets the attenuation that controls how quickly does audio volume drop off as the listener moves further from the source. At 0, no distance attenuation ever occurs.
Declaration
public void SetAttenuation(float value)
Parameters
|
float
value
|
SetDopplerFactor(float value)
Sets the doppler effect factor. Scale for source velocity. Default is 1.
Declaration
public void SetDopplerFactor(float value)
Parameters
|
float
value
|
SetIsLooping(bool value)
Determines whether the audio clip should loop when it finishes playing.
Declaration
public void SetIsLooping(bool value)
Parameters
|
bool
value
|
SetMinDistance(float value)
Sets the minimum distance at which audio attenuation starts. When the listener is closer to the source than this value, audio is heard at full volume. Once farther away the audio starts attenuating.
Declaration
public void SetMinDistance(float value)
Parameters
|
float
value
|
SetPan(float value)
Sets the stereo pan of the played audio (-1 is left speaker, 1 is right speaker, 0 is balanced). The default is 0. Used by non-spatial audio only.
Declaration
public void SetPan(float value)
Parameters
|
float
value
|
SetPitch(float value)
Sets the pitch of the played audio. The default is 1.
Declaration
public void SetPitch(float value)
Parameters
|
float
value
|
SetPlayOnStart(bool value)
Determines whether the audio clip should autoplay on game start.
Declaration
public void SetPlayOnStart(bool value)
Parameters
|
bool
value
|
SetStartTime(float value)
Determines the time (in seconds) at which the audio clip starts playing if Play On Start is enabled.
Declaration
public void SetStartTime(float value)
Parameters
|
float
value
|
SetTime(float time)
Sets the current time of playback. If playback has not yet started, it specifies the time at which playback will start at. The time is in seconds, in range [0, ClipLength].
Declaration
public void SetTime(float time)
Parameters
|
float
time
The time. |
SetVolume(float value)
Sets the volume of the audio played from this source, in [0, 1] range.
Declaration
public void SetVolume(float value)
Parameters
|
float
value
|
Stop()
Stops audio playback, rewinding it to the start.
Declaration
public void Stop()
UseStreaming()
Returns true if audio clip is valid, loaded and uses dynamic data streaming.
Declaration
public bool UseStreaming() const
Returns
|
bool
|