Search Results for

    Show / Hide Table of Contents

    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.

    Inheritance
    Object
    ScriptingObject
    SceneObject
    Actor
    AudioSource
    Inherited Members
    Actor::_box
    Actor::_drawCategory
    Actor::_drawNoCulling
    ScriptingObject::_gcHandle
    ScriptingObject::_id
    Actor::_isActive
    Actor::_isActiveInHierarchy
    Actor::_isEnabled
    Actor::_isHierarchyDirty
    Actor::_isPrefabRoot
    Actor::_layer
    Actor::_localTransform
    Actor::_name
    SceneObject::_parent
    Actor::_physicsScene
    SceneObject::_prefabID
    SceneObject::_prefabObjectID
    Actor::_scene
    Actor::_sphere
    Actor::_staticFlags
    Actor::_transform
    ScriptingObject::_type
    Actor::AddMovement(const Vector3& translation)
    Actor::AddMovement(const Vector3& translation, const Quaternion& rotation)
    Actor::AddScript()
    Actor::AddStaticFlags(StaticFlags flags)
    Actor::AddTag(const Tag& tag)
    Actor::AddTagRecursive(const Tag& tag)
    AudioSource
    Actor::BreakPrefabLink()
    ScriptingObject::CanCast(const ScriptingTypeHandle& from, const ScriptingTypeHandle& to)
    ScriptingObject::CanCast(const MClass* from, const MClass* to)
    ScriptingObject::Cast(ScriptingObject* obj)
    ScriptingObject::ChangeID(const Guid& newId)
    Actor::ChangeScriptOrder(Script* script, int32 newIndex)
    Actor::Children
    Actor::Clone()
    ScriptingObject::CreateManaged()
    ScriptingObject::CreateManagedInternal()
    ScriptingObject::Deleted
    Object::DeleteObject(float timeToLive = 0.0f, bool useGameTime=false)
    Object::DeleteObjectNow()
    Actor::DEPRECATED("Use HasTag instead") const String& GetTag()
    Actor::DEPRECATED("Use AddTag instead") void SetTag(const StringView& value)
    ISerializable::DeserializeIfExists(DeserializeStream& stream, const char* memberName, ISerializeModifier* modifier)
    AudioSource
    Actor::DestroyChildren(float timeLeft = 0.0f)
    ScriptingObject::DestroyManaged()
    Actor::Draw(RenderContext& renderContext)
    Actor::Draw(RenderContextBatch& renderContextBatch)
    Actor::EndPlay()
    Actor::FindActor(const StringView& name)
    Actor::FindActor(const MClass* type, bool activeOnly=false)
    Actor::FindActor(const MClass* type, const StringView& name)
    Actor::FindActor(const MClass* type, const Tag& tag, bool activeOnly=false)
    Actor::FindActor()
    Actor::FindActor(const Tag& tag)
    Actor::FindScript(const MClass* type)
    Actor::FindScript()
    Object::Flags
    Actor::FromBytes(const Span<byte>& data, Array<Actor* >& output, ISerializeModifier* modifier)
    Actor::FromBytes(const Span<byte>& data)
    Actor::FromBytes(const Span<byte>& data, const Dictionary<Guid, Guid, HeapAllocation>& idsMapping)
    ScriptingObject::FromInterface(void* interfaceObj, const ScriptingTypeHandle& interfaceType)
    ScriptingObject::FromInterface(T* interfaceObj)
    Actor::FromJson(const StringAnsiView& json)
    Actor::GetBox()
    Actor::GetBoxWithChildren()
    Actor::GetChild(int32 index)
    Actor::GetChild(const StringView& name)
    Actor::GetChild(const MClass* type)
    Actor::GetChild()
    Actor::GetChildren(const MClass* type)
    Actor::GetChildren()
    Actor::GetChildrenCount()
    ScriptingObject::GetClass()
    Actor::GetDirection()
    Actor::GetEditorBoxChildren()
    ScriptingObject::GetID()
    Actor::GetIsActive()
    Actor::GetLayer()
    Actor::GetLayerMask()
    Actor::GetLayerName()
    Actor::GetLocalOrientation()
    Actor::GetLocalPosition()
    Actor::GetLocalScale()
    Actor::GetLocalToWorldMatrix(Matrix& localToWorld)
    Actor::GetLocalToWorldMatrix(Double4x4& localToWorld)
    Actor::GetLocalTransform()
    ScriptingObject::GetManagedInstance()
    Actor::GetName()
    SceneObject::GetNamePath(Char separatorChar='/')
    Actor::GetOrAddChild()
    ScriptingObject::GetOrCreateManagedInstance()
    Actor::GetOrderInParent()
    Actor::GetOrientation()
    SceneObject::GetParent()
    Actor::GetPerInstanceRandom()
    Actor::GetPhysicsScene()
    Actor::GetPosition()
    SceneObject::GetPrefabID()
    SceneObject::GetPrefabObjectID()
    Actor::GetPrefabRoot()
    Actor::GetRotation()
    Actor::GetScale()
    Actor::GetScene()
    Actor::GetSceneObjectId()
    Actor::GetSceneRendering()
    Actor::GetScript(int32 index)
    Actor::GetScript(const MClass* type)
    Actor::GetScript()
    Actor::GetScriptByID(const Guid& id)
    Actor::GetScripts(const MClass* type)
    Actor::GetScripts()
    Actor::GetScriptsCount()
    Actor::GetSphere()
    Actor::GetStaticFlags()
    Actor::GetTransform()
    ScriptingObject::GetType()
    ScriptingObject::GetTypeHandle()
    Actor::GetWorldToLocalMatrix(Matrix& worldToLocal)
    Actor::GetWorldToLocalMatrix(Double4x4& worldToLocal)
    Actor::HasActorInChildren(Actor* a)
    Actor::HasActorInHierarchy(Actor* a)
    ScriptingObject::HasManagedInstance()
    SceneObject::HasParent()
    SceneObject::HasPrefabLink()
    Actor::HasScene()
    Actor::HasStaticFlag(StaticFlags flag)
    Actor::HasTag()
    Actor::HasTag(const Tag& tag)
    Actor::HasTag(const StringView& tag)
    Actor::HideFlags
    Actor::Initialize()
    Actor::InitializeHierarchy()
    Actor::Intersects(const Ray& ray, Real& distance, Vector3& normal)
    ScriptingObject::Is(const ScriptingTypeHandle& type)
    ScriptingObject::Is(const MClass* type)
    ScriptingObject::Is()
    Actor::IsActiveInHierarchy()
    SceneObject::IsDuringPlay()
    Actor::IsPrefabRoot()
    ScriptingObject::IsRegistered()
    Actor::IsStatic()
    Actor::IsTransformStatic()
    Actor::LinkPrefab(const Guid& prefabId, const Guid& prefabObjectId)
    Actor::LookAt(const Vector3& worldPos)
    Actor::LookAt(const Vector3& worldPos, const Vector3& worldUp)
    Actor::LookingAt(const Vector3& worldPos)
    Actor::LookingAt(const Vector3& worldPos, const Vector3& worldUp)
    ScriptingObject::NewObject(const ScriptingTypeHandle& typeHandle)
    ScriptingObject::NewObject()
    Actor::OnActiveChanged()
    Actor::OnActiveInTreeChanged()
    Actor::OnBeginPlay()
    Actor::OnDebugDraw()
    Actor::OnDeleteObject()
    Actor::OnEndPlay()
    Actor::OnLayerChanged()
    ScriptingObject::OnManagedInstanceDeleted()
    Actor::OnOrderInParentChanged()
    Actor::OnParentChanged()
    Actor::OnPhysicsSceneChanged(PhysicsScene* previous)
    ScriptingObject::OnScriptingDispose()
    Actor::OnStaticFlagsChanged()
    ScriptingObject::RegisterObject()
    Actor::RemoveStaticFlags(StaticFlags flags)
    Actor::RemoveTag(const Tag& tag)
    Actor::ResetLocalTransform()
    SceneObject::SceneObject(const SpawnParams& params)
    ScriptingObject::ScriptingObject(const SpawnParams& params)
    Actor::Scripts
    AudioSource
    AudioSource
    Actor::SetDirection(const Float3& value)
    Actor::SetIsActive(bool value)
    Actor::SetLayer(int32 layerIndex)
    Actor::SetLayerName(const StringView& value)
    Actor::SetLayerNameRecursive(const StringView& value)
    Actor::SetLayerRecursive(int32 layerIndex)
    Actor::SetLocalOrientation(const Quaternion& value)
    Actor::SetLocalPosition(const Vector3& value)
    Actor::SetLocalScale(const Float3& value)
    Actor::SetLocalTransform(const Transform& value)
    ScriptingObject::SetManagedInstance(MObject* instance)
    Actor::SetName(String&& value)
    Actor::SetName(const StringView& value)
    Actor::SetOrderInParent(int32 index)
    Actor::SetOrientation(const Quaternion& value)
    Actor::SetParent(Actor* value, bool worldPositionsStays, bool canBreakPrefabLink)
    Actor::SetParent(Actor* value, bool canBreakPrefabLink=true)
    SceneObject::SetParent(Actor* value)
    Actor::SetPhysicsScene(PhysicsScene* scene)
    Actor::SetPosition(const Vector3& value)
    Actor::SetRotation(const Matrix& value)
    Actor::SetScale(const Float3& value)
    Actor::SetStaticFlag(StaticFlags flag, bool value)
    Actor::SetStaticFlags(StaticFlags value)
    Actor::SetTransform(const Transform& value)
    AudioSource
    AudioSource
    Actor::Tags
    Actor::ToBytes(const Array<Actor* >& actors, MemoryWriteStream& output)
    Actor::ToBytes(const Array<Actor* >& actors)
    ScriptingObject::ToInterface(ScriptingObject* obj, const ScriptingTypeHandle& interfaceType)
    ScriptingObject::ToInterface(ScriptingObject* obj)
    Actor::ToJson()
    ScriptingObject::ToManaged(const ScriptingObject* obj)
    ScriptingObject::ToNative(MObject* obj)
    Actor::ToString()
    Actor::TreeExecute(Function<bool(Actor* , Params ...)>& action, Params ... args)
    Actor::TreeExecuteChildren(Function<bool(Actor* , Params ...)>& action, Params ... args)
    Actor::TryGetSerializedObjectsIds(const Span<byte>& data)
    ScriptingObject::UnregisterObject()
    Actor::UnregisterObjectHierarchy()
    ISerializable::~ISerializable()
    Object::~Object()
    SceneObject::~SceneObject()
    ScriptingObject::~ScriptingObject()
    Assembly: FlaxEngine.dll
    File: Engine/Audio/AudioSource.h
    Syntax
    public class AudioSource : public Actor

    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>

    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
    SceneObject::BeginPlay(SceneBeginData* data)

    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
    ISerializable::Deserialize(DeserializeStream& stream, ISerializeModifier* modifier)

    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
    Actor::GetEditorBox()

    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
    Actor::HasContentLoaded()

    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
    Actor::IntersectsItself(const Ray& ray, Real& distance, Vector3& normal)

    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
    Actor::OnDebugDrawSelected()

    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
    Actor::OnDisable()

    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
    Actor::OnEnable()

    OnTransformChanged()

    Called when actor transform gets changed.

    Declaration
    protected virtual void OnTransformChanged() override
    Overrides
    Actor::OnTransformChanged()

    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
    ISerializable::Serialize(SerializeStream& stream, const void* otherObj)

    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

    • Improve this Doc
    • View Source
    In This Article
    Back to top Copyright © 2012-2024 Wojciech Figat