Annwvyn::AnnAudioEngine Class Reference

Class that handle the OpenAL audio. More...

#include <AnnAudioEngine.hpp>

Inheritance diagram for Annwvyn::AnnAudioEngine:
Collaboration diagram for Annwvyn::AnnAudioEngine:

Public Member Functions

 AnnAudioEngine ()
 class constructor More...
 
 ~AnnAudioEngine ()
 class destructor More...
 
bool initOpenAL ()
 init OpenAL More...
 
void shutdownOpenAL ()
 shutdown and cleanup OpenAL More...
 
ALuint loadBuffer (const std::string &filename)
 
void preLoadBuffer (const std::string &filename)
 
More...
 
ALuint isBufferLoader (const std::string &filename)
 Return "false" if buffer not loaded. Return buffer index if buffer is loaded. More...
 
void unloadBuffer (const std::string &filename)
 
void playBGM (const std::string &filename, float volume=0.5f)
 
void stopBGM () const
 stop the current background music from playing More...
 
std::string getLastError () const
 Get the last error message that occurred in-engine. More...
 
AnnAudioSourcePtr createSource ()
 Create an audio source. More...
 
AnnAudioSourcePtr createSource (std::string name)
 Create an audio source and attach (and load if necessary) buffer from audio file. More...
 
void removeSource (AnnAudioSourcePtr source)
 Remove an audio source frop the engine. More...
 
void logError () const
 Write last error text to the log. More...
 
- Public Member Functions inherited from Annwvyn::AnnSubSystem
 AnnSubSystem (const std::string &systemName)
 Construct a SubSystem. More...
 
virtual ~AnnSubSystem ()
 Destruct a SubSystem. More...
 

Private Member Functions

void updateListenerPos (AnnVect3 pos)
 
void update () override
 Update the subsystem : set the listener position. More...
 
void detectPlaybackDevices (const char *list)
 Detect playback devices from the device enumeration string. More...
 

Static Private Member Functions

static void updateListenerOrient (AnnQuaternion orient)
 

Private Attributes

std::string lastError
 The last error this class has generated. More...
 
ALCdevice * alDevice
 AL alDevice. More...
 
ALCcontext * alContext
 AL Context. More...
 
ALuint bgmBuffer
 Audio buffer for background music. More...
 
ALuint bgmSource
 Audio source for background music. More...
 
std::unordered_map< std::string, ALuint > buffers
 Map between audio filenames and OpenAL buffer. More...
 
bool locked
 Prevent some operation if set to true. More...
 
std::list< AnnAudioSourcePtraudioSources
 List of the audio sources object present in the audio engine. More...
 
std::vector< std::stringdetectedDevices
 List of audio device names. More...
 
AnnAudioFileManageraudioFileManager
 Custom Ogre resource manager that loads binary files used to load audio files. More...
 

Friends

class AnnEngine
 For engine : update listener Orientation. More...
 

Additional Inherited Members

- Protected Member Functions inherited from Annwvyn::AnnSubSystem
virtual bool needUpdate ()
 To be called by AnnEngine : Return if the subsystem wants to be updated. More...
 
- Protected Attributes inherited from Annwvyn::AnnSubSystem
std::string name
 Name of the subsystem. More...
 

Detailed Description

Class that handle the OpenAL audio.

Definition at line 82 of file AnnAudioEngine.hpp.

Constructor & Destructor Documentation

◆ AnnAudioEngine()

AnnAudioEngine::AnnAudioEngine ( )

class constructor

Definition at line 11 of file AnnAudioEngine.cpp.

Here is the call graph for this function:

◆ ~AnnAudioEngine()

AnnAudioEngine::~AnnAudioEngine ( )

class destructor

Definition at line 48 of file AnnAudioEngine.cpp.

Here is the call graph for this function:

Member Function Documentation

◆ createSource() [1/2]

std::shared_ptr< AnnAudioSource > AnnAudioEngine::createSource ( )

Create an audio source.

Definition at line 371 of file AnnAudioEngine.cpp.

Here is the caller graph for this function:

◆ createSource() [2/2]

std::shared_ptr< AnnAudioSource > AnnAudioEngine::createSource ( std::string  name)

Create an audio source and attach (and load if necessary) buffer from audio file.

Definition at line 359 of file AnnAudioEngine.cpp.

Here is the call graph for this function:

◆ detectPlaybackDevices()

void AnnAudioEngine::detectPlaybackDevices ( const char *  list)
private

Detect playback devices from the device enumeration string.

Definition at line 56 of file AnnAudioEngine.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getLastError()

std::string AnnAudioEngine::getLastError ( ) const

Get the last error message that occurred in-engine.

Definition at line 354 of file AnnAudioEngine.cpp.

◆ initOpenAL()

bool AnnAudioEngine::initOpenAL ( )

init OpenAL

Definition at line 78 of file AnnAudioEngine.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isBufferLoader()

ALuint AnnAudioEngine::isBufferLoader ( const std::string filename)

Return "false" if buffer not loaded. Return buffer index if buffer is loaded.

Definition at line 175 of file AnnAudioEngine.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ loadBuffer()

ALuint AnnAudioEngine::loadBuffer ( const std::string filename)

Load a sound file. return a sound buffer. Add the buffer to the buffer list. This permit to pre-load sound files to the engine. If want to avoid loading a Bunch of sound file (that causes disk I/O access) you can just load the sound file before the start of your gameplay sequence.

Parameters
filenameName of the file you want to load

Definition at line 183 of file AnnAudioEngine.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ logError()

void AnnAudioEngine::logError ( ) const

Write last error text to the log.

Definition at line 43 of file AnnAudioEngine.cpp.

Here is the caller graph for this function:

◆ playBGM()

void AnnAudioEngine::playBGM ( const std::string filename,
float  volume = 0.5f 
)

play background music. you can specify the volume of the music (0.0f to 1.0f)

Parameters
filenamename of the audio file to use as background music
volumeFloat number between 0 and 1, Loudness of the sound. At 0.5f by default

Definition at line 303 of file AnnAudioEngine.cpp.

Here is the call graph for this function:

◆ preLoadBuffer()

void AnnAudioEngine::preLoadBuffer ( const std::string filename)


This method is intended to be used in moments like loading levels If a buffer is already loaded, getting it with loadBuffer is equivalent at getting something from an unordered map. If loadBuffer is called with a "new" sound file, the engine will load it in memory before doing anything else, delaying stuff because of disk I/O Load a sound file. return a sound buffer. Add the buffer to the buffer list. This permit to pre-load sound files to the engine. If want to avoid loading a Bunch of sound file (that causes disk I/O access) you can just load the sound file before the start of your gameplay sequence.

Parameters
filenameName of the file you want to load

Definition at line 170 of file AnnAudioEngine.cpp.

Here is the call graph for this function:

◆ removeSource()

void AnnAudioEngine::removeSource ( AnnAudioSourcePtr  source)

Remove an audio source frop the engine.

Definition at line 366 of file AnnAudioEngine.cpp.

◆ shutdownOpenAL()

void AnnAudioEngine::shutdownOpenAL ( )

shutdown and cleanup OpenAL

Definition at line 144 of file AnnAudioEngine.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ stopBGM()

void AnnAudioEngine::stopBGM ( ) const

stop the current background music from playing

Definition at line 319 of file AnnAudioEngine.cpp.

◆ unloadBuffer()

void AnnAudioEngine::unloadBuffer ( const std::string filename)

Unload a buffer from the engine. The buffer is identified by the sound file it represent

Parameters
filenamePath of the file you want to load

Definition at line 279 of file AnnAudioEngine.cpp.

Here is the call graph for this function:

◆ update()

void AnnAudioEngine::update ( )
overrideprivatevirtual

Update the subsystem : set the listener position.

Reimplemented from Annwvyn::AnnSubSystem.

Definition at line 347 of file AnnAudioEngine.cpp.

Here is the call graph for this function:

◆ updateListenerOrient()

void AnnAudioEngine::updateListenerOrient ( AnnQuaternion  orient)
staticprivate

For the engine : update the listener orientation to match the player's head

Parameters
orientThe orientation of the player

Definition at line 337 of file AnnAudioEngine.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ updateListenerPos()

void AnnAudioEngine::updateListenerPos ( AnnVect3  pos)
private

For the engine: update the listener position to match the player's head

Parameters
posThe position of the player

Definition at line 325 of file AnnAudioEngine.cpp.

Here is the caller graph for this function:

Friends And Related Function Documentation

◆ AnnEngine

friend class AnnEngine
friend

For engine : update listener Orientation.

Definition at line 152 of file AnnAudioEngine.hpp.

Member Data Documentation

◆ alContext

ALCcontext* Annwvyn::AnnAudioEngine::alContext
private

AL Context.

Definition at line 165 of file AnnAudioEngine.hpp.

◆ alDevice

ALCdevice* Annwvyn::AnnAudioEngine::alDevice
private

AL alDevice.

Definition at line 163 of file AnnAudioEngine.hpp.

◆ audioFileManager

AnnAudioFileManager* Annwvyn::AnnAudioEngine::audioFileManager
private

Custom Ogre resource manager that loads binary files used to load audio files.

Definition at line 183 of file AnnAudioEngine.hpp.

◆ audioSources

std::list<AnnAudioSourcePtr> Annwvyn::AnnAudioEngine::audioSources
private

List of the audio sources object present in the audio engine.

Definition at line 178 of file AnnAudioEngine.hpp.

◆ bgmBuffer

ALuint Annwvyn::AnnAudioEngine::bgmBuffer
private

Audio buffer for background music.

Definition at line 168 of file AnnAudioEngine.hpp.

◆ bgmSource

ALuint Annwvyn::AnnAudioEngine::bgmSource
private

Audio source for background music.

Definition at line 170 of file AnnAudioEngine.hpp.

◆ buffers

std::unordered_map<std::string, ALuint> Annwvyn::AnnAudioEngine::buffers
private

Map between audio filenames and OpenAL buffer.

Definition at line 173 of file AnnAudioEngine.hpp.

◆ detectedDevices

std::vector<std::string> Annwvyn::AnnAudioEngine::detectedDevices
private

List of audio device names.

Definition at line 181 of file AnnAudioEngine.hpp.

◆ lastError

std::string Annwvyn::AnnAudioEngine::lastError
private

The last error this class has generated.

Definition at line 161 of file AnnAudioEngine.hpp.

◆ locked

bool Annwvyn::AnnAudioEngine::locked
private

Prevent some operation if set to true.

Definition at line 176 of file AnnAudioEngine.hpp.


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