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::AudioSource Class Reference

Represents a playable audio source managed by AudioManager. More...

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

Public Member Functions

 AudioSource (uint32_t sourceID, AudioManager &manager)
 Creates a new audio source.
 
 ~AudioSource ()
 Destroys the audio source.
 
void play ()
 Starts or resumes audio playback.
 
void pause ()
 Pauses audio playback.
 
void stop ()
 Stops audio playback.
 
void setBuffer (std::shared_ptr< AudioBuffer > buffer)
 Assigns an audio buffer to this source.
 
void setLooping (bool loop)
 Enables or disables looping playback.
 
void setPitch (float pitch)
 Sets the playback pitch.
 
void setGain (float gain)
 Sets the playback gain.
 
uint32_t sourceID () const
 Returns the unique identifier of this audio source.
 

Detailed Description

Represents a playable audio source managed by AudioManager.

This class provides a high-level interface for controlling audio playback, including starting, stopping, pausing, and modifying playback properties such as gain, pitch, and looping state.

AudioSource instances do not interact with OpenAL directly. Instead, they submit commands to the associated AudioManager, which processes them asynchronously on a dedicated audio thread.

An AudioSource owns a unique source identifier used by AudioManager to reference the underlying OpenAL source object.

Note
Destroying an AudioSource automatically releases its associated OpenAL source through AudioManager.

Definition at line 54 of file audio_source.hpp.

Constructor & Destructor Documentation

◆ AudioSource()

utility::sound::AudioSource::AudioSource ( uint32_t  sourceID,
AudioManager manager 
)

Creates a new audio source.

Parameters
sourceIDUnique identifier assigned by AudioManager.
managerReference to the AudioManager responsible for processing audio commands.

Definition at line 25 of file audio_source.cpp.

◆ ~AudioSource()

utility::sound::AudioSource::~AudioSource ( )

Destroys the audio source.

The associated OpenAL source is released through AudioManager.

Definition at line 32 of file audio_source.cpp.

Member Function Documentation

◆ pause()

void utility::sound::AudioSource::pause ( )

Pauses audio playback.

Playback can later be resumed by calling play().

Definition at line 43 of file audio_source.cpp.

◆ play()

void utility::sound::AudioSource::play ( )

Starts or resumes audio playback.

Playback is performed asynchronously by the audio thread.

Definition at line 37 of file audio_source.cpp.

◆ setBuffer()

void utility::sound::AudioSource::setBuffer ( std::shared_ptr< AudioBuffer buffer)

Assigns an audio buffer to this source.

The buffer contains the decoded audio data to be played.

Parameters
bufferShared audio buffer associated with this source.

Definition at line 55 of file audio_source.cpp.

◆ setGain()

void utility::sound::AudioSource::setGain ( float  gain)

Sets the playback gain.

Parameters
gainVolume multiplier.

Definition at line 80 of file audio_source.cpp.

◆ setLooping()

void utility::sound::AudioSource::setLooping ( bool  loop)

Enables or disables looping playback.

Parameters
loopTrue to enable looping, false otherwise.

Definition at line 64 of file audio_source.cpp.

◆ setPitch()

void utility::sound::AudioSource::setPitch ( float  pitch)

Sets the playback pitch.

Values greater than 1.0 increase playback speed and pitch, while values lower than 1.0 decrease them.

Parameters
pitchPitch multiplier.

Definition at line 72 of file audio_source.cpp.

◆ sourceID()

uint32_t utility::sound::AudioSource::sourceID ( ) const

Returns the unique identifier of this audio source.

Returns
The source identifier assigned by AudioManager.

Definition at line 88 of file audio_source.cpp.

◆ stop()

void utility::sound::AudioSource::stop ( )

Stops audio playback.

Stopping playback resets the playback position to the beginning of the audio stream.

Definition at line 49 of file audio_source.cpp.


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