simgear  3.5.0 [next] git://gitorious.org/fg/simgear.git
SimGear - Simulator Construction Tools
SGSoundMgr Class Reference

#include <soundmgr_openal.hxx>

Inheritance diagram for SGSoundMgr:
SGSubsystem SGReferenced

Classes

class  SoundManagerPrivate
 

Public Types

enum  { NO_SOURCE = (unsigned int)-1, NO_BUFFER = (unsigned int)-1, FAILED_BUFFER = (unsigned int)-2 }
 
enum  InitStatus { INIT_DONE, INIT_CONTINUE }
 

Public Member Functions

 SGSoundMgr ()
 
 ~SGSoundMgr ()
 
void activate ()
 
bool add (SGSampleGroup *sgrp, const std::string &refname)
 
bool bad_doppler_effect ()
 
virtual void bind ()
 
bool exists (const std::string &refname)
 
SGSampleGroupfind (const std::string &refname, bool create=false)
 
std::vector< const char * > get_available_devices ()
 
SGVec3f get_direction () const
 
const SGQuatdget_orientation () const
 
const SGVec3dget_position () const
 
const std::string & get_renderer ()
 
SGVec3f get_velocity ()
 
const std::string & get_vendor ()
 
float get_volume ()
 
bool has_changed ()
 
virtual InitStatus incrementalInit ()
 
void init ()
 
bool is_active () const
 
virtual bool is_suspended () const
 
bool is_working () const
 
bool load (const std::string &samplepath, void **data, int *format, size_t *size, int *freq)
 
virtual void postinit ()
 
void reinit ()
 
void release_buffer (SGSoundSample *sample)
 
void release_source (unsigned int source)
 
bool remove (const std::string &refname)
 
void reportTiming (void)
 
unsigned int request_buffer (SGSoundSample *sample)
 
unsigned int request_source ()
 
void resume ()
 
void select_device (const char *devname)
 
void set_orientation (const SGQuatd &ori)
 
void set_position (const SGVec3d &pos, const SGGeod &pos_geod)
 
void set_position_offset (const SGVec3d &pos)
 
void set_velocity (const SGVec3d &vel)
 
void set_volume (float vol)
 
virtual void shutdown ()
 
void stamp (const std::string &name)
 
void stop ()
 
void suspend ()
 
virtual void suspend (bool suspended)
 
virtual void unbind ()
 
void update (double dt)
 

Static Public Member Functions

static unsigned count (const SGReferenced *ref)
 
static unsigned get (const SGReferenced *ref)
 
static unsigned put (const SGReferenced *ref)
 
static bool shared (const SGReferenced *ref)
 

Protected Attributes

bool _suspended
 
eventTimeVec timingInfo
 

Static Protected Attributes

static SGSubsystemTimingCb reportTimingCb = NULL
 
static voidreportTimingUserData = NULL
 

Private Member Functions

bool testForALCError (std::string s)
 
bool testForALError (std::string s)
 
bool testForError (void *p, std::string s)
 
void update_sample_config (SGSampleGroup *sound)
 

Private Attributes

bool _active
 
bool _bad_doppler
 
bool _changed
 
std::string _device_name
 
SGGeod _geod_pos
 
SGVec3d _offset_pos
 
std::string _renderer
 
SGVec3d _velocity
 
std::string _vendor
 
float _volume
 
std::auto_ptr< SoundManagerPrivated
 private implementation object More...
 

Detailed Description

Manage a collection of SGSampleGroup instances

Definition at line 49 of file soundmgr_openal.hxx.

Member Enumeration Documentation

anonymous enum
Enumerator
NO_SOURCE 
NO_BUFFER 
FAILED_BUFFER 

Definition at line 178 of file soundmgr_openal.hxx.

enum SGSubsystem::InitStatus
inherited
Enumerator
INIT_DONE 

subsystem is fully initialised

INIT_CONTINUE 

init should be called again

Definition at line 151 of file subsystem_mgr.hxx.

Constructor & Destructor Documentation

SGSoundMgr::SGSoundMgr ( )

Definition at line 126 of file soundmgr_openal.cxx.

SGSoundMgr::~SGSoundMgr ( )

Definition at line 142 of file soundmgr_openal.cxx.

Member Function Documentation

void SGSoundMgr::activate ( void  )

Set the sound manager to a working condition.

Definition at line 269 of file soundmgr_openal.cxx.

Referenced by main().

bool SGSoundMgr::add ( SGSampleGroup sgrp,
const std::string &  refname 
)

Register a sample group to the sound manager.

Parameters
sgrpPointer to a sample group to add
refnameReference name of the sample group
Returns
true if successful, false otherwise

Definition at line 410 of file soundmgr_openal.cxx.

Referenced by find(), and SGSampleGroup::SGSampleGroup().

bool SGSoundMgr::bad_doppler_effect ( )
inline

Some implementations seem to need the velocity multiplied by a factor of 100 to make them distinct. I've not found if this is a problem in the implementation or in out code. Until then this function is used to detect the problematic implementations.

Definition at line 242 of file soundmgr_openal.hxx.

Referenced by SGSampleGroup::update_sample_config().

void SGSubsystem::bind ( void  )
virtualinherited

Acquire the subsystem's property bindings.

This method should bind all properties that the subsystem publishes. It will be invoked after init, but before any invocations of update.

Reimplemented in SGSubsystemMgr, SGSubsystemGroup, simgear::SGTerraSync, and SGPerformanceMonitor.

Definition at line 82 of file subsystem_mgr.cxx.

Referenced by main().

static unsigned SGReferenced::count ( const SGReferenced ref)
inlinestaticinherited
bool SGSoundMgr::exists ( const std::string &  refname)

Test if a specified sample group is registered at the sound manager

Parameters
refnameReference name of the sample group test for
Returns
true if the specified sample group exists

Definition at line 441 of file soundmgr_openal.cxx.

SGSampleGroup * SGSoundMgr::find ( const std::string &  refname,
bool  create = false 
)

Find a specified sample group in the sound manager

Parameters
refnameReference name of the sample group to find
createIf the group should be create if it does not exist
Returns
A pointer to the SGSampleGroup

Definition at line 449 of file soundmgr_openal.cxx.

Referenced by main().

vector< const char * > SGSoundMgr::get_available_devices ( )

Get a list of available playback devices.

Definition at line 645 of file soundmgr_openal.cxx.

SGVec3f SGSoundMgr::get_direction ( ) const

Get the direction vector of the sound manager This is in the same coordinate system as OpenGL; y=up, z=back, x=right.

Returns
Look-at direction of the OpenAL listener

Definition at line 737 of file soundmgr_openal.cxx.

Referenced by SGSampleGroup::update_sample_config().

const SGQuatd & SGSoundMgr::get_orientation ( ) const

Get the orientation of the sound manager

Returns
Quaternation containing the orientation information

Definition at line 716 of file soundmgr_openal.cxx.

const SGVec3d & SGSoundMgr::get_position ( ) const

Get the position of the sound manager. This is in the same coordinate system as OpenGL; y=up, z=back, x=right

Returns
OpenAL listener position

Definition at line 727 of file soundmgr_openal.cxx.

Referenced by SGSampleGroup::update_pos_and_orientation().

const std::string& SGSoundMgr::get_renderer ( )
inline

Definition at line 269 of file soundmgr_openal.hxx.

SGVec3f SGSoundMgr::get_velocity ( )
inline

Get the velocity vector of the sound manager This is in the same coordinate system as OpenGL; y=up, z=back, x=right.

Returns
Velocity vector of the OpenAL listener

Definition at line 154 of file soundmgr_openal.hxx.

Referenced by SGSampleGroup::update_sample_config().

const std::string& SGSoundMgr::get_vendor ( )
inline

Get the current OpenAL vendor or rendering backend.

Definition at line 268 of file soundmgr_openal.hxx.

float SGSoundMgr::get_volume ( )
inline

Get the master volume.

Returns
Volume (must be between 0.0 and 1.0)

Definition at line 196 of file soundmgr_openal.hxx.

bool SGSoundMgr::has_changed ( )
inline

Test if the position of the sound manager has changed. The value will be set to false upon the next call to update_late()

Returns
true if the position has changed

Definition at line 234 of file soundmgr_openal.hxx.

Referenced by SGSampleGroup::check_playing_sample(), and SGSampleGroup::update().

SGSubsystem::InitStatus SGSubsystem::incrementalInit ( )
virtualinherited

Reimplemented in SGSubsystemMgr, and SGSubsystemGroup.

Definition at line 60 of file subsystem_mgr.cxx.

void SGSoundMgr::init ( void  )
virtual

Initialize the subsystem.

This method should set up the state of the subsystem, but should not bind any properties. Note that any dependencies on the state of other subsystems should be placed here rather than in the constructor, so that FlightGear can control the initialization order.

Reimplemented from SGSubsystem.

Definition at line 150 of file soundmgr_openal.cxx.

Referenced by main(), and reinit().

bool SGSoundMgr::is_active ( ) const
inline

Test is the sound manager is in an active and working condition.

Returns
true is the sound manager is active

Definition at line 86 of file soundmgr_openal.hxx.

bool SGSubsystem::is_suspended ( ) const
virtualinherited

Test whether this subsystem is suspended.

Returns
true if the subsystem is suspended, false if it is not.

Reimplemented in SGSubsystemMgr, and SGSubsystemGroup.

Definition at line 110 of file subsystem_mgr.cxx.

bool SGSoundMgr::is_working ( ) const

Test is the sound manager is in a working condition.

Returns
true is the sound manager is working

Definition at line 711 of file soundmgr_openal.cxx.

Referenced by activate(), init(), load(), resume(), stop(), suspend(), and ~SGSoundMgr().

bool SGSoundMgr::load ( const std::string &  samplepath,
void **  data,
int format,
size_t *  size,
int freq 
)

Load a sample file and return it's configuration and data.

Parameters
samplepathPath to the file to load
dataPointer to a variable that points to the allocated data
formatPointer to a vairable that gets the OpenAL format
sizePointer to a vairable that gets the sample size in bytes
freqPointer to a vairable that gets the sample frequency in Herz
Returns
true if succesful, false on error

Definition at line 610 of file soundmgr_openal.cxx.

Referenced by main(), and request_buffer().

void SGSubsystem::postinit ( )
virtualinherited

Initialize parts that depend on other subsystems having been initialized.

This method should set up all parts that depend on other subsystems. One example is the scripting/Nasal subsystem, which is initialized last. So, if a subsystem wants to execute Nasal code in subsystem-specific configuration files, it has to do that in its postinit() method.

Reimplemented in SGSubsystemMgr, and SGSubsystemGroup.

Definition at line 67 of file subsystem_mgr.cxx.

static unsigned SGReferenced::put ( const SGReferenced ref)
inlinestaticinherited

Definition at line 46 of file SGReferenced.hxx.

void SGSoundMgr::reinit ( )
virtual

Reinitialize the subsystem.

This method should cause the subsystem to reinitialize itself, and (normally) to reload any configuration files.

Reimplemented from SGSubsystem.

Definition at line 253 of file soundmgr_openal.cxx.

void SGSoundMgr::release_buffer ( SGSoundSample sample)

Free an OpenAL buffer-id for this sample

Parameters
samplePointer to an audio sample for which to free the buffer

Definition at line 586 of file soundmgr_openal.cxx.

Referenced by SGSampleGroup::check_playing_sample(), SGSampleGroup::cleanup_removed_samples(), and SGSampleGroup::stop().

void SGSoundMgr::release_source ( unsigned int  source)

Free an OpenAL source-id for future use

Parameters
sourceOpenAL source-id to free

Definition at line 498 of file soundmgr_openal.cxx.

Referenced by SGSampleGroup::check_playing_sample(), SGSampleGroup::cleanup_removed_samples(), SGSampleGroup::start_playing_sample(), and SGSampleGroup::stop().

bool SGSoundMgr::remove ( const std::string &  refname)

Remove a sample group from the sound manager.

Parameters
refnameReference name of the sample group to remove
Returns
true if successful, false otherwise

Definition at line 426 of file soundmgr_openal.cxx.

void SGSubsystem::reportTiming ( void  )
inherited

Trigger the callback to report timing information for all subsystems.

unsigned int SGSoundMgr::request_buffer ( SGSoundSample sample)

Get a free OpenAL buffer-id The buffer-id will be assigned to the sample by calling this function.

Parameters
samplePointer to an audio sample to assign the buffer-id to
Returns
NO_BUFFER if loading of the buffer failed.

Definition at line 520 of file soundmgr_openal.cxx.

Referenced by SGSampleGroup::start_playing_sample().

unsigned int SGSoundMgr::request_source ( )

Get a free OpenAL source-id

Returns
NO_SOURCE if no source is available

Definition at line 482 of file soundmgr_openal.cxx.

Referenced by SGSampleGroup::start_playing_sample().

void SGSoundMgr::resume ( )
virtual

Resume operation of this subsystem.

This method instructs the subsystem to resume sim-time-depended operations. It is not an error for the resume method to be invoked when the subsystem is not suspended; the invocation should simply be ignored.

Reimplemented from SGSubsystem.

Definition at line 345 of file soundmgr_openal.cxx.

Referenced by reinit().

void SGSoundMgr::select_device ( const char *  devname)
inline

Select a specific sound device. Requires a init/reinit call before sound is actually switched.

Definition at line 69 of file soundmgr_openal.hxx.

Referenced by main().

void SGSoundMgr::set_orientation ( const SGQuatd ori)

Set the orientation of the sound manager

Parameters
oriQuaternation containing the orientation information

Definition at line 721 of file soundmgr_openal.cxx.

void SGSoundMgr::set_position ( const SGVec3d pos,
const SGGeod pos_geod 
)

Set the Cartesian position of the sound manager.

Parameters
posOpenAL listener position

Definition at line 732 of file soundmgr_openal.cxx.

Referenced by main().

void SGSoundMgr::set_position_offset ( const SGVec3d pos)
inline

Definition at line 126 of file soundmgr_openal.hxx.

void SGSoundMgr::set_velocity ( const SGVec3d vel)
inline

Set the velocity vector (in meters per second) of the sound manager This is the horizontal local frame; x=north, y=east, z=down

Parameters
velVelocity vector

Definition at line 144 of file soundmgr_openal.hxx.

void SGSoundMgr::set_volume ( float  vol)

Set the master volume.

Parameters
volVolume (must be between 0.0 and 1.0)

Definition at line 466 of file soundmgr_openal.cxx.

Referenced by main().

static bool SGReferenced::shared ( const SGReferenced ref)
inlinestaticinherited

Definition at line 50 of file SGReferenced.hxx.

void SGSubsystem::shutdown ( )
virtualinherited

Shutdown the subsystem.

Release any state associated with subsystem. Shutdown happens in the reverse order to init(), so this is the correct place to do shutdown that depends on other subsystems.

Reimplemented in SGSubsystemMgr, SGSubsystemGroup, SGEventMgr, simgear::SGTerraSync, and simgear::PropertyBasedMgr.

Definition at line 77 of file subsystem_mgr.cxx.

void SGSubsystem::stamp ( const std::string &  name)
inherited

Place time stamps at strategic points in the execution of subsystems update() member functions. Predominantly for debugging purposes.

Definition at line 115 of file subsystem_mgr.cxx.

void SGSoundMgr::stop ( )

Definition at line 286 of file soundmgr_openal.cxx.

Referenced by reinit(), and ~SGSoundMgr().

void SGSoundMgr::suspend ( )
virtual

Suspend operation of this subsystem.

This method instructs the subsystem to suspend sim-time-dependent operations until asked to resume. The update method will still be invoked so that the subsystem can take any non-time-dependent actions, such as updating the display.

It is not an error for the suspend method to be invoked when the subsystem is already suspended; the invocation should simply be ignored.

Reimplemented from SGSubsystem.

Definition at line 330 of file soundmgr_openal.cxx.

Referenced by reinit().

void SGSubsystem::suspend ( bool  suspended)
virtualinherited

Suspend or resume operation of this subsystem.

Parameters
suspendedtrue if the subsystem should be suspended, false otherwise.

Definition at line 98 of file subsystem_mgr.cxx.

bool SGSoundMgr::testForALCError ( std::string  s)
private

Definition at line 696 of file soundmgr_openal.cxx.

Referenced by init().

bool SGSoundMgr::testForALError ( std::string  s)
private

Definition at line 683 of file soundmgr_openal.cxx.

Referenced by init(), release_buffer(), release_source(), request_buffer(), stop(), and update().

bool SGSoundMgr::testForError ( void p,
std::string  s 
)
private

Definition at line 673 of file soundmgr_openal.cxx.

Referenced by init().

void SGSubsystem::unbind ( void  )
virtualinherited

Release the subsystem's property bindings.

This method should release all properties that the subsystem publishes. It will be invoked by FlightGear (not the destructor) just before the subsystem is removed.

Reimplemented in SGSubsystemMgr, SGSubsystemGroup, SGEventMgr, simgear::SGTerraSync, and SGPerformanceMonitor.

Definition at line 87 of file subsystem_mgr.cxx.

Referenced by main().

void SGSoundMgr::update ( double  delta_time_sec)
virtual

Update the subsystem.

FlightGear invokes this method every time the subsystem should update its state.

Parameters
delta_time_secThe delta time, in seconds, since the last update. On first update, delta time will be 0.

Implements SGSubsystem.

Definition at line 361 of file soundmgr_openal.cxx.

Referenced by main().

void SGSoundMgr::update_sample_config ( SGSampleGroup sound)
private

Member Data Documentation

bool SGSoundMgr::_active
private

Definition at line 276 of file soundmgr_openal.hxx.

Referenced by activate(), add(), is_active(), reinit(), resume(), stop(), suspend(), and update().

bool SGSoundMgr::_bad_doppler
private

Definition at line 287 of file soundmgr_openal.hxx.

Referenced by bad_doppler_effect(), init(), and update().

bool SGSoundMgr::_changed
private
std::string SGSoundMgr::_device_name
private

Definition at line 290 of file soundmgr_openal.hxx.

Referenced by init(), and select_device().

SGGeod SGSoundMgr::_geod_pos
private

Definition at line 282 of file soundmgr_openal.hxx.

Referenced by set_position(), SGSoundMgr(), and update().

SGVec3d SGSoundMgr::_offset_pos
private

Definition at line 281 of file soundmgr_openal.hxx.

Referenced by set_position_offset().

std::string SGSoundMgr::_renderer
private

Definition at line 288 of file soundmgr_openal.hxx.

Referenced by get_renderer(), init(), and stop().

bool SGSubsystem::_suspended
protectedinherited
SGVec3d SGSoundMgr::_velocity
private

Definition at line 285 of file soundmgr_openal.hxx.

Referenced by get_velocity(), set_velocity(), and update().

std::string SGSoundMgr::_vendor
private

Definition at line 289 of file soundmgr_openal.hxx.

Referenced by get_vendor(), init(), and stop().

float SGSoundMgr::_volume
private

Definition at line 278 of file soundmgr_openal.hxx.

Referenced by get_volume(), set_volume(), and update().

SGSubsystemTimingCb SGSubsystem::reportTimingCb = NULL
staticprotectedinherited
void * SGSubsystem::reportTimingUserData = NULL
staticprotectedinherited
eventTimeVec SGSubsystem::timingInfo
protectedinherited

Definition at line 279 of file subsystem_mgr.hxx.

Referenced by SGSubsystem::stamp().


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