Main Page | Namespace List | Class List | Directories | File List | Namespace Members | Class Members | File Members

osgAL::SoundManager Class Reference

A SoundManager handles the sound system. More...

List of all members.

Public Member Functions

virtual void shutdown ()
bool initialized ()
 Return a pointer to the singleton object Returns true if the SoundManager is initalized.
bool pushSoundEvent (SoundState *state, unsigned int priority=0)
openalpp::Sample * SoundManager::getSample (const std::string &path, bool add_to_cache=true)
void SoundManager::clearSampleCache (void)
openalpp::Stream * SoundManager::getStream (const std::string &path, bool add_to_cache=true)
void SoundManager::clearStreamCache (void)
SoundStatefindSoundState (const std::string &id)
void releaseSource (openalpp::Source *source)
void init (unsigned int num_soundsources, float sound_velocity=343)
 Initializes the SoundManager.
void update ()
openalpp::Listener * getListener ()
 Return a pointer to the listener.
openalpp::AudioEnvironment * getEnvironment ()
 Return a pointer to the Sound environment.
void addSoundState (osgAL::SoundState *state)
bool removeSoundState (const std::string &id)
 Removes the sound state from the list of existing soundstates.
bool removeSoundState (osgAL::SoundState *state)
void setListenerDirection (const osg::Vec3 &dir)
const osg::Vec3 & getListenerDirection () const
void setListenerMatrix (const osg::Matrix &matrix)
 Set the transformation matrix for the listener.
const osg::Matrix & getListenerMatrix () const
 Return the current listener matrix.
openalpp::Source * allocateSource (unsigned int priority, bool mutual_use=true)
void setMaxVelocity (float vel)
 Set the maximum velocity used in doppler calculation.
float getMaxVelocity () const
 Returns the maximum velocity used in doppler calculation.
void setFilePathEnvironmentVariable (const std::string &env)
void addFilePath (const std::string &path)
unsigned int getNumAvailableSources ()
unsigned int getNumSources ()
unsigned int getNumActiveSources ()

Static Public Member Functions

SoundManagerinstance (void)
 Return the singleton object.


Detailed Description

A SoundManager handles the sound system.

This class initialises the Sound system. It also keeps track of loaded sound samples. It is based on the Singleton Design pattern. To manage a limited resource of Sound sources (which is usually around 32) a schema has to be set up.

This class initially initializes sound sources and places them into a pool of available sources. Whenever someone calls allocateSource() the sound manager tries to free a source and return a pointer to it. If there are no sources available it goes through the active sources and tries to find one with a lower priority. If it still fails, an exception is thrown. Otherwise the found source is returned.

The allocateSource() has an argument indicating that if the source should be placed in the list of active sources. If this argument is false, the caller is responsible to call releaseSource() when finished using the source.

SoundManager also handles SoundStates. Whenever pushSoundEvent() is called, a FlyWeight set of SoundStates is inquired for a free SoundState. The argument of pushSoundEvent() is copied to the free SoundState and that SoundState is then pushed to the queue of waiting SoundStates.

When SoundManager::update() is called, the queue of waiting SoundStates is inquired and for each SoundState a Source is allocated. When the SoundManager realizes that a SoundState is not playing anymore, it is removed from the list of active SoundStates and put back in to the FlyWeight set of available SoundStates.


Member Function Documentation

void osgAL::SoundManager::addFilePath const std::string &  path  )  [inline]
 

void osgAL::SoundManager::addSoundState osgAL::SoundState state  )  [inline]
 

Add a SoundState to the list of existing sound states

openalpp::Source* osgAL::SoundManager::allocateSource unsigned int  priority,
bool  mutual_use = true
[inline]
 

Tries to find an available sound Source

Parameters:
if mutual_use then the source is registrated in the soundmanager as a source that can be reused by a call to getSource with higher priority. If on the other hand mutual_use is false, then it is allocated
Returns:
Pointer to an available sound Source

SoundState* osgAL::SoundManager::findSoundState const std::string &  id  ) 
 

Return a pointer to the SoundState with the name id.

Returns:
Null if no matching SoundState can be found.

openalpp::AudioEnvironment * osgAL::SoundManager::getEnvironment  )  [inline]
 

Return a pointer to the Sound environment.

openalpp::Listener * osgAL::SoundManager::getListener  )  [inline]
 

Return a pointer to the listener.

const osg::Vec3& osgAL::SoundManager::getListenerDirection  )  const [inline]
 

const osg::Matrix& osgAL::SoundManager::getListenerMatrix  )  const [inline]
 

Return the current listener matrix.

float osgAL::SoundManager::getMaxVelocity  )  const [inline]
 

Returns the maximum velocity used in doppler calculation.

unsigned int osgAL::SoundManager::getNumActiveSources  )  [inline]
 

Returns the number of SoundSources currently in use. Should be between 0..getNumSources()

unsigned int osgAL::SoundManager::getNumAvailableSources  )  [inline]
 

Returns the number of free and available SoundSoures for allocation. Should be between 0 .. getNumSources()

unsigned int osgAL::SoundManager::getNumSources  )  [inline]
 

Returns the number of initialized SoundSources. Should be between 0..

void osgAL::SoundManager::init unsigned int  num_soundsources,
float  sound_velocity = 343
 

Initializes the SoundManager.

bool osgAL::SoundManager::initialized  )  [inline]
 

Return a pointer to the singleton object Returns true if the SoundManager is initalized.

SoundManager* osgAL::SoundManager::instance void   )  [static]
 

Return the singleton object.

bool osgAL::SoundManager::pushSoundEvent SoundState state,
unsigned int  priority = 0
 

Push a SoundState to the queue of waiting SoundStates When the update method later on is called, this queue is inquired and each waiting SoundEvent will be put in the active state and put to a list of active SoundStates with a Source allocated.

Parameters:
state - The state that will be pushed to the waiting queue
priority - The priority of the state, 0 lowest

void osgAL::SoundManager::releaseSource openalpp::Source *  source  ) 
 

Puts the source into the list of available sound sources

bool osgAL::SoundManager::removeSoundState osgAL::SoundState state  ) 
 

Removes the sound state from the list of existing soundstates

bool osgAL::SoundManager::removeSoundState const std::string &  id  ) 
 

Removes the sound state from the list of existing soundstates.

void osgAL::SoundManager::setFilePathEnvironmentVariable const std::string &  env  ) 
 

void osgAL::SoundManager::setListenerDirection const osg::Vec3 &  dir  ) 
 

To make it possible to flip left and right ear for the listner this vector specified will be multiplied with the up vector everytime the orientation of the listener is calculated The default value is (1, 1, 1). Make sure not to set anyone to zero, this will be caught and an exception will be thrown.

void osgAL::SoundManager::setListenerMatrix const osg::Matrix &  matrix  ) 
 

Set the transformation matrix for the listener.

void osgAL::SoundManager::setMaxVelocity float  vel  )  [inline]
 

Set the maximum velocity used in doppler calculation.

virtual void osgAL::SoundManager::shutdown  )  [virtual]
 

Deallocates any allocated memory, this method have to be called prior to the end of main() OpenAL doesnt like destruction of sources outside the main() function.

void osgAL::SoundManager::SoundManager::clearSampleCache void   )  [inline]
 

Clear the sample cache with all loaded samples.

void osgAL::SoundManager::SoundManager::clearStreamCache void   )  [inline]
 

Clear the Stream cache with all loaded streams.

openalpp::Sample* osgAL::SoundManager::SoundManager::getSample const std::string &  path,
bool  add_to_cache = true
 

Return a pointer to a Sample. Each Sample will be stored in a cache with its associated path (if add_to_cache is true) Each call to getSample will first look in the cache and try to find the path there. If it can be found, it will return to that Sample. Otherwise it will be loaded from disk.

openalpp::Stream* osgAL::SoundManager::SoundManager::getStream const std::string &  path,
bool  add_to_cache = true
 

Return a pointer to a Stream Each Stream will be stored in a cache with its associated path. Each call to getStream will first look in the cache and try to find the path there. If it can be found, it will return to that Stream. Otherwise it will be loaded from disk.

void osgAL::SoundManager::update  ) 
 


The documentation for this class was generated from the following file:
Generated on Fri Dec 10 08:46:05 2004 for osgAL by  doxygen 1.3.9.1