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.

Public

Constructors

AudioSource

AudioSource(const HSceneObject &parent)

Methods

~AudioSource

virtual ~AudioSource() noexcept = default

SetClip

void SetClip(const HAudioClip &clip)

Audio clip to play.

GetClip

HAudioClip GetClip() const

SetVolume

void SetVolume(float volume)

Volume of the audio played from this source, in [0, 1] range.

GetVolume

float GetVolume() const

SetPitch

void SetPitch(float pitch)

Determines the pitch of the played audio. 1 is the default.

GetPitch

float GetPitch() const

SetIsLooping

void SetIsLooping(bool loop)

Determines whether the audio clip should loop when it finishes playing.

GetIsLooping

bool GetIsLooping() const

SetPriority

void SetPriority(u32 priority)

Determines the priority of the audio source.

If more audio sources are playing than supported by the hardware, some might get disabled. By setting a higher priority the audio source is guaranteed to be disabled after sources with lower priority.

GetPriority

u32 GetPriority() const

SetMinDistance

void SetMinDistance(float distance)

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.

GetMinDistance

float GetMinDistance() const

SetAttenuation

void SetAttenuation(float attenuation)

Attenuation that controls how quickly does audio volume drop off as the listener moves further from the source.

GetAttenuation

float GetAttenuation() const

SetTime

void SetTime(float time)

Determines the current time of playback.

If playback hasn't yet started, it specifies the time at which playback will start at. The time is in seconds, in range [0, clipLength].

GetTime

float GetTime() const

SetPlayOnStart

void SetPlayOnStart(bool enable)

Sets whether playback should start as soon as the component is enabled.

GetPlayOnStart

bool GetPlayOnStart() const

Determines should playback start as soon as the component is enabled.

Play

void Play()

Starts playing the currently assigned audio clip.

Pause

void Pause()

Pauses the audio playback.

Stop

void Stop()

Stops audio playback, rewinding it to the start.

GetState

AudioSourceState GetState() const

Returns the current state of the audio playback (playing/paused/stopped).

staticGetRttiStatic

static RTTIType *GetRttiStatic()

GetRtti

RTTIType *GetRtti() const

Returns an interface you can use to access class' Run Time Type Information.

Protected

Constructors

AudioSource

AudioSource()

Methods

OnDestroyed

void OnDestroyed() override

Called once just before the component is destroyed.

Called regardless of the state the component is in.

OnDisabled

void OnDisabled() override

Called every time a component is placed into the Stopped state.

This includes component destruction if component wasn't already in Stopped state during destruction. When called during destruction it is called before OnDestroyed.

OnEnabled

void OnEnabled() override

Called every time a component leaves the Stopped state, if the component is enabled.

This includes component creation if requirements for leaving the Stopped state are met. When called during creation it is called after OnBeginPlay.

OnTransformChanged

void OnTransformChanged(TransformChangedFlags flags) override

Called when the component's parent scene object has changed.

Not called if the component is in Stopped state. Also only called if necessary notify flags are set via SetNotifyFlagsInternal().

Update

void Update() override

Called once per frame.

Only called if the component is in Running state.

GetListenerResources

void GetListenerResources(Vector<HResource> &resources) override

Retrieves all the resources that the class depends on.

NotifyResourceChanged

void NotifyResourceChanged(const HResource &resource) override

Called when the internal resource the resource handle is pointing to changes.

RestoreInternal

void RestoreInternal()

Creates the internal representation of the AudioSource and restores the values saved by the Component.

DestroyInternal

void DestroyInternal()

Destroys the internal AudioSource representation.

UpdateTransform

void UpdateTransform()

Updates the transform of the internal AudioSource representation from the transform of the component's scene object.

Fields

mImplementation

SPtr<IAudioSourceImplementation> mImplementation

mLastPosition

Vector3 mLastPosition

mVelocity

Vector3 mVelocity

mAudioClip

HAudioClip mAudioClip

mVolume

float mVolume

mPitch

float mPitch

mLoop

bool mLoop

mPriority

u32 mPriority

mMinDistance

float mMinDistance

mAttenuation

float mAttenuation

mPlayOnStart

bool mPlayOnStart