1 // soundmgr.hxx -- Sound effect management class
3 // Sampel Group handler initially written by Erik Hofman
5 // Copyright (C) 2009 Erik Hofman - <erik@ehofman.com>
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 // General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software Foundation,
19 // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24 * \file sample_group.hxx
25 * sample groups contain all sounds related to one specific object and
26 * have to be added to the sound manager, otherwise they won't get processed.
29 #ifndef _SG_SAMPLE_GROUP_OPENAL_HXX
30 #define _SG_SAMPLE_GROUP_OPENAL_HXX 1
33 # error This library requires C++
36 #if defined(__APPLE__)
37 # include <OpenAL/al.h>
45 #include <simgear/compiler.h>
46 #include <simgear/math/SGMath.hxx>
47 #include <simgear/structure/SGReferenced.hxx>
48 #include <simgear/structure/SGSharedPtr.hxx>
49 #include <simgear/structure/exception.hxx>
51 #include "sample_openal.hxx"
56 typedef map < string, SGSharedPtr<SGSoundSample> > sample_map;
57 typedef sample_map::iterator sample_map_iterator;
58 typedef sample_map::const_iterator const_sample_map_iterator;
62 class SGSampleGroup : public SGReferenced
66 SGSampleGroup ( SGSoundMgr *smgr, const string &refname );
69 virtual void update (double dt);
72 * add a sound effect, return true if successful
74 bool add( SGSoundSample *sound, const string& refname );
77 * remove a sound effect, return true if successful
79 bool remove( const string& refname );
82 * return true of the specified sound exists in the sound manager system
84 bool exists( const string& refname );
87 * return a pointer to the SGSoundSample if the specified sound
88 * exists in the sound manager system, otherwise return NULL
90 SGSoundSample *find( const string& refname );
93 * request to stop playing all associated samples until further notice
98 * request to resume playing all associated samples
104 * request to start playing the associated samples
106 bool play( const string& refname, bool looping );
109 * tell the scheduler to play the indexed sample in a continuous
112 inline bool play_looped( const string& refname ) {
113 return play( refname, true );
117 * tell the scheduler to play the indexed sample once
119 inline bool play_once( const string& refname ) {
120 return play( refname, false );
124 * return true of the specified sound is currently being played
126 bool is_playing( const string& refname );
129 * request to stop playing the associated samples
131 bool stop( const string& refname );
134 * set overall volume for the application.
135 * @param must be between 0.0 and 1.0
137 void set_volume( float vol );
140 * set the positions of all managed sound sources
142 void set_position( SGVec3d pos );
145 * set the velocities of all managed sound sources
147 void set_velocity( SGVec3f vel );
150 * set the orientation of all managed sound sources
152 void set_orientation( SGVec3f ori );
154 inline void tie_to_listener() { _tied_to_listener = true; }
164 SGVec3f _orientation;
165 bool _tied_to_listener;
169 bool testForALError(string s);
170 bool testForError(void *p, string s);
174 void update_sample_config( SGSoundSample *sound );
177 #endif // _SG_SAMPLE_GROUP_OPENAL_HXX