Main Page   Namespace List   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

osgAL::SoundManager Class Reference

A SoundManager handles the sound system. More...

Collaboration diagram for osgAL::SoundManager:

Collaboration graph
[legend]
List of all members.

Public Methods

virtual void shutdown ()
bool initialized ()
 Return a pointer to the singleton object Returns true if the SoundManager is initalized. More...

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. More...

void update ()
openalpp::Listener * getListener ()
 Return a pointer to the listener. More...

openalpp::AudioEnvironment * getEnvironment ()
 Return a pointer to the Sound environment. More...

void addSoundState (osgAL::SoundState *state)
bool removeSoundState (const std::string &id)
 Removes the sound state from the list of existing soundstates. More...

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. More...

const osg::Matrix & getListenerMatrix () const
 Return the current listener matrix. More...

openalpp::Source * allocateSource (unsigned int priority, bool mutual_use=true)
void setMaxVelocity (float vel)
 Set the maximum velocity used in doppler calculation. More...

float getMaxVelocity () const
 Returns the maximum velocity used in doppler calculation. More...

void setFilePathEnvironmentVariable (const std::string &env)
void addFilePath (const std::string &path)
unsigned int getNumAvailableSources ()
unsigned int getNumSources ()
unsigned int getNumActiveSources ()

Static Public Methods

SoundManager * instance (void)
 Return the singleton object. More...


Private Types

typedef std::map< std::string,
openalpp::ref_ptr< openalpp::Sample > > 
SampleMap
typedef SampleMap::iterator SampleMapIterator
typedef SampleMap::value_type SampleMapValType
typedef std::map< std::string,
openalpp::ref_ptr< openalpp::FileStream > > 
StreamMap
typedef StreamMap::iterator StreamMapIterator
typedef StreamMap::value_type StreamMapValType
typedef std::vector< openalpp::ref_ptr<
openalpp::Source > > 
SourceVector
typedef std::vector< std::pair<
unsigned int, openalpp::ref_ptr<
openalpp::Source > > > 
ActiveSourceVector
typedef std::map< std::string,
osg::ref_ptr< SoundState > > 
SoundStateMap
typedef std::priority_queue<
SoundStateQueueItem
SoundStateQueue
typedef std::vector< osg::ref_ptr<
SoundState > > 
SoundStateVector

Private Methods

openalpp::Source * getSource (unsigned int priority, bool registrate_as_active=true, int depth=0)
 ~SoundManager ()
 Destructor. More...

 SoundManager (void)
 Default Constructor. More...

void resetSource (openalpp::Source *source)

Private Attributes

osg::ref_ptr< SoundStateFlyWeightm_sound_state_FlyWeight
SampleMap m_sample_cache
StreamMap m_stream_cache
openalpp::ref_ptr< openalpp::Listener > m_listener
openalpp::ref_ptr< openalpp::AudioEnvironment > m_sound_environment
ActiveSourceVector m_active_soundsources
SourceVector m_soundsources
osg::Matrix m_listener_matrix
SourceVector m_available_soundsources
SoundStateMap m_sound_states
SoundStateQueue m_sound_state_queue
SoundStateVector m_active_sound_states
bool m_initialized
osg::Vec3 m_last_pos
float m_max_velocity
osg::Timer m_timer
osg::Timer_t m_last_tick
bool m_first_run
FilePathContainer m_filepathcontainer
osg::Vec3 m_listener_direction

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 Typedef Documentation

typedef std::vector<std::pair< unsigned int, openalpp::ref_ptr<openalpp::Source> > > osgAL::SoundManager::ActiveSourceVector [private]
 

typedef std::map<std::string, openalpp::ref_ptr<openalpp::Sample> > osgAL::SoundManager::SampleMap [private]
 

typedef SampleMap::iterator osgAL::SoundManager::SampleMapIterator [private]
 

typedef SampleMap::value_type osgAL::SoundManager::SampleMapValType [private]
 

typedef std::map<std::string, osg::ref_ptr<SoundState> > osgAL::SoundManager::SoundStateMap [private]
 

typedef std::priority_queue<SoundStateQueueItem> osgAL::SoundManager::SoundStateQueue [private]
 

typedef std::vector<osg::ref_ptr<SoundState> > osgAL::SoundManager::SoundStateVector [private]
 

typedef std::vector<openalpp::ref_ptr<openalpp::Source> > osgAL::SoundManager::SourceVector [private]
 

typedef std::map<std::string, openalpp::ref_ptr<openalpp::FileStream> > osgAL::SoundManager::StreamMap [private]
 

typedef StreamMap::iterator osgAL::SoundManager::StreamMapIterator [private]
 

typedef StreamMap::value_type osgAL::SoundManager::StreamMapValType [private]
 


Constructor & Destructor Documentation

osgAL::SoundManager::~SoundManager   [private]
 

Destructor.

osgAL::SoundManager::SoundManager void    [private]
 

Default Constructor.


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..

openalpp::Source* osgAL::SoundManager::getSource unsigned int    priority,
bool    registrate_as_active = true,
int    depth = 0
[private]
 

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::resetSource openalpp::Source *    source [private]
 

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  
 


Member Data Documentation

SoundStateVector osgAL::SoundManager::m_active_sound_states [private]
 

ActiveSourceVector osgAL::SoundManager::m_active_soundsources [private]
 

SourceVector osgAL::SoundManager::m_available_soundsources [private]
 

FilePathContainer osgAL::SoundManager::m_filepathcontainer [private]
 

bool osgAL::SoundManager::m_first_run [private]
 

bool osgAL::SoundManager::m_initialized [private]
 

osg::Vec3 osgAL::SoundManager::m_last_pos [private]
 

osg::Timer_t osgAL::SoundManager::m_last_tick [private]
 

openalpp::ref_ptr<openalpp::Listener> osgAL::SoundManager::m_listener [private]
 

osg::Vec3 osgAL::SoundManager::m_listener_direction [private]
 

osg::Matrix osgAL::SoundManager::m_listener_matrix [private]
 

float osgAL::SoundManager::m_max_velocity [private]
 

SampleMap osgAL::SoundManager::m_sample_cache [private]
 

openalpp::ref_ptr<openalpp::AudioEnvironment> osgAL::SoundManager::m_sound_environment [private]
 

osg::ref_ptr<SoundStateFlyWeight> osgAL::SoundManager::m_sound_state_FlyWeight [private]
 

SoundStateQueue osgAL::SoundManager::m_sound_state_queue [private]
 

SoundStateMap osgAL::SoundManager::m_sound_states [private]
 

SourceVector osgAL::SoundManager::m_soundsources [private]
 

StreamMap osgAL::SoundManager::m_stream_cache [private]
 

osg::Timer osgAL::SoundManager::m_timer [private]
 


The documentation for this class was generated from the following file:
Generated on Mon Nov 22 09:27:17 2004 for OpenSceneGraphAudioLibrary(OsgAL) by doxygen1.2.15