utility 2026.1.9
A comprehensive C++ utilities library tailored for the development of modern desktop and extended reality (XR) applications.
Loading...
Searching...
No Matches
utility::sound::AudioManager Class Reference

Central manager responsible for OpenAL initialization and audio resource management. More...

#include <headers/utility/sound/audio_manager.hpp>

Inheritance diagram for utility::sound::AudioManager:
Collaboration diagram for utility::sound::AudioManager:

Public Member Functions

 AudioManager ()
 Creates and initializes the audio subsystem.
 
 ~AudioManager ()
 Stops the audio thread and releases OpenAL resources.
 
void submitCommand (const AudioCommand &command)
 Submits an audio command for asynchronous execution.
 
std::unique_ptr< AudioSourcecreateAudioSource (std::shared_ptr< AudioBuffer > buffer)
 Creates a new audio source.
 
void destroyAudioSource (uint32_t sourceID)
 Destroys an existing audio source.
 
void stop ()
 Requests termination of the audio thread.
 
bool isRunning () const
 Indicates whether the audio manager is running.
 

Additional Inherited Members

- Protected Member Functions inherited from utility::logging::Loggable< AudioManager, utility::logging::DefaultLogger >
 Loggable (void)
 Construct a Loggable with the specified LoggerType.
 
 Loggable (Loggable &&other) noexcept
 Move constructor for Loggable.
 
Loggableoperator= (Loggable &&other) noexcept
 Move assignment operator for Loggable.
 
LoggerType & getLogger (void)
 Get the internal logger.
 
LoggerType & getLogger (void) const
 Get the internal logger.
 
virtual ~Loggable (void)=default
 Virtual destructor for proper cleanup.
 

Detailed Description

Central manager responsible for OpenAL initialization and audio resource management.

AudioManager owns the OpenAL device and context and executes all OpenAL operations on a dedicated audio thread.

AudioSource instances communicate with the manager by submitting AudioCommand objects through a thread-safe command queue.

This class is responsible for:

  • Initializing and shutting down OpenAL
  • Creating and destroying OpenAL sources
  • Processing asynchronous audio commands
  • Synchronizing access to shared audio resources
Note
All OpenAL calls should be performed on the audio thread.

Definition at line 161 of file audio_manager.hpp.

Constructor & Destructor Documentation

◆ AudioManager()

utility::sound::AudioManager::AudioManager ( )

Creates and initializes the audio subsystem.

This constructor opens the default OpenAL device, creates an audio context, and starts the dedicated audio processing thread.

If the audio device or context cannot be created, the manager degrades gracefully: audio is disabled (isRunning() returns false) and no exception is thrown, so callers can continue without audio.

Definition at line 24 of file audio_manager.cpp.

Here is the call graph for this function:

◆ ~AudioManager()

utility::sound::AudioManager::~AudioManager ( )

Stops the audio thread and releases OpenAL resources.

This destructor waits for the audio thread to terminate, destroys the OpenAL context, and closes the audio device.

Definition at line 49 of file audio_manager.cpp.

Member Function Documentation

◆ createAudioSource()

std::unique_ptr< utility::sound::AudioSource > utility::sound::AudioManager::createAudioSource ( std::shared_ptr< AudioBuffer buffer)

Creates a new audio source.

The corresponding OpenAL source object is created asynchronously on the audio thread.

Parameters
bufferInitial audio buffer assigned to the source.
Returns
A unique pointer to the created AudioSource instance.

Definition at line 69 of file audio_manager.cpp.

◆ destroyAudioSource()

void utility::sound::AudioManager::destroyAudioSource ( uint32_t  sourceID)

Destroys an existing audio source.

Parameters
sourceIDIdentifier of the source to destroy.
Note
Consider submitting a DestroySource command instead of directly performing OpenAL operations to ensure all audio API calls remain confined to the audio thread.

Definition at line 90 of file audio_manager.cpp.

◆ isRunning()

bool utility::sound::AudioManager::isRunning ( ) const

Indicates whether the audio manager is running.

Returns
true if the audio thread is active, false otherwise.

Definition at line 114 of file audio_manager.cpp.

◆ stop()

void utility::sound::AudioManager::stop ( )

Requests termination of the audio thread.

Definition at line 108 of file audio_manager.cpp.

◆ submitCommand()

void utility::sound::AudioManager::submitCommand ( const AudioCommand command)

Submits an audio command for asynchronous execution.

Commands are stored in a thread-safe queue and processed by the audio thread.

Parameters
commandThe command to enqueue.

Definition at line 62 of file audio_manager.cpp.


The documentation for this class was generated from the following files: