3#include "AudioConfig.h"
4#include "Engine/Asset/AssetHandles.h"
5#include "Engine/Audio/AudioFlow.h"
11#include <unordered_map>
15#include <glm/gtc/quaternion.hpp>
149 float volume = 1.0f,
bool loop =
false);
163 void setListener(
const glm::vec3& worldPosition,
const glm::quat& worldOrientation);
204 bool init( std::optional<uint32_t> deviceIndex );
218 Assets::Audio * asset,
const std::string & assetPath,
float volume,
bool loop,
219 const std::optional<glm::vec3> & worldPosition,
AudioHandle handle
Registry for audio flows keyed by (glTF path, flow name).
Holds decoded PCM audio data as an engine asset.
Registry store for authored audio clip handles.
std::unordered_map< AudioHandle, PlayingSound > playingSounds_
bool isPlaying(AudioHandle handle) const
Check if a sound is currently playing.
void setFlowParam(AudioHandle handle, Assets::FlowSettingHandle setting, float value)
Change a reactive flow setting on a playing flow instance.
std::string playbackDeviceName_
AudioHandle play(Assets::AudioClipHandle clip, float volume=1.0f, bool loop=false)
Play a loaded audio clip by its stable asset handle.
void drainPendingForPath(const std::filesystem::path &path, Assets::Audio *asset)
Starts pending (deferred) playback requests whose clip payload just landed.
float getMasterVolume() const
void updateSpatializedSource(AudioHandle handle, const glm::vec3 &worldPosition)
Move a playing spatialized source to a new world position.
void onAudioLoaded(Assets::Audio *asset, const std::filesystem::path &path)
Called by AudioAssetPipeline when an asset finishes loading. Starts any deferred playback requests th...
void setFlowStore(Assets::AudioFlowStore *store)
Set the flow registry used to resolve flow playback.
void stopAll()
Stop all currently playing sounds.
AudioHandle playFlow(Assets::AudioFlowHandle flow, float volume=1.0f, bool loop=false)
Play an audio flow (reactive node graph) non-spatialized.
AudioEngine(const AudioClipStore *audioClips=nullptr)
Construct an uninitialized audio engine.
~AudioEngine()
Shut down the audio engine on destruction.
AudioHandle playSpatialized(Assets::AudioClipHandle clip, const glm::vec3 &worldPosition, float volume=1.0f, bool loop=false)
Play an audio clip spatialized at a world position by stable handle.
void setListener(const glm::vec3 &worldPosition, const glm::quat &worldOrientation)
Update the HRTF listener pose from the headset.
bool setPlaybackDevice(std::optional< uint32_t > deviceIndex)
Rebuilds the audio backend using a playback device from getPlaybackDevices().
std::unique_ptr< SteamAudioBackend > steamAudio_
void cleanupFinishedSounds()
void cleanup()
Shut down the audio engine and free all resources.
std::unordered_map< AudioHandle, SpatializedSound > spatializedSounds_
void setMasterVolume(float volume)
Set the master volume.
AudioEngine(const AudioEngine &)=delete
AudioEngine owns native audio resources and cannot be copied.
AudioHandle startPlayback(Assets::Audio *asset, const std::string &assetPath, float volume, bool loop, const std::optional< glm::vec3 > &worldPosition, AudioHandle handle)
Starts playback of a decoded audio payload.
void renderSpatialized(float *pFramesOut, std::uint64_t frameCount)
Accumulate the Steam Audio binaural mix into the engine output. Called from the audio thread via the ...
bool init()
Initialize the miniaudio engine with AudioConfig settings.
ma_sound * silenceSound_
Silent looping sound that keeps the engine node graph producing frames, so the onProcess hook fires e...
bool init(std::optional< uint32_t > deviceIndex)
void purgeStalePending()
Drops deferred playback requests whose clip failed to load or expired.
AudioEngine & operator=(const AudioEngine &)=delete
AudioEngine owns native audio resources and cannot be copy-assigned.
const std::string & getPlaybackDeviceName() const
Returns the active playback device name, or an empty string when audio is disabled.
bool isInitialized() const
Check if the audio engine initialized successfully.
void stop(AudioHandle handle)
Stop a playing sound.
std::unordered_map< AudioHandle, PendingPlay > pendingPlays_
Assets::AudioFlowStore * flowStore_
std::unordered_map< AudioHandle, PlayingFlow > playingFlows_
std::vector< AudioDeviceInfo > getPlaybackDevices() const
Enumerates playback devices currently reported by miniaudio.
const AudioClipStore * audioClips_
Binaural HRTF spatialization backend built on Steam Audio.
AssetHandle< AudioClipHandleTag > AudioClipHandle
Handle to audio clip asset data.
constexpr AudioHandle INVALID_AUDIO_HANDLE
Invalid or failed playback handle.
uint32_t AudioHandle
Identifies a playing sound instance.
Stable identity of an audio flow: the glTF asset path plus the flow name (unique within the asset)....
Stable handle to a named, runtime-controllable setting of a flow.
Deferred playback request awaiting its clip's async payload.
Assets::AudioClipHandle clip
Clip handle whose payload this request waits on.
float volume
Volume multiplier requested at play time.
std::string assetPath
Source path of the clip (matches the pipeline's load path).
bool loop
Whether the sound should loop.
std::optional< glm::vec3 > worldPosition
World position for spatialized playback, or nullopt for non-spatialized.
Active flow graph playback instance.
ma_sound * sound
miniaudio sound wrapping the flow data source.
void * dataSource
Opaque FlowDataSource (AudioFlowGraph + ma_data_source_base).
Active miniaudio sound instance owned by the audio engine.
ma_sound * sound
Runtime miniaudio sound handle.
std::string assetPath
Asset path used to start this sound.
Active spatialized sound referencing a Steam Audio backend source.
std::uint32_t source
Backend source registered with SteamAudioBackend.
std::string assetPath
Asset path used to start this sound.