![]() |
V-Gears 0
Free Final Fantasy VII engine.
|
The audio manager. More...
#include <AudioManager.h>
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::Music * | GetMusic (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::Sound * | GetSound (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... | |
![]() | |
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::Music > | music_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::Sound > | sound_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 | |
![]() | |
enum | Module { FIELD = 0 , BATTLE = 1 , WORLD = 2 } |
The modules the entity manager can handle. More... | |
![]() | |
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... | |
![]() | |
Module | module_ |
The currently selected module. More... | |
Module | prev_module_ |
The previous module. More... | |
bool | paused_ |
Indicates if the game is paused. More... | |
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.
AudioManager::AudioManager | ( | ) |
Constructor.
|
virtual |
Destructor.
void AudioManager::AddMusic | ( | const AudioManager::Music & | music | ) |
Adds a music track to the audio manager.
[in] | music | The track to add. |
void AudioManager::AddSound | ( | const AudioManager::Sound & | sound | ) |
Adds a sound to the audio manager.
[in] | sound | The sound to add. |
void AudioManager::AddTrack | ( | const int | id, |
const int | track_id | ||
) |
Adds a music track ID to the list of music tracks of the field.
[in] | id | ID of the track in the map. |
[in] | track_id | Music track ID. |
|
private |
|
private |
|
overridevirtual |
Clears all battle information in the audio manager.
It clears the music track assigned for the battle.
Implements Manager.
|
overridevirtual |
Clears all field information in the audio manager.
It clears the music tracks assigned for the fields.
Implements Manager.
|
overridevirtual |
Clears all world map information in the audio manager.
It clears the tracks assigned for the world map.
Implements Manager.
AudioManager::Music * AudioManager::GetMusic | ( | const Ogre::String & | name | ) |
Retrieves a music track by name.
[in] | name | The track name. |
AudioManager::Sound * AudioManager::GetSound | ( | const Ogre::String & | name | ) |
Retrieves a sound by name.
[in] | name | The sound name. |
|
private |
Initializes the audio manager.
|
overridevirtual |
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 {
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.
[in] | name | Name of the track to play. |
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.
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.
|
overridevirtual |
Handles resizing events.
Implements Manager.
void AudioManager::operator() | ( | ) |
Used by boost libraries.
int AudioManager::ScriptGetBattleTrack | ( | ) |
Retrieves the music ID for the current or next battle.
int AudioManager::ScriptGetTrack | ( | int | id | ) |
Retrieves the music ID for the specified track for a field or world map.
[in] | id | ID of the track in the field or world map. |
void AudioManager::ScriptPlayMusic | ( | const char * | name | ) |
Plays a music track.
To be called from Lua scripts
[in] | name | Name of the track to play. |
void AudioManager::ScriptPlaySound | ( | const char * | name | ) |
Plays a sound.
To be called from Lua scripts
[in] | name | Name of the sound to play. |
void AudioManager::ScriptPlaySound | ( | const char * | name, |
const int | channel | ||
) |
Plays a sound in a channel.
To be called from Lua scripts
[in] | name | Name of the sound to play. |
[in] | channel | Channel to play the sound in (1-5). |
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.
[in] | name1 | Name of the first sound to play. |
[in] | name2 | Name of the second sound to play. |
[in] | name3 | Name of the third sound to play. |
[in] | name4 | Name of the fourth sound to play. |
void AudioManager::ScriptSetBattleTrack | ( | int | id | ) |
Sets the music track for upcoming battles.
Must be called before entering the battle mode.
[in] | id | ID of the track for the upcoming battles. |
void AudioManager::SoundPlay | ( | const Ogre::String & | name | ) |
Plays a sound.
[in] | name | Name of the sound to play. |
|
overrideprivatevirtual |
Updates the audio manager while on a battle.
Implements Manager.
|
overridevirtual |
Updates the audio manager with debug information.
Implements Manager.
|
overrideprivatevirtual |
Updates the audio manager while on the field.
Implements Manager.
|
overrideprivatevirtual |
Updates the audio manager while on the world map.
Implements Manager.
|
private |
Audio context.
|
private |
Audio output device.
|
private |
Music player for battles.
|
private |
ID of the track for the current battle.
|
private |
Audio buffer.
TODO: Unused? Not there are buffers per player. Remove.
|
staticprivate |
Number of buffers.
2 channels.
|
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.
|
private |
Sound effect player.
|
private |
Indicates if the audio manager has been initialized.
|
private |
Music player for either fields or world map.
|
private |
List of music.
|
private |
List of music.
|
private |
Flag to indicate if the playback must continue.
|
private |
IDs of the music tracks of the current content (field or world map).
|
private |
Mutex to handle concurrent operations.
|
private |
Thread to handle concurrent operations.