Vulkan Schnee 0.0.1
High-performance rendering engine
Loading...
Searching...
No Matches
Engine::Core::AudioEngine Class Reference

Owns the miniaudio engine and provides the playback API. More...

#include <AudioEngine.h>

Collaboration diagram for Engine::Core::AudioEngine:

Classes

struct  PlayingSound
struct  RegisteredAudio

Public Member Functions

 AudioEngine ()
 ~AudioEngine ()
 AudioEngine (const AudioEngine &)=delete
AudioEngineoperator= (const AudioEngine &)=delete
bool init ()
 Initialize the miniaudio engine with AudioConfig settings.
void cleanup ()
 Shut down the audio engine and free all resources.
void onAudioLoaded (Assets::Audio *asset, const std::filesystem::path &path)
 Called by AudioAssetPipeline when an asset finishes loading. Registers the asset for playback.
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.
void stopAll ()
 Stop all currently playing sounds.
void setMasterVolume (float volume)
 Set the master volume.
bool isPlaying (AudioHandle handle) const
 Check if a sound is currently playing.
bool isInitialized () const
 Check if the audio engine initialized successfully.

Private Member Functions

void cleanupFinishedSounds ()

Private Attributes

ma_engine * engine_ = nullptr
bool initialized_ = false
AudioHandle nextHandle_ = 1
std::unordered_map< std::string, RegisteredAudioregisteredAudio_
std::unordered_map< AudioHandle, PlayingSoundplayingSounds_

Detailed Description

Owns the miniaudio engine and provides the playback API.

Initialized once during engine startup. Audio assets are registered via onAudioLoaded() and can then be played by path.

Definition at line 32 of file AudioEngine.h.

Constructor & Destructor Documentation

◆ AudioEngine() [1/2]

Engine::Core::AudioEngine::AudioEngine ( )

Referenced by AudioEngine(), and operator=().

Here is the caller graph for this function:

◆ ~AudioEngine()

Engine::Core::AudioEngine::~AudioEngine ( )

◆ AudioEngine() [2/2]

Engine::Core::AudioEngine::AudioEngine ( const AudioEngine & )
delete

References AudioEngine().

Here is the call graph for this function:

Member Function Documentation

◆ cleanup()

void Engine::Core::AudioEngine::cleanup ( )

Shut down the audio engine and free all resources.

◆ cleanupFinishedSounds()

void Engine::Core::AudioEngine::cleanupFinishedSounds ( )
private

◆ init()

bool Engine::Core::AudioEngine::init ( )

Initialize the miniaudio engine with AudioConfig settings.

Returns
true on success

◆ isInitialized()

bool Engine::Core::AudioEngine::isInitialized ( ) const
inlinenodiscard

Check if the audio engine initialized successfully.

Definition at line 95 of file AudioEngine.h.

References initialized_.

◆ isPlaying()

bool Engine::Core::AudioEngine::isPlaying ( AudioHandle handle) const
nodiscard

Check if a sound is currently playing.

Parameters
handleHandle returned by play()
Returns
true if the sound is still playing

◆ onAudioLoaded()

void Engine::Core::AudioEngine::onAudioLoaded ( Assets::Audio * asset,
const std::filesystem::path & path )

Called by AudioAssetPipeline when an asset finishes loading. Registers the asset for playback.

Parameters
assetThe loaded audio asset
pathThe asset path (used as lookup key)

◆ operator=()

AudioEngine & Engine::Core::AudioEngine::operator= ( const AudioEngine & )
delete

References AudioEngine().

Here is the call graph for this function:

◆ play()

AudioHandle Engine::Core::AudioEngine::play ( const std::filesystem::path & path,
float volume = 1.0f,
bool loop = false )

Play a loaded audio clip.

Parameters
pathAsset path of the clip to play
volumeVolume multiplier (0.0 - 1.0)
loopWhether to loop the sound
Returns
Handle to the playing sound, or INVALID_AUDIO_HANDLE on failure

◆ setMasterVolume()

void Engine::Core::AudioEngine::setMasterVolume ( float volume)

Set the master volume.

Parameters
volumeVolume multiplier (0.0 - 1.0)

◆ stop()

void Engine::Core::AudioEngine::stop ( AudioHandle handle)

Stop a playing sound.

Parameters
handleHandle returned by play()

◆ stopAll()

void Engine::Core::AudioEngine::stopAll ( )

Stop all currently playing sounds.

Member Data Documentation

◆ engine_

ma_engine* Engine::Core::AudioEngine::engine_ = nullptr
private

Definition at line 98 of file AudioEngine.h.

◆ initialized_

bool Engine::Core::AudioEngine::initialized_ = false
private

Definition at line 99 of file AudioEngine.h.

Referenced by isInitialized().

◆ nextHandle_

AudioHandle Engine::Core::AudioEngine::nextHandle_ = 1
private

Definition at line 101 of file AudioEngine.h.

◆ playingSounds_

std::unordered_map<AudioHandle, PlayingSound> Engine::Core::AudioEngine::playingSounds_
private

Definition at line 112 of file AudioEngine.h.

◆ registeredAudio_

std::unordered_map<std::string, RegisteredAudio> Engine::Core::AudioEngine::registeredAudio_
private

Definition at line 106 of file AudioEngine.h.


The documentation for this class was generated from the following file:
  • /home/magerbeton/Documents/gl3-vulkan/Engine/include/Engine/Audio/AudioEngine.h