V-Gears 0
Free Final Fantasy VII engine.
AudioManager Class Reference

The audio manager. More...

#include <AudioManager.h>

Inheritance diagram for AudioManager:
Collaboration diagram for AudioManager:

Classes

struct  Music
 Music structure. More...
 
class  Player
 An audio player. More...
 
struct  Sound
 Music structure. More...
 

Public Member Functions

 AudioManager ()
 Constructor. More...
 
virtual ~AudioManager ()
 Destructor. More...
 
void operator() ()
 Used by boost libraries. More...
 
void Input (const VGears::Event &event) override
 Handles an input event. More...
 
void UpdateDebug () override
 Updates the audio manager with debug information. More...
 
void OnResize () override
 Handles resizing events. More...
 
void ClearField () override
 Clears all field information in the audio manager. More...
 
void ClearBattle () override
 Clears all battle information in the audio manager. More...
 
void ClearWorld () override
 Clears all world map information in the audio manager. More...
 
void MusicPause ()
 Pauses currently playing music. More...
 
void MusicResume ()
 resumes currently paused music. More...
 
void ScriptPlayMusic (const char *name)
 Plays a music track. More...
 
void MusicPlay (const Ogre::String &name)
 Plays a music track. More...
 
void ScriptPlaySound (const char *name)
 Plays a sound. More...
 
void ScriptPlaySound (const char *name, const int channel)
 Plays a sound in a channel. More...
 
void ScriptPlaySounds (const char *name1, const char *name2, const char *name3, const char *name4)
 Plays up to 4 sounds, in 4 different channels. More...
 
void SoundPlay (const Ogre::String &name)
 Plays a sound. More...
 
void MusicStop ()
 Stops the currently playing music. More...
 
void AddMusic (const AudioManager::Music &music)
 Adds a music track to the audio manager. More...
 
AudioManager::MusicGetMusic (const Ogre::String &name)
 Retrieves a music track by name. More...
 
void AddSound (const AudioManager::Sound &sound)
 Adds a sound to the audio manager. More...
 
AudioManager::SoundGetSound (const Ogre::String &name)
 Retrieves a sound by name. More...
 
void AddTrack (const int id, const int track_id)
 Adds a music track ID to the list of music tracks of the field. More...
 
int ScriptGetTrack (int id)
 Retrieves the music ID for the specified track for a field or world map. More...
 
int ScriptGetBattleTrack ()
 Retrieves the music ID for the current or next battle. More...
 
void ScriptSetBattleTrack (int id)
 Sets the music track for upcoming battles. More...
 
- Public Member Functions inherited from Manager
 Manager ()
 Constructor. More...
 
virtual ~Manager ()
 Destructor. More...
 
Module GetModule () const
 Retrieves the currently selected module. More...
 
bool IsModule (const Module module) const
 Checks the currently selected module. More...
 
bool IsFieldModule () const
 Checks if the currently selected module is the field module. More...
 
bool IsBattleModule () const
 Checks if the currently selected module is the battle module. More...
 
bool IsWorldModule () const
 Checks if the currently selected module is the world module. More...
 
void SetModule (const Module module)
 Sets the current module for the entity manager. More...
 
void SetFieldModule ()
 Sets the current module to the field mode. More...
 
void SetBattleModule ()
 Sets the current module to the battle mode. More...
 
void SetWorldModule ()
 Sets the current module to the world map mode. More...
 
void SetPreviousModule ()
 Sets the module that was loaded before a battle. More...
 
virtual void Input (const VGears::Event &event)=0
 Handles an input event. More...
 
void Update ()
 Called every frame, performs an update on the things controlled by the manager. More...
 
virtual void UpdateDebug ()=0
 Called every frame, performs an update on the things controlled by the manager. More...
 
virtual void OnResize ()=0
 Handles resizing events. More...
 
void Clear ()
 Clears the manager. More...
 
void Clear (const Module module)
 Clears the manager. More...
 
virtual void ClearField ()=0
 Clear all field information in the manager. More...
 
virtual void ClearBattle ()=0
 Clear all battle information in the manager. More...
 
virtual void ClearWorld ()=0
 Clear all world map information in the manager. More...
 
void ClearAll ()
 Clears the manager. More...
 
void ScriptSetPaused (const bool paused)
 Handles game pausing. More...
 

Private Member Functions

const bool Init ()
 Initializes the audio manager. More...
 
const char * ALError ()
 Handles errors. More...
 
const char * ALCError (const ALCdevice *device)
 Handles errors. More...
 
void UpdateField () override
 Updates the audio manager while on the field. More...
 
void UpdateBattle () override
 Updates the audio manager while on a battle. More...
 
void UpdateWorld () override
 Updates the audio manager while on the world map. More...
 

Private Attributes

bool initialized_
 Indicates if the audio manager has been initialized. More...
 
ALCdevice * al_device_
 Audio output device. More...
 
ALCcontext * al_context_
 Audio context. More...
 
char * buffer_
 Audio buffer. More...
 
boost::recursive_mutex update_mutex_
 Mutex to handle concurrent operations. More...
 
boost::thread * update_thread_
 Thread to handle concurrent operations. More...
 
bool thread_continue_
 Flag to indicate if the playback must continue. More...
 
AudioManager::Player music_
 Music player for either fields or world map. More...
 
AudioManager::Player battle_music_
 Music player for battles. More...
 
AudioManager::Player fx_
 Sound effect player. More...
 
std::list< AudioManager::Musicmusic_list_
 List of music. More...
 
std::unordered_map< unsigned int, unsigned int > tracks_
 IDs of the music tracks of the current content (field or world map). More...
 
int battle_track_
 ID of the track for the current battle. More...
 
std::list< AudioManager::Soundsound_list_
 List of music. More...
 

Static Private Attributes

static ALsizei channel_buffer_size_ = 96 * 1024
 Size of a channel buffer. More...
 
static int channel_buffer_number_ = 2
 Number of buffers. More...
 

Additional Inherited Members

- Public Types inherited from Manager
enum  Module { FIELD = 0 , BATTLE = 1 , WORLD = 2 }
 The modules the entity manager can handle. More...
 
- Protected Member Functions inherited from Manager
virtual void UpdateField ()=0
 Updates the field entities in the manager. More...
 
virtual void UpdateBattle ()=0
 Updates the battle entities in the manager. More...
 
virtual void UpdateWorld ()=0
 Updates the world map entities in the manager. More...
 
void Update (Module module)
 Updates the entities of one module in the manager. More...
 
- Protected Attributes inherited from Manager
Module module_
 The currently selected module. More...
 
Module prev_module_
 The previous module. More...
 
bool paused_
 Indicates if the game is paused. More...
 

Detailed Description

The audio manager.

It handles all music and sounds in the application. The manager has three players: one for battle music, another for music shared between fields and the world map, and a third one for sounds, that can be used anytime.

Constructor & Destructor Documentation

◆ AudioManager()

AudioManager::AudioManager ( )

Constructor.

◆ ~AudioManager()

AudioManager::~AudioManager ( )
virtual

Destructor.

Member Function Documentation

◆ AddMusic()

void AudioManager::AddMusic ( const AudioManager::Music music)

Adds a music track to the audio manager.

Parameters
[in]musicThe track to add.

◆ AddSound()

void AudioManager::AddSound ( const AudioManager::Sound sound)

Adds a sound to the audio manager.

Parameters
[in]soundThe sound to add.

◆ AddTrack()

void AudioManager::AddTrack ( const int  id,
const int  track_id 
)

Adds a music track ID to the list of music tracks of the field.

Parameters
[in]idID of the track in the map.
[in]track_idMusic track ID.

◆ ALCError()

const char * AudioManager::ALCError ( const ALCdevice *  device)
private

Handles errors.

Returns
nullptr
Todo:
Implement and get error info.

◆ ALError()

const char * AudioManager::ALError ( )
private

Handles errors.

Returns
nullptr
Todo:
Implement and get error info.

◆ ClearBattle()

void AudioManager::ClearBattle ( )
overridevirtual

Clears all battle information in the audio manager.

It clears the music track assigned for the battle.

Implements Manager.

◆ ClearField()

void AudioManager::ClearField ( )
overridevirtual

Clears all field information in the audio manager.

It clears the music tracks assigned for the fields.

Implements Manager.

◆ ClearWorld()

void AudioManager::ClearWorld ( )
overridevirtual

Clears all world map information in the audio manager.

It clears the tracks assigned for the world map.

Implements Manager.

◆ GetMusic()

AudioManager::Music * AudioManager::GetMusic ( const Ogre::String &  name)

Retrieves a music track by name.

Parameters
[in]nameThe track name.
Returns
The music track, or nullptr if there is no track by that name.

◆ GetSound()

AudioManager::Sound * AudioManager::GetSound ( const Ogre::String &  name)

Retrieves a sound by name.

Parameters
[in]nameThe sound name.
Returns
The sound track, or nullptr if there is no sound by that name.

◆ Init()

const bool AudioManager::Init ( )
private

Initializes the audio manager.

Todo:
Verify this comment.

◆ Input()

void AudioManager::Input ( const VGears::Event event)
overridevirtual

Handles an input event.

Parameters
[in]eventEvent to handle.

Implements Manager.

◆ MusicPause()

void AudioManager::MusicPause ( )

Pauses currently playing music.

If the manager is in battle mode, the battle music player will be paused. If not, the field or world map player will be paused. Playback can be resumed by calling {

See also
MusicResume}.

◆ MusicPlay()

void AudioManager::MusicPlay ( const Ogre::String &  name)

Plays a music track.

If the manager is in battle mode, the field or world map player will be paused, and the battle player will play. If not, the battle music player will stop and the field or world map will start playing. If there is no music by the specified name, an error will be printed and nothing will be done.

Parameters
[in]nameName of the track to play.

◆ MusicResume()

void AudioManager::MusicResume ( )

resumes currently paused music.

If the manager is in battle mode, the battle music player will be resumed. If not, the field or world map player will be resumed.

◆ MusicStop()

void AudioManager::MusicStop ( )

Stops the currently playing music.

Playback can't be resumed. If the battle mode is active, the battle music player will be the one stoped. If not, the field/world map player will be the one stopping.

◆ OnResize()

void AudioManager::OnResize ( )
overridevirtual

Handles resizing events.

Implements Manager.

◆ operator()()

void AudioManager::operator() ( )

Used by boost libraries.

◆ ScriptGetBattleTrack()

int AudioManager::ScriptGetBattleTrack ( )

Retrieves the music ID for the current or next battle.

Returns
The music track ID for the current or upcoming battles.

◆ ScriptGetTrack()

int AudioManager::ScriptGetTrack ( int  id)

Retrieves the music ID for the specified track for a field or world map.

Parameters
[in]idID of the track in the field or world map.
Returns
The music track ID, or -1 if it doesn't exist.

◆ ScriptPlayMusic()

void AudioManager::ScriptPlayMusic ( const char *  name)

Plays a music track.

To be called from Lua scripts

Parameters
[in]nameName of the track to play.

◆ ScriptPlaySound() [1/2]

void AudioManager::ScriptPlaySound ( const char *  name)

Plays a sound.

To be called from Lua scripts

Parameters
[in]nameName of the sound to play.

◆ ScriptPlaySound() [2/2]

void AudioManager::ScriptPlaySound ( const char *  name,
const int  channel 
)

Plays a sound in a channel.

To be called from Lua scripts

Parameters
[in]nameName of the sound to play.
[in]channelChannel to play the sound in (1-5).

◆ ScriptPlaySounds()

void AudioManager::ScriptPlaySounds ( const char *  name1,
const char *  name2,
const char *  name3,
const char *  name4 
)

Plays up to 4 sounds, in 4 different channels.

To be called from Lua scripts.

Parameters
[in]name1Name of the first sound to play.
[in]name2Name of the second sound to play.
[in]name3Name of the third sound to play.
[in]name4Name of the fourth sound to play.

◆ ScriptSetBattleTrack()

void AudioManager::ScriptSetBattleTrack ( int  id)

Sets the music track for upcoming battles.

Must be called before entering the battle mode.

Parameters
[in]idID of the track for the upcoming battles.

◆ SoundPlay()

void AudioManager::SoundPlay ( const Ogre::String &  name)

Plays a sound.

Parameters
[in]nameName of the sound to play.

◆ UpdateBattle()

void AudioManager::UpdateBattle ( )
overrideprivatevirtual

Updates the audio manager while on a battle.

Implements Manager.

◆ UpdateDebug()

void AudioManager::UpdateDebug ( )
overridevirtual

Updates the audio manager with debug information.

Implements Manager.

◆ UpdateField()

void AudioManager::UpdateField ( )
overrideprivatevirtual

Updates the audio manager while on the field.

Implements Manager.

◆ UpdateWorld()

void AudioManager::UpdateWorld ( )
overrideprivatevirtual

Updates the audio manager while on the world map.

Implements Manager.

Member Data Documentation

◆ al_context_

ALCcontext* AudioManager::al_context_
private

Audio context.

◆ al_device_

ALCdevice* AudioManager::al_device_
private

Audio output device.

◆ battle_music_

AudioManager::Player AudioManager::battle_music_
private

Music player for battles.

◆ battle_track_

int AudioManager::battle_track_
private

ID of the track for the current battle.

◆ buffer_

char* AudioManager::buffer_
private

Audio buffer.

TODO: Unused? Not there are buffers per player. Remove.

◆ channel_buffer_number_

ALsizei AudioManager::channel_buffer_number_ = 2
staticprivate

Number of buffers.

2 channels.

◆ channel_buffer_size_

int AudioManager::channel_buffer_size_ = 96 * 1024
staticprivate

Size of a channel buffer.

96Kb are allocated for each channel. ~0.5 seconds of 44100Hz stereo 16-bit data can be allocated in each channel. This way, 250ms can pass between buffer updates.

◆ fx_

AudioManager::Player AudioManager::fx_
private

Sound effect player.

◆ initialized_

bool AudioManager::initialized_
private

Indicates if the audio manager has been initialized.

◆ music_

AudioManager::Player AudioManager::music_
private

Music player for either fields or world map.

◆ music_list_

std::list<AudioManager::Music> AudioManager::music_list_
private

List of music.

◆ sound_list_

std::list<AudioManager::Sound> AudioManager::sound_list_
private

List of music.

◆ thread_continue_

bool AudioManager::thread_continue_
private

Flag to indicate if the playback must continue.

◆ tracks_

std::unordered_map<unsigned int, unsigned int> AudioManager::tracks_
private

IDs of the music tracks of the current content (field or world map).

◆ update_mutex_

boost::recursive_mutex AudioManager::update_mutex_
private

Mutex to handle concurrent operations.

◆ update_thread_

boost::thread* AudioManager::update_thread_
private

Thread to handle concurrent operations.


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