BARE2D
BARE2D::AudioManager Class Reference

#include <AudioManager.hpp>

+ Collaboration diagram for BARE2D::AudioManager:

Public Member Functions

void init ()
 Initializes all necessary bits and pieces. More...
 
void destroy ()
 Destroys/quits all necessary bits and pieces. More...
 
unsigned int playSound (Sound &sound, unsigned int fadeTime=0, unsigned int timeOut=0, int angle=0, unsigned char distance=128)
 Plays a sound at a position. More...
 
void moveSound (unsigned int &soundID, int angle, unsigned char distance=128)
 Resets the sound's position for positional audio. More...
 
void stopSound (unsigned int &soundID, unsigned int fadeTime=0)
 Stops a sound. More...
 
void pauseSound (unsigned int &soundID)
 Pauses a sound. More...
 
void resumeSound (unsigned int &soundID)
 Resumes a paused sound. More...
 
void playMusic (Music &music, unsigned int fadeTime=0)
 Plays some music! Only one "music" can be played at a time. More...
 
void stopMusic (unsigned int fadeTime=0)
 Stops the music. More...
 
void pauseMusic ()
 Pauses the music. More...
 
void resumeMusic ()
 Resumes the paused music. More...
 
void mute ()
 Mutes all sounds and music. More...
 
void unmute ()
 Unmutes all sounds and music. More...
 
void setSoundVolume (unsigned char volumeLevel)
 Sets the volume level of all sounds. More...
 
void setMusicVolume (unsigned char volumeLevel)
 Sets the volume level of all music. More...
 
void setMasterVolumeModifier (unsigned char masterLevel)
 Sets the modifier of all sound levels - eg., if sounds were set at 40% and music at 60%, setting the master modifier to 50% would set sounds to 20% and music to 30%. More...
 
bool isMusicPlaying ()
 

Static Public Member Functions

static AudioManagergetInstance ()
 
static void release ()
 

Private Member Functions

 AudioManager ()
 
 ~AudioManager ()
 

Private Attributes

unsigned char m_soundVolume = 255
 
unsigned char m_musicVolume = 255
 
unsigned char m_masterVolume = 255
 
bool m_muted = false
 

Static Private Attributes

static AudioManagerm_instance = nullptr
 

Detailed Description

Definition at line 14 of file AudioManager.hpp.

Constructor & Destructor Documentation

◆ AudioManager()

BARE2D::AudioManager::AudioManager ( )
private

Definition at line 28 of file AudioManager.cpp.

Referenced by getInstance().

+ Here is the caller graph for this function:

◆ ~AudioManager()

BARE2D::AudioManager::~AudioManager ( )
private

Definition at line 32 of file AudioManager.cpp.

Member Function Documentation

◆ destroy()

void BARE2D::AudioManager::destroy ( )

Destroys/quits all necessary bits and pieces.

Definition at line 71 of file AudioManager.cpp.

References BARE2D::SDL_MIXER_CLOSE_FAILURE, and BARE2D::throwError().

Referenced by release().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getInstance()

AudioManager * BARE2D::AudioManager::getInstance ( )
static

Definition at line 12 of file AudioManager.cpp.

References AudioManager(), and m_instance.

+ Here is the call graph for this function:

◆ init()

void BARE2D::AudioManager::init ( )

Initializes all necessary bits and pieces.

Definition at line 37 of file AudioManager.cpp.

References BARE2D::SDL_MIXER_FLAC_FAILURE, BARE2D::SDL_MIXER_MOD_FAILURE, BARE2D::SDL_MIXER_MP3_FAILURE, BARE2D::SDL_MIXER_OGG_FAILURE, and BARE2D::throwError().

+ Here is the call graph for this function:

◆ isMusicPlaying()

bool BARE2D::AudioManager::isMusicPlaying ( )
Returns
True if there is music currently playing, false otherwise.

Definition at line 223 of file AudioManager.cpp.

◆ moveSound()

void BARE2D::AudioManager::moveSound ( unsigned int &  soundID,
int  angle,
unsigned char  distance = 128 
)

Resets the sound's position for positional audio.

Parameters
soundIDA reference to the ID that represents the sound to move.
angleThe angle (clockwise in degrees, where 0 is directly forward) that the sound is to be played at.
distanceThe distance from the camera that the sound should be played (from 0 (very near, loud) to 255 (very distant, quiet))

Definition at line 119 of file AudioManager.cpp.

References utf8::distance(), BARE2D::SDL_MIXER_SOUND_FAILURE, and BARE2D::throwFatalError().

+ Here is the call graph for this function:

◆ mute()

void BARE2D::AudioManager::mute ( )

Mutes all sounds and music.

Definition at line 179 of file AudioManager.cpp.

References m_musicVolume, m_muted, and m_soundVolume.

◆ pauseMusic()

void BARE2D::AudioManager::pauseMusic ( )

Pauses the music.

Definition at line 169 of file AudioManager.cpp.

◆ pauseSound()

void BARE2D::AudioManager::pauseSound ( unsigned int &  soundID)

Pauses a sound.

Parameters
soundIDThe ID of the sound to pause, given by playSound(...) calls.

Definition at line 135 of file AudioManager.cpp.

◆ playMusic()

void BARE2D::AudioManager::playMusic ( Music music,
unsigned int  fadeTime = 0 
)

Plays some music! Only one "music" can be played at a time.

Parameters
musicThe music to play
fadeTimeThe number of milliseconds that the sound will take to fade in. Defaults to 0 (no fade).

Definition at line 145 of file AudioManager.cpp.

References BARE2D::Music::music, BARE2D::SDL_MIXER_SOUND_FAILURE, and BARE2D::throwFatalError().

+ Here is the call graph for this function:

◆ playSound()

unsigned int BARE2D::AudioManager::playSound ( Sound sound,
unsigned int  fadeTime = 0,
unsigned int  timeOut = 0,
int  angle = 0,
unsigned char  distance = 128 
)

Plays a sound at a position.

Parameters
soundA reference to the sound that is to be played.
fadeTimeThe number of milliseconds that the sound will take to fade in. Defaults to 0 (no fade).
timeOutthe number of milliseconds before the sound times out. Defaults to 0 (never).
angleThe angle (clockwise in degrees, where 0 is directly forward) that the sound is to be played at. Defaults to 0 (directly in front)
distanceThe distance from the camera that the sound should be played (from 0 (very near, loud) to 255 (very distant, quiet))
Returns
The unsigned integer that represents the sound's ID.

Definition at line 92 of file AudioManager.cpp.

References BARE2D::Sound::chunk, BARE2D::SDL_MIXER_SOUND_FAILURE, and BARE2D::throwFatalError().

+ Here is the call graph for this function:

◆ release()

void BARE2D::AudioManager::release ( )
static

Definition at line 20 of file AudioManager.cpp.

References destroy(), and m_instance.

+ Here is the call graph for this function:

◆ resumeMusic()

void BARE2D::AudioManager::resumeMusic ( )

Resumes the paused music.

Definition at line 174 of file AudioManager.cpp.

◆ resumeSound()

void BARE2D::AudioManager::resumeSound ( unsigned int &  soundID)

Resumes a paused sound.

Parameters
soundIDThe ID of the sound to resume, given by playSound(...) calls.

Definition at line 140 of file AudioManager.cpp.

◆ setMasterVolumeModifier()

void BARE2D::AudioManager::setMasterVolumeModifier ( unsigned char  masterLevel)

Sets the modifier of all sound levels - eg., if sounds were set at 40% and music at 60%, setting the master modifier to 50% would set sounds to 20% and music to 30%.

Parameters
masterLevelThe level of the volume - 0 is muted, 255 is very loud.

Definition at line 210 of file AudioManager.cpp.

References m_masterVolume, m_musicVolume, m_soundVolume, setMusicVolume(), and setSoundVolume().

+ Here is the call graph for this function:

◆ setMusicVolume()

void BARE2D::AudioManager::setMusicVolume ( unsigned char  volumeLevel)

Sets the volume level of all music.

Parameters
volumeLevelThe level of the volume - 0 is muted, 255 is very loud.

Definition at line 204 of file AudioManager.cpp.

References m_masterVolume, and m_musicVolume.

Referenced by setMasterVolumeModifier().

+ Here is the caller graph for this function:

◆ setSoundVolume()

void BARE2D::AudioManager::setSoundVolume ( unsigned char  volumeLevel)

Sets the volume level of all sounds.

Parameters
volumeLevelThe level of the volume (clamped from 0 (muted) to 255(loud))

Definition at line 198 of file AudioManager.cpp.

References m_masterVolume, and m_soundVolume.

Referenced by setMasterVolumeModifier().

+ Here is the caller graph for this function:

◆ stopMusic()

void BARE2D::AudioManager::stopMusic ( unsigned int  fadeTime = 0)

Stops the music.

Parameters
fadeTimeThe number of milliseconds the sound will take to fade out. Defaults to 0 (no fade).

Definition at line 160 of file AudioManager.cpp.

◆ stopSound()

void BARE2D::AudioManager::stopSound ( unsigned int &  soundID,
unsigned int  fadeTime = 0 
)

Stops a sound.

Parameters
fadeTimeThe number of milliseconds the sound will take to fade out. Defaults to 0 (no fade).
soundIDThe ID of the sound to stop, given by playSound(...) calls.

Definition at line 126 of file AudioManager.cpp.

◆ unmute()

void BARE2D::AudioManager::unmute ( )

Unmutes all sounds and music.

Definition at line 189 of file AudioManager.cpp.

References m_musicVolume, m_muted, and m_soundVolume.

Field Documentation

◆ m_instance

AudioManager * BARE2D::AudioManager::m_instance = nullptr
staticprivate

Definition at line 118 of file AudioManager.hpp.

Referenced by getInstance(), and release().

◆ m_masterVolume

unsigned char BARE2D::AudioManager::m_masterVolume = 255
private

Definition at line 120 of file AudioManager.hpp.

Referenced by setMasterVolumeModifier(), setMusicVolume(), and setSoundVolume().

◆ m_musicVolume

unsigned char BARE2D::AudioManager::m_musicVolume = 255
private

Definition at line 120 of file AudioManager.hpp.

Referenced by mute(), setMasterVolumeModifier(), setMusicVolume(), and unmute().

◆ m_muted

bool BARE2D::AudioManager::m_muted = false
private

Definition at line 121 of file AudioManager.hpp.

Referenced by mute(), and unmute().

◆ m_soundVolume

unsigned char BARE2D::AudioManager::m_soundVolume = 255
private

Definition at line 120 of file AudioManager.hpp.

Referenced by mute(), setMasterVolumeModifier(), setSoundVolume(), and unmute().


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