Public Member Functions | |
virtual void | shutdown () |
bool | initialized () |
Returns true if the SoundManager is initalized. | |
bool | pushSoundEvent (SoundState *state, unsigned int priority=0) |
openalpp::Sample * | getSample (const std::string &path, bool add_to_cache=true) |
void | clearSampleCache (void) |
openalpp::Stream * | getStream (const std::string &path, bool add_to_cache=true) |
void | clearStreamCache (void) |
SoundState * | findSoundState (const std::string &id) |
void | releaseSource (openalpp::Source *source) |
void | init (unsigned int num_soundsources, float sound_velocity=343) |
Initializes the SoundManager. | |
void | update () |
void | processQueuedSoundStates () |
For each soundstate in queue, allocate a soundsource and play it. | |
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. | |
unsigned int | getNumAvailableSources () |
unsigned int | getNumSources () |
void | stopAllSources () |
unsigned int | getNumActiveSources () |
void | setClampVelocity (bool c) |
Set if the velocity is clamped (using the MaxVelocity attribute). | |
bool | getClampVelocity () |
Get true if the velocity is clamped (using the MaxVelocity attribute). | |
const bool | getClampVelocity () const |
Get const true if the velocity is clamped (using the MaxVelocity attribute). | |
void | setUpdateFrequency (float frequency) |
Set the update frequency for both sources and listener, to update pos, dir and occlusions. | |
float | getUpdateFrequency () |
Get the update frequency for both sources and listener, to update pos, dir and occlusions. | |
const float | getUpdateFrequency () const |
Get const the update frequency for both sources and listener, to update pos, dir and occlusions. | |
Static Public Member Functions | |
static SoundManager * | instance (void) |
Return a pointer to the singleton object. | |
Classes | |
class | SoundStateFlyWeight |
Class that handles all the soundstates. See FlyWeight Design pattern. | |
class | SoundStateQueueItem |
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.
This makes the pushSoundEvent method suitable for playing soundeffects.
static SoundManager* osgAL::SoundManager::instance | ( | void | ) | [static] |
Return a pointer to the singleton object.
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.
bool osgAL::SoundManager::initialized | ( | ) | [inline] |
Returns true if the SoundManager is initalized.
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.
state | - The state that will be pushed to the waiting queue | |
priority | - The priority of the state, 0 lowest |
openalpp::Sample* osgAL::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.
void osgAL::SoundManager::clearSampleCache | ( | void | ) | [inline] |
Clear the sample cache with all loaded samples.
openalpp::Stream* osgAL::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::clearStreamCache | ( | void | ) | [inline] |
Clear the Stream cache with all loaded streams.
SoundState* osgAL::SoundManager::findSoundState | ( | const std::string & | id | ) |
Return a pointer to the SoundState with the name id.
void osgAL::SoundManager::releaseSource | ( | openalpp::Source * | source | ) |
Puts the source into the list of available sound sources
void osgAL::SoundManager::init | ( | unsigned int | num_soundsources, | |
float | sound_velocity = 343 | |||
) |
Initializes the SoundManager.
void osgAL::SoundManager::update | ( | ) |
void osgAL::SoundManager::processQueuedSoundStates | ( | ) |
For each soundstate in queue, allocate a soundsource and play it.
openalpp::Listener * osgAL::SoundManager::getListener | ( | ) | [inline] |
Return a pointer to the listener.
openalpp::AudioEnvironment * osgAL::SoundManager::getEnvironment | ( | ) | [inline] |
Return a pointer to the Sound environment.
void osgAL::SoundManager::addSoundState | ( | osgAL::SoundState * | state | ) | [inline] |
Add a SoundState to the list of existing sound states
References osgAL::SoundState::getName().
bool osgAL::SoundManager::removeSoundState | ( | const std::string & | id | ) |
Removes the sound state from the list of existing soundstates.
bool osgAL::SoundManager::removeSoundState | ( | osgAL::SoundState * | state | ) |
Removes the sound state from the list of existing soundstates
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.
const osg::Vec3& osgAL::SoundManager::getListenerDirection | ( | ) | const [inline] |
void osgAL::SoundManager::setListenerMatrix | ( | const osg::Matrix & | matrix | ) |
Set the transformation matrix for the listener.
const osg::Matrix& osgAL::SoundManager::getListenerMatrix | ( | ) | const [inline] |
Return the current listener matrix.
openalpp::Source* osgAL::SoundManager::allocateSource | ( | unsigned int | priority, | |
bool | mutual_use = true | |||
) | [inline] |
Tries to find an available sound Source
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 |
void osgAL::SoundManager::setMaxVelocity | ( | float | vel | ) | [inline] |
Set the maximum velocity used in doppler calculation.
float osgAL::SoundManager::getMaxVelocity | ( | ) | const [inline] |
Returns the maximum velocity used in doppler calculation.
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::stopAllSources | ( | ) |
Stop playing on all initialized SoundSources immediately.
unsigned int osgAL::SoundManager::getNumActiveSources | ( | ) | [inline] |
Returns the number of SoundSources currently in use. Should be between 0..getNumSources()
void osgAL::SoundManager::setClampVelocity | ( | bool | c | ) | [inline] |
Set if the velocity is clamped (using the MaxVelocity attribute).
bool osgAL::SoundManager::getClampVelocity | ( | ) | [inline] |
Get true if the velocity is clamped (using the MaxVelocity attribute).
const bool osgAL::SoundManager::getClampVelocity | ( | ) | const [inline] |
Get const true if the velocity is clamped (using the MaxVelocity attribute).
void osgAL::SoundManager::setUpdateFrequency | ( | float | frequency | ) | [inline] |
Set the update frequency for both sources and listener, to update pos, dir and occlusions.
float osgAL::SoundManager::getUpdateFrequency | ( | ) | [inline] |
Get the update frequency for both sources and listener, to update pos, dir and occlusions.
const float osgAL::SoundManager::getUpdateFrequency | ( | ) | const [inline] |
Get const the update frequency for both sources and listener, to update pos, dir and occlusions.