Public Member Functions | List of all members
ime::audio::AudioManager Class Reference

Class for managing audio. More...

#include <AudioManager.h>

Public Member Functions

 AudioManager ()
 Default constructor. More...
 
 AudioManager (const AudioManager &)=delete
 Copy constructor. More...
 
AudioManageroperator= (const AudioManager &)=delete
 Copy assignment operator. More...
 
 AudioManager (AudioManager &&) noexcept=default
 Move constructor. More...
 
AudioManageroperator= (AudioManager &&) noexcept=default
 Move assignment operator. More...
 
void play (Type audioType, const std::string &filename, bool isLooped=false)
 Play an audio file. More...
 
void setVolumeFor (Type audioType, float volume)
 Set the volume for an audio type. More...
 
float getVolumeFor (Type audioType) const
 Get the volume of an audio type. More...
 
void setMasterVolume (float volume)
 Set the maximum volume for all audio types. More...
 
void adjustMasterVolume (float offset)
 Offset the maximum volume for all audio players. More...
 
float getMasterVolume () const
 Get the maximum volume for all audio players. More...
 
void playAllAudio ()
 Play all paused/stopped audio files. More...
 
void pauseAllAudio ()
 Pause all playing audio files. More...
 
void stopAllAudio ()
 Stop all playing audio files. More...
 
void setMute (bool isMuted)
 Mute or unmute all audio players. More...
 
void onMute (Callback< bool > callback)
 Add an event listener to a mute event. More...
 
void onVolumeChanged (Callback< float > callback)
 Add an event listener to a volume change event. More...
 
void removePlayedAudio ()
 Remove audio that has finished playing. More...
 

Detailed Description

Class for managing audio.

This class allows us to play multiple audio files at the same time. This class can play multiple sound effects at the same time as one music file. Playing another music file while there is a music file playing will replace it. Each audio file is played in a separate thread

See also
Music and SoundEffect

Definition at line 56 of file AudioManager.h.

Constructor & Destructor Documentation

◆ AudioManager() [1/3]

ime::audio::AudioManager::AudioManager ( )

Default constructor.

◆ AudioManager() [2/3]

ime::audio::AudioManager::AudioManager ( const AudioManager )
delete

Copy constructor.

◆ AudioManager() [3/3]

ime::audio::AudioManager::AudioManager ( AudioManager &&  )
defaultnoexcept

Move constructor.

Member Function Documentation

◆ adjustMasterVolume()

void ime::audio::AudioManager::adjustMasterVolume ( float  offset)

Offset the maximum volume for all audio players.

Parameters
offsetVolume offset

This function will add/subtract to/from the current volume

See also
setMasterVolume

◆ getMasterVolume()

float ime::audio::AudioManager::getMasterVolume ( ) const

Get the maximum volume for all audio players.

Returns
The maximum volume for all audio players

◆ getVolumeFor()

float ime::audio::AudioManager::getVolumeFor ( Type  audioType) const

Get the volume of an audio type.

Parameters
audioTypeType of the audio to get volume for
Returns
The volume for a given audio type

◆ onMute()

void ime::audio::AudioManager::onMute ( Callback< bool >  callback)

Add an event listener to a mute event.

Parameters
callbackFunction to execute when mute state changes

◆ onVolumeChanged()

void ime::audio::AudioManager::onVolumeChanged ( Callback< float >  callback)

Add an event listener to a volume change event.

Parameters
callbackFunction to execute when volume changes

◆ operator=() [1/2]

AudioManager& ime::audio::AudioManager::operator= ( AudioManager &&  )
defaultnoexcept

Move assignment operator.

◆ operator=() [2/2]

AudioManager& ime::audio::AudioManager::operator= ( const AudioManager )
delete

Copy assignment operator.

◆ pauseAllAudio()

void ime::audio::AudioManager::pauseAllAudio ( )

Pause all playing audio files.

◆ play()

void ime::audio::AudioManager::play ( Type  audioType,
const std::string &  filename,
bool  isLooped = false 
)

Play an audio file.

Parameters
audioTypeType of the audio file to play
filenameFilename of the audio to play
isLoopedTrue if audio should be looped, otherwise false
Exceptions
FileNotFoundif the audio file cannot be found on the disk

The audio files are played in a separate thread. This means that, the main thread is not blocked and other audio file may be played simultaneously.

◆ playAllAudio()

void ime::audio::AudioManager::playAllAudio ( )

Play all paused/stopped audio files.

◆ removePlayedAudio()

void ime::audio::AudioManager::removePlayedAudio ( )

Remove audio that has finished playing.

The number of audio that played and stopped must not be left to reach 255, otherwise an error would occur and audio will stop playing

◆ setMasterVolume()

void ime::audio::AudioManager::setMasterVolume ( float  volume)

Set the maximum volume for all audio types.

Parameters
volumeThe new maximum volume

This function will overwrite the previous volume The maximum volume for all audio players is 100 by default

See also
adjustMasterVolume

◆ setMute()

void ime::audio::AudioManager::setMute ( bool  isMuted)

Mute or unmute all audio players.

Parameters
isMutedTrue to mute all audio, otherwise false

◆ setVolumeFor()

void ime::audio::AudioManager::setVolumeFor ( Type  audioType,
float  volume 
)

Set the volume for an audio type.

Parameters
audioTypeType of the audio file to set volume for
volumeVolume to set, in the range (mute) 0 <= volume <= 100 (max)

The default volume is 100 (max) for all audio types

◆ stopAllAudio()

void ime::audio::AudioManager::stopAllAudio ( )

Stop all playing audio files.

Stopping an audio file (playing/paused) will reset the current playing position to the beginning


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