TurtleBrains  0.2.1
High quality, portable, C++ API for native application and game development.
TurtleBrains::Audio::AudioManager Class Reference

#include <tb_audio_manager.h>

Inheritance diagram for TurtleBrains::Audio::AudioManager:
TurtleBrains::Core::Noncopyable

Public Member Functions

 AudioManager (void)
 
 ~AudioManager (void)
 
bool LoadEventTable (const tbCore::tbString &eventTableName, const tbCore::tbString &eventTableFile)
 
AudioHandle CreateSoundFromFile (const tbCore::tbString &filename)
 
void DestroySound (const AudioHandle &audioHandle)
 
AudioController PlayEvent (const tbCore::tbString &eventTableName, const tbCore::tbString &eventName)
 
AudioController PlaySound (const AudioHandle &audioHandle, const bool isLooping=false)
 
void Update (void)
 

Detailed Description

The AudioManager is the interface for loading and playing sound effects. Like the SpriteManager the AudioManager is a global singleton like object accessed with tbAudio::theAudioManager. It can create a table of audio events that can then be played with PlayEvent().

Constructor & Destructor Documentation

TurtleBrains::Audio::AudioManager::AudioManager ( void  )

The AudioManager should be treated like a singleton object and should only ever be accessed through the tbAudio::theAudioManager 'global' variable.

TurtleBrains::Audio::AudioManager::~AudioManager ( void  )

The AudioManager should be treated like a singleton object and should only ever be accessed through the tbAudio::theAudioManager 'global' variable.

Member Function Documentation

AudioHandle TurtleBrains::Audio::AudioManager::CreateSoundFromFile ( const tbCore::tbString filename)

Consider this an implementation detail, it will indeed load a sound from the file provided, however it may become an implementation detail and be stripped away from the AudioManager interface.

Note
Use at your own risk, this may be pulled out of the AudioManager to be replaced by LoadEventTable().
void TurtleBrains::Audio::AudioManager::DestroySound ( const AudioHandle audioHandle)

Consider this an implementation detail, it will indeed destroy a sound previously created, however it will do so even if it is being played, or shouldn't. Also this may become an implementation detail and be stripped away from the AudioManager interface.

Note
Use at your own risk, this may be pulled out of the AudioManager to be replaced by LoadEventTable().
bool TurtleBrains::Audio::AudioManager::LoadEventTable ( const tbCore::tbString eventTableName,
const tbCore::tbString eventTableFile 
)

Loads a table of audio events and the audio data files required for playback. Once loaded an audio event can be played by calling PlayEvent(). If the tablefile or any audio files could not be loaded an error condition will be triggered.

Note
currently an event table cannot be unloaded until shutdown.

Ex. EventTable:

{ "audio_events" : [ { "name" : "event_name1", "file" : "data/sound.wav", "looping" : false }, { "name" : "event_name2", "file" : "data/sound.wav", "pitch" : 1.0, "volume" : 1.0 }, { "name" : "event_name3", "file" : [ "data/sound.wav, "data/sound2.wav" ... ] }, { "name" : "event_name3", "file" : [ { "file" : "data/sound.wav, "pitch" : 1.0, "volume" : 1.0 }, { "file" : "data/sound2.wav", "min_pitch" : 0.8, "max_pitch" : 1.2, "min_volume" : 0.5, "max_volume" : 0.6 } ... ] }, ] }

The json data does not need to contain the optional parameters shown below with their default values. looping(false), pitch(1.0), volume(1.0), min_pitch(1.0), max_pitch(1.0), min_volume(1.0), max_volume(1.0)

AudioController TurtleBrains::Audio::AudioManager::PlayEvent ( const tbCore::tbString eventTableName,
const tbCore::tbString eventName 
)

Triggers an audio event to begin playing in the background, an audio event can have multiple sound files to randomly choose from. The audio event must have been loaded by LoadEventTable prior to being the call or an error condition will be triggered.

Note
Currently this is still under development and not completely set in stone, the eventTableName and eventName may be swapped to provide an overload that searches all tables for eventName.
AudioController TurtleBrains::Audio::AudioManager::PlaySound ( const AudioHandle audioHandle,
const bool  isLooping = false 
)

Consider this an implementation detail, it will indeed play a sound by an AudioHandle loaded from CreateSoundFromFile, however it may be pulled out of the AudioManager interface in favor of PlayEvent().

Note
Use at your own risk, this may be pulled out of the AudioManager in favor for only playing by event or other means. It is provided for quickly testing and developing the AudioManager api.
void TurtleBrains::Audio::AudioManager::Update ( void  )

Consider this an implementation detail, it will indeed load a sound from file and play it however it may be pulled out of the AudioManager interface in favor of PlayEvent().

Note
Use at your own risk, this may be pulled out of the AudioManager in favor for only playing by event or other means. It is provided for quickly testing and developing the AudioManager api.

This must be called once per frame, every frame, to keep the sounds playing, it is likely already called by the GameScene::PerformFrame, however if for some reason that is not being used, call manually.