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
19namespace Engine::Core {
23 using AudioHandle = uint32_t;
25
33 public:
36
37 AudioEngine(const AudioEngine&) = delete;
39
44 bool init();
45
49 void cleanup();
50
57 void onAudioLoaded( Assets::Audio * asset, const std::filesystem::path& path);
58
66 AudioHandle play(const std::filesystem::path& path, float volume = 1.0f, bool loop = false);
67
72 void stop(AudioHandle handle);
73
77 void stopAll();
78
83 void setMasterVolume(float volume);
84
90 [[nodiscard]] bool isPlaying(AudioHandle handle) const;
91
95 [[nodiscard]] bool isInitialized() const { return initialized_; }
96
97 private:
98 ma_engine* engine_ = nullptr;
99 bool initialized_ = false;
100
102
104 Assets::Audio * asset = nullptr;
105 };
106 std::unordered_map<std::string, RegisteredAudio> registeredAudio_;
107
109 ma_sound* sound = nullptr;
110 std::string assetPath;
111 };
112 std::unordered_map<AudioHandle, PlayingSound> playingSounds_;
113
115 };
116
117} // namespace EngineCore
Holds decoded PCM audio data as an engine asset.
Definition AudioAsset.h:13
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:95
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.
Core audio subsystem owning the miniaudio engine and managing playback.
Definition AudioConfig.h:9
constexpr AudioHandle INVALID_AUDIO_HANDLE
Definition AudioEngine.h:24
uint32_t AudioHandle
Identifies a playing sound instance.
Definition AudioEngine.h:23