5#include <unordered_map>
6#include <unordered_set>
9#include "core/event/bus.h"
10#include "core/system.h"
11#include "ecs/entity.h"
12#include "resource/asset/audio_clip_asset.h"
13#include "system/audio/audio_device.h"
14#include "system/audio/audio_events.h"
16namespace Vkm::Engine {
29class AudioSystem :
public System {
31 AudioSystem() =
default;
32 ~AudioSystem()
override =
default;
34 AudioSystem(
const AudioSystem& other) =
delete;
35 AudioSystem& operator=(
const AudioSystem& other) =
delete;
37 AudioSystem(AudioSystem && other) =
delete;
38 AudioSystem& operator=(AudioSystem && other) =
delete;
57 void setSilent(
bool silent =
true) { m_silent = silent; }
103 const glm::vec3& worldPosition,
126 void warnIfNoListener(
bool spatial);
137 void warnIfStereoSpatial(
const AudioClipAsset& asset,
bool spatial);
148 AudioClipHandle clip;
150 uint64_t seenOnFrame = 0;
155 bool m_silent =
false;
158 std::unordered_map<uint32_t, ActiveVoice> m_voices;
161 std::vector<PlaySoundEvent> m_pending;
164 std::vector<PlaySoundEvent> m_starting;
170 ListenerId m_playListener = 0;
173 uint64_t m_assetEpoch = 0;
176 uint64_t m_frame = 0;
179 bool m_hasListener =
false;
181 glm::vec3 m_listenerPosition{0.0f};
184 bool m_warnedNoListener =
false;
187 std::unordered_set<std::string> m_warnedStereoClips;
The engine's whole surface onto the audio backend.
Definition audio_device.h:80
VoiceId voiceOf(EntityId entity) const
The voice entity's AudioSource is being heard through.
void init(FrameContext &ctx) override
Called once after all systems are registered, before the first update.
void shutdown() override
Called once on engine shutdown.
AudioDevice & device()
The device, for a tool (auditioning, a transport pause), not a game.
Definition audio_system.h:50
void setSilent(bool silent=true)
Run without opening a device, for a host that plays to nobody; set before init().
Definition audio_system.h:57
void update(FrameContext &ctx) override
Execute this system for the current frame.
void stopEverything()
Stop every voice and forget them.
Typed pub/sub event dispatcher.
Definition event_bus.h:22
A sound: fully decoded interleaved PCM, plus the rate and layout it was written at.
Definition audio_clip_asset.h:58
A sound emitter: one clip, how loud, and where it is heard from.
Definition audio_source.h:17
Names one entity of one Scene, for as long as that slot holds it.
Definition entity.h:23
Per-frame state bundle passed to every system.
Definition system.h:55