7#include "ncengine/asset/Assets.h"
22 static constexpr uint8_t None = 0b00000000;
23 static constexpr uint8_t Play = 0b00000001;
24 static constexpr uint8_t Loop = 0b00000010;
25 static constexpr uint8_t Spatial = 0b00000100;
32 float innerRadius = 1.0f;
33 float outerRadius = 15.0f;
34 uint8_t flags = AudioSourceFlags::None;
50 std::vector<asset::AudioClipView> clips = {},
54 void Play(uint32_t clipIndex = 0ull);
60 auto IsPlaying() const noexcept ->
bool {
return m_properties.flags & AudioSourceFlags::Play; }
101 auto GetClips() const noexcept -> const std::vector<asset::AudioClipView>& {
return m_clips; }
103 auto GetGain() const noexcept ->
float {
return m_properties.gain; }
104 auto GetInnerRadius() const noexcept ->
float {
return m_properties.innerRadius; }
105 auto GetOuterRadius() const noexcept ->
float {
return m_properties.outerRadius; }
106 auto IsSpatial() const noexcept ->
bool {
return m_properties.flags & AudioSourceFlags::Spatial; }
107 auto IsLooping() const noexcept ->
bool {
return m_properties.flags & AudioSourceFlags::Loop; }
109 void SetProperties(
const AudioSourceProperties& properties)
noexcept { m_properties = properties; }
110 void SetGain(
float gain)
noexcept { m_properties.gain = gain; }
111 void SetInnerRadius(
float radius)
noexcept { m_properties.innerRadius = radius; }
112 void SetOuterRadius(
float radius)
noexcept { m_properties.outerRadius = radius; }
114 void SetSpatial(
bool spatialize)
noexcept
116 m_properties.flags = spatialize
117 ? m_properties.flags | AudioSourceFlags::Spatial
118 : m_properties.flags & ~AudioSourceFlags::Spatial;
121 void SetLooping(
bool loop)
noexcept
123 m_properties.flags = loop
124 ? m_properties.flags | AudioSourceFlags::Loop
125 : m_properties.flags & ~AudioSourceFlags::Loop;
129 std::vector<asset::AudioClipView> m_clips;
131 uint32_t m_currentSampleIndex = 0u;
132 AudioSourceProperties m_properties;
134 void SetPlaying() noexcept { m_properties.flags |= AudioSourceFlags::Play; }
135 void SetStopped() noexcept { m_properties.flags &= ~AudioSourceFlags
::Play; }
136 void WriteSpatialSamples(
double* buffer,
size_t frames,
const Vector3& sourcePosition,
const Vector3& listenerPosition,
const Vector3& rightEar);
137 void WriteNonSpatialSamples(
double* buffer,
size_t frames);
139 friend class audio::NcAudioImpl;
constexpr auto NullClipIndex
Indicates an invalid audio clip index.
Definition: AudioSource.h:38
Component managing audio clips.
Definition: AudioSource.h:47
auto AddClip(const asset::AudioClipView &clip) -> uint32_t
Add an audio clip.
void Resume()
Continue playing from the last position.
auto GetQueuedClipIndex() const noexcept -> uint32_t
Get the index of the most recently queued or played clip.
Definition: AudioSource.h:72
void PlayNext()
Play the audio clip following the one most recently played (round-robin).
void Play(uint32_t clipIndex=0ull)
Play the audio clip at a given index.
void RemoveClip(uint32_t clipIndex)
Remove the audio clip at a given index.
auto IsPlaying() const noexcept -> bool
Check if a clip is currently playing.
Definition: AudioSource.h:60
void ResetPlayPosition()
Go back the beginning of the current playing or queued clip.
Definition: AudioSource.h:84
void SetClip(uint32_t clipIndex, const asset::AudioClipView &clip)
Replace the audio clip at a given index.
void Stop() noexcept
Stop the currently playing audio clip, preserving the current position in the clip.
Definition: AudioSource.h:75
void Queue(uint32_t clipIndex)
Preemptively set the next clip to be played. This can be started with Resume() instead of Play().
Optional base class for components.
Definition: Component.h:27
Identifies an object in the registry.
Definition: Entity.h:18
Flags applying to all clips in an AudioSource.
Definition: AudioSource.h:21
Properties applying to all clips in an AudioSource.
Definition: AudioSource.h:30
Definition: AssetViews.h:25