Vulkan Schnee 0.0.1
High-performance rendering engine
Loading...
Searching...
No Matches
AudioEngine.h
Go to the documentation of this file.
1#pragma once
2
3#include "AudioConfig.h"
4
5#include <filesystem>
6#include <unordered_map>
7#include <string>
8
9namespace Engine::Assets
10{
11 class Audio;
12} // namespace Engine::Assets
13struct ma_engine;
14struct ma_sound;
15
16namespace Engine::Core {
20 using AudioHandle = uint32_t;
22
30 public:
33
34 AudioEngine(const AudioEngine&) = delete;
36
41 bool init();
42
46 void cleanup();
47
54 void onAudioLoaded( Assets::Audio * asset, const std::filesystem::path& path);
55
63 AudioHandle play(const std::filesystem::path& path, float volume = 1.0f, bool loop = false);
64
69 void stop(AudioHandle handle);
70
74 void stopAll();
75
80 void setMasterVolume(float volume);
81
87 [[nodiscard]] bool isPlaying(AudioHandle handle) const;
88
92 [[nodiscard]] bool isInitialized() const { return initialized_; }
93
94 private:
95 ma_engine* engine_ = nullptr;
96 bool initialized_ = false;
97
99
107 Assets::Audio * asset = nullptr;
108 };
109 std::unordered_map<std::string, RegisteredAudio> registeredAudio_;
110
118 ma_sound* sound = nullptr;
119
123 std::string assetPath;
124 };
125 std::unordered_map<AudioHandle, PlayingSound> playingSounds_;
126
128 };
129
130} // namespace EngineCore
Holds decoded PCM audio data as an engine asset.
Definition AudioAsset.h:14
std::unordered_map< AudioHandle, PlayingSound > playingSounds_
bool isPlaying(AudioHandle handle) const
Check if a sound is currently playing.
void onAudioLoaded(Assets::Audio *asset, const std::filesystem::path &path)
Called by AudioAssetPipeline when an asset finishes loading. Registers the asset for playback.
void stopAll()
Stop all currently playing sounds.
void cleanup()
Shut down the audio engine and free all resources.
void setMasterVolume(float volume)
Set the master volume.
AudioEngine(const AudioEngine &)=delete
std::unordered_map< std::string, RegisteredAudio > registeredAudio_
bool init()
Initialize the miniaudio engine with AudioConfig settings.
AudioEngine & operator=(const AudioEngine &)=delete
bool isInitialized() const
Check if the audio engine initialized successfully.
Definition AudioEngine.h:92
AudioHandle play(const std::filesystem::path &path, float volume=1.0f, bool loop=false)
Play a loaded audio clip.
void stop(AudioHandle handle)
Stop a playing sound.
Manages IBL (Image-Based Lighting) resources for specular reflections.
constexpr AudioHandle INVALID_AUDIO_HANDLE
Definition AudioEngine.h:21
uint32_t AudioHandle
Identifies a playing sound instance.
Definition AudioEngine.h:20
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.
Audio asset registered for playback by path.
Assets::Audio * asset
Asset payload containing decoded audio data.