dEngine
Simple 2D C++ game engine
Public Member Functions | Static Public Member Functions | Private Attributes | Static Private Attributes | List of all members
dengine::AudioManager Class Reference

Manages the loading, unloading, and playing of sounds. More...

#include <AudioManager.h>

Public Member Functions

void AddSound (std::string name, std::string filepath)
 Add a sound to audio manager. More...
 
void LoadSounds ()
 Load added sounds to memory. More...
 
void PlaySound (std::string name)
 Play a sound. More...
 
void ClearSounds ()
 Clear all stored sounds. More...
 
void RemoveSound (std::string name)
 Remove a single sound. More...
 
bool HasSound (std::string name)
 Check if sound has been added. More...
 

Static Public Member Functions

static AudioManagerGetInstance ()
 

Private Attributes

std::map< std::string, std::shared_ptr< Sound > > audioCollection
 

Static Private Attributes

static AudioManagerinstance
 

Detailed Description

Manages the loading, unloading, and playing of sounds.

The audio manager is designed to be used by individual GameLevels to help manage sounds on a per level basis allowing only sounds for that level to be loaded at the loading screen

See also
Sound

Member Function Documentation

◆ AddSound()

void AudioManager::AddSound ( std::string  name,
std::string  filepath 
)

Add a sound to audio manager.

Add a sound to the audio manager without loading it into memory

Parameters
filepathFilepath to the wave file
nameThe name of the sound
See also
LoadSounds
AudioManager::GetInstance().AddSound("background","./Assets/background.wav");

◆ ClearSounds()

void AudioManager::ClearSounds ( )

Clear all stored sounds.

Clear all currently added and loaded sounds freeing up previously allocated space

◆ GetInstance()

AudioManager & AudioManager::GetInstance ( )
static

Returns an instance of the audio manager

◆ HasSound()

bool AudioManager::HasSound ( std::string  name)

Check if sound has been added.

Checks if sound has been added to audiomanager

Parameters
nameName of the sound
Returns
Whether sound currently exists in audiomanager or not
AudioManager::GetInstance().AddSound("background","./Assets/background.wav");
if(AudioManager::GetInstance().HasSound("background")){
}

◆ LoadSounds()

void AudioManager::LoadSounds ( )

Load added sounds to memory.

Loads all added sounds into memory

◆ PlaySound()

void AudioManager::PlaySound ( std::string  name)

Play a sound.

Plays a sound through the default audio device

Parameters
nameThe name of the sound
AudioManager::GetInstance().AddSound("background","./Assets/background.wav");

◆ RemoveSound()

void AudioManager::RemoveSound ( std::string  name)

Remove a single sound.

Removes a single sound by name from memory

Parameters
nameName of sound to remove

Member Data Documentation

◆ audioCollection

std::map<std::string, std::shared_ptr<Sound> > dengine::AudioManager::audioCollection
private

◆ instance

AudioManager * AudioManager::instance
staticprivate

Referenced by GetInstance().