hoa_audio::GameAudio Class Reference

A singleton class for managing and interfacing with audio data. More...

#include <audio.h>

Inheritance diagram for hoa_audio::GameAudio:

Inheritance graph
[legend]
Collaboration diagram for hoa_audio::GameAudio:

Collaboration graph
[legend]
List of all members.

Public Member Functions

uint32 CheckErrors ()
 Returns a set of error codes and also clears the error code to a no-error state.
void DEBUG_PrintInfo ()
 Prints information related to the system's audio capabilities as reported by SDL_mixer.
void PlaySound (std::string filename)
 Plays a sound once.
bool SingletonInitialize ()
 A method for the inheriting class to implement, which initializes the class.
void Update ()
 Periodically removes any temporarily loaded sounds that have finished playing.
 ~GameAudio ()
Volume Member Access Functions
Used for reading and modifying the volume of music/sound in the game.

These volume changes have a global effect (they modify the volume of all music/sound sources). There is currently no support to change the volume levels of individual sound or music sources. However, one can achieve the same effect by modifying the source properties and (in the case of single-channel audio) manipulating distance attenuation.

Note:
In OpenAL, the gain property of sources is essentially the volume.

In addition to these functions, you can also change the gain (volume) of the listener, which will effect the volume level of all audio heard in the game.



float GetMusicVolume ()
float GetSoundVolume ()
void SetMusicVolume (float vol)
void SetSoundVolume (float vol)
Global Music Manipulation Functions
Performs specified operation on all active music.

Since there is only one music source, these functions only affect that source. They are equivalent to calling the {Pause/Resume/Stop/Rewind}Music functions on the MusicDescriptor which currently has posession of the source.

void PauseAllMusic ()
void ResumeAllMusic ()
void RewindAllMusic ()
void StopAllMusic ()
Global Sound Manipulation Functions
Performs specified operation on all active sounds.

void PauseAllSounds ()
void ResumeAllSounds ()
void StopAllSounds ()
Global Audio Manipulation Functions
Performs specified operation on all active sounds and music.

These functions will only effect audio data that is in the state(s) specified below: PauseAudio() <==> playing state ResumeAudio() <==> paused state StopAudio() <==> playing state RewindAudio() <==> playing state, paused state

void PauseAudio ()
void ResumeAudio ()
void RewindAudio ()
void StopAudio ()

Private Member Functions

 GameAudio ()
Audio Data Retrieval Functions
Creates and loads new audio data if the data is not already loaded.

Parameters:
filename The filename of the file data to search for (not including the pathname or file extension).
Returns:
A pointer to the class object holding the new data. NULL may also be returned, indicating an error.
These functions are critical to ensuring efficient memory usage in the audio engine (in other words: making sure no more than one copy of audio data is loaded into the engine at any given time). When these functions are called, first the map of audio data objects is searched to see if the data is already found in there. If it is, a pointer to that object is returned. Otherwise, the function will attempt to create a new object and store that into the appropriate data object map. If that fails for some reason, the function will return NULL.

private_audio::MusicData_AcquireMusicData (std::string filename)
private_audio::SoundData_AcquireSoundData (std::string filename)

Private Attributes

uint32 _audio_errors
 Retains all the errors that have occured on audio-related function calls, except for loading errors.
float _music_volume
 The volume level for music playback. Valid range is between 0.0f and 1.0f.
float _sound_volume
 The volume level for sound playback. Valid range is between 0.0f and 1.0f.
std::list< SoundDescriptor * > _temp_sounds
 Holds sounds which are temporarily loaded and played This vector holds any sounds loaded via a call to AudioManager::PlaySound. It will play the sound once to completion. The AudioManager::Update call periodically reviews this list and removes any sounds which have finished playing.
Audio Data Containers
Sound (WAV) and music (OGG) data are stored in these container classes and referenced by the SoundDescriptor and MusicDescriptor classes. They are stored in this manner to allow for optimized memory usage (in other words, only one instance of .wav and .ogg data can be loaded in the application at any point in time). The sound or music filename string serves as the map key for determining if the data is loaded or not. The key is a reference to the filename string (which is stored in the SoundData or MusicData class itself).

std::map< std::string, private_audio::MusicData * > _music_data
std::map< std::string, private_audio::SoundData * > _sound_data

Friends

class hoa_utils::Singleton< GameAudio >
class MusicDescriptor
class private_audio::MusicData
class private_audio::SoundData
class SoundDescriptor

Detailed Description

A singleton class for managing and interfacing with audio data.

****************************************************************************

This class manages all audio data allocation and manipulation. The OpenAL sources are wrapped inside this class and OpenAL buffers (which are represented by the SoundDescriptor and MusicObject classes) grab these sources as they need them. The buffers are stored in map structures so that audio data is not loaded when it already exists.

Note:
1) Operations that load audio data should be done during parts of the game when game modes are being created and destroyed. In other words, ideally you should load data into SoundSource and MusicSource objects when a new game mode class object is created, instead of creating them only immediately before they are needed.

2) This audio engine uses smart memory management so that loaded audio data is not re-loaded if the user requests a load operation on the same data. Audio data is only freed once there are no more references to the data.

Definition at line 120 of file audio.h.


Constructor & Destructor Documentation

hoa_audio::GameAudio::~GameAudio (  ) 

Definition at line 52 of file audio.cpp.

References _music_data, _sound_data, hoa_audio::private_audio::ALL_CHANNELS, and hoa_audio::AUDIO_DEBUG.

hoa_audio::GameAudio::GameAudio (  )  [private]

Definition at line 46 of file audio.cpp.

References hoa_audio::AUDIO_DEBUG.


Member Function Documentation

private_audio::MusicData* hoa_audio::GameAudio::_AcquireMusicData ( std::string  filename  )  [private]

Referenced by hoa_audio::MusicDescriptor::LoadMusic().

private_audio::SoundData* hoa_audio::GameAudio::_AcquireSoundData ( std::string  filename  )  [private]

uint32 hoa_audio::GameAudio::CheckErrors (  )  [inline]

Returns a set of error codes and also clears the error code to a no-error state.

This is the standard CheckErrors() function as defined in the Allacrost code standard. The error code constants are listed at the top of this file in the Audio Error Codes group.

Definition at line 139 of file audio.h.

References _audio_errors, and hoa_audio::AUDIO_ERROR_NONE.

void hoa_audio::GameAudio::DEBUG_PrintInfo (  ) 

Prints information related to the system's audio capabilities as reported by SDL_mixer.

Definition at line 289 of file audio.cpp.

float hoa_audio::GameAudio::GetMusicVolume (  )  [inline]

Definition at line 162 of file audio.h.

References _music_volume.

Referenced by hoa_boot::BootMode::_OnMusicLeft(), hoa_boot::BootMode::_OnMusicRight(), hoa_boot::BootMode::_SaveSettingsFile(), and hoa_boot::BootMode::_UpdateAudioOptions().

float hoa_audio::GameAudio::GetSoundVolume (  )  [inline]

Definition at line 164 of file audio.h.

References _sound_volume.

Referenced by hoa_boot::BootMode::_OnSoundLeft(), hoa_boot::BootMode::_OnSoundRight(), hoa_boot::BootMode::_SaveSettingsFile(), and hoa_boot::BootMode::_UpdateAudioOptions().

void hoa_audio::GameAudio::PauseAllMusic (  ) 

Definition at line 259 of file audio.cpp.

References _music_data.

Referenced by PauseAudio().

void hoa_audio::GameAudio::PauseAllSounds (  ) 

Definition at line 241 of file audio.cpp.

References hoa_audio::private_audio::ALL_CHANNELS.

Referenced by PauseAudio().

void hoa_audio::GameAudio::PauseAudio (  ) 

Definition at line 220 of file audio.cpp.

References PauseAllMusic(), and PauseAllSounds().

Here is the call graph for this function:

void hoa_audio::GameAudio::PlaySound ( std::string  filename  ) 

Plays a sound once.

Parameters:
filename The name of the sound file to play
This method of playback is useful because it doesn't require any SoundDescriptor objects to be managed by the user. This is ideal for the case of scripts which wish to play a sound only once.

Referenced by hoa_battle::private_battle::FinishWindow::Update().

void hoa_audio::GameAudio::ResumeAllMusic (  ) 

Definition at line 267 of file audio.cpp.

References _music_data.

Referenced by ResumeAudio().

void hoa_audio::GameAudio::ResumeAllSounds (  ) 

Definition at line 246 of file audio.cpp.

References hoa_audio::private_audio::ALL_CHANNELS.

Referenced by ResumeAudio().

void hoa_audio::GameAudio::ResumeAudio (  ) 

Definition at line 225 of file audio.cpp.

References ResumeAllMusic(), and ResumeAllSounds().

Here is the call graph for this function:

void hoa_audio::GameAudio::RewindAllMusic (  ) 

Definition at line 283 of file audio.cpp.

Referenced by RewindAudio().

void hoa_audio::GameAudio::RewindAudio (  ) 

Definition at line 235 of file audio.cpp.

References RewindAllMusic().

Here is the call graph for this function:

void hoa_audio::GameAudio::SetMusicVolume ( float  vol  ) 

Definition at line 182 of file audio.cpp.

References _music_volume, and hoa_audio::AUDIO_DEBUG.

Referenced by hoa_boot::BootMode::_OnMusicLeft(), hoa_boot::BootMode::_OnMusicRight(), and hoa_system::GameSystem::SingletonInitialize().

void hoa_audio::GameAudio::SetSoundVolume ( float  vol  ) 

Definition at line 201 of file audio.cpp.

References _sound_volume, hoa_audio::private_audio::ALL_CHANNELS, and hoa_audio::AUDIO_DEBUG.

Referenced by hoa_boot::BootMode::_OnSoundLeft(), hoa_boot::BootMode::_OnSoundRight(), and hoa_system::GameSystem::SingletonInitialize().

bool hoa_audio::GameAudio::SingletonInitialize (  )  [virtual]

A method for the inheriting class to implement, which initializes the class.

Returns:
True if initialization was successful, false if it was not

Implements hoa_utils::Singleton< T >.

Definition at line 74 of file audio.cpp.

References hoa_audio::AUDIO_DEBUG, hoa_audio::private_audio::BUFFER_SIZE, and hoa_audio::private_audio::SOUND_CHANNELS.

Referenced by InitializeEngine().

void hoa_audio::GameAudio::StopAllMusic (  ) 

Definition at line 275 of file audio.cpp.

References _music_data.

Referenced by hoa_audio::MusicDescriptor::PlayMusic(), and StopAudio().

void hoa_audio::GameAudio::StopAllSounds (  ) 

Definition at line 251 of file audio.cpp.

References hoa_audio::private_audio::ALL_CHANNELS.

Referenced by StopAudio().

void hoa_audio::GameAudio::StopAudio (  ) 

Definition at line 230 of file audio.cpp.

References StopAllMusic(), and StopAllSounds().

Here is the call graph for this function:

void hoa_audio::GameAudio::Update (  ) 

Periodically removes any temporarily loaded sounds that have finished playing.

This method is called once every frame, but it only actually checks for finished sounds once every 5 seconds.

Definition at line 94 of file audio.cpp.

References _temp_sounds, hoa_audio::AUDIO_STATE_STOPPED, hoa_system::GameSystem::GetUpdateTime(), and hoa_system::SystemManager.

Referenced by main().

Here is the call graph for this function:


Friends And Related Function Documentation

friend class hoa_utils::Singleton< GameAudio > [friend]

Definition at line 122 of file audio.h.

friend class MusicDescriptor [friend]

Definition at line 126 of file audio.h.

friend class private_audio::MusicData [friend]

Definition at line 125 of file audio.h.

friend class private_audio::SoundData [friend]

Definition at line 123 of file audio.h.

friend class SoundDescriptor [friend]

Definition at line 124 of file audio.h.


Member Data Documentation

uint32 hoa_audio::GameAudio::_audio_errors [private]

Retains all the errors that have occured on audio-related function calls, except for loading errors.

Definition at line 229 of file audio.h.

Referenced by CheckErrors(), hoa_audio::private_audio::SoundData::DEBUG_PrintProperties(), hoa_audio::private_audio::MusicData::DEBUG_PrintProperties(), hoa_audio::MusicDescriptor::PauseMusic(), hoa_audio::SoundDescriptor::PauseSound(), hoa_audio::SoundDescriptor::PlaySound(), hoa_audio::MusicDescriptor::ResumeMusic(), hoa_audio::SoundDescriptor::ResumeSound(), hoa_audio::MusicDescriptor::RewindMusic(), hoa_audio::MusicDescriptor::SeekMusic(), hoa_audio::MusicDescriptor::StopMusic(), and hoa_audio::SoundDescriptor::StopSound().

std::map<std::string, private_audio::MusicData*> hoa_audio::GameAudio::_music_data [private]

Definition at line 239 of file audio.h.

Referenced by PauseAllMusic(), ResumeAllMusic(), StopAllMusic(), and ~GameAudio().

float hoa_audio::GameAudio::_music_volume [private]

The volume level for music playback. Valid range is between 0.0f and 1.0f.

Definition at line 225 of file audio.h.

Referenced by GetMusicVolume(), and SetMusicVolume().

std::map<std::string, private_audio::SoundData*> hoa_audio::GameAudio::_sound_data [private]

Definition at line 240 of file audio.h.

Referenced by ~GameAudio().

float hoa_audio::GameAudio::_sound_volume [private]

The volume level for sound playback. Valid range is between 0.0f and 1.0f.

Definition at line 227 of file audio.h.

Referenced by GetSoundVolume(), and SetSoundVolume().

std::list<SoundDescriptor*> hoa_audio::GameAudio::_temp_sounds [private]

Holds sounds which are temporarily loaded and played This vector holds any sounds loaded via a call to AudioManager::PlaySound. It will play the sound once to completion. The AudioManager::Update call periodically reviews this list and removes any sounds which have finished playing.

Definition at line 264 of file audio.h.

Referenced by Update().


The documentation for this class was generated from the following files:
Generated on Fri Jul 6 23:12:34 2007 for Hero of Allacrost by  doxygen 1.5.1