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>
47 #include <simgear/compiler.h>
48 #include <simgear/math/SGMath.hxx>
49 #include <simgear/structure/SGReferenced.hxx>
50 #include <simgear/structure/SGSharedPtr.hxx>
51 #include <simgear/structure/exception.hxx>
53 #include "sample_openal.hxx"
58 typedef map < string, SGSharedPtr<SGSoundSample> > sample_map;
59 typedef sample_map::iterator sample_map_iterator;
60 typedef sample_map::const_iterator const_sample_map_iterator;
64 class SGSampleGroup : public SGReferenced
68 SGSampleGroup ( SGSoundMgr *smgr, const string &refname );
71 virtual void update (double dt);
74 * add a sound effect, return true if successful
76 bool add( SGSoundSample *sound, const string& refname );
79 * remove a sound effect, return true if successful
81 bool remove( const string& refname );
84 * return true of the specified sound exists in the sound manager system
86 bool exists( const string& refname );
89 * return a pointer to the SGSoundSample if the specified sound
90 * exists in the sound manager system, otherwise return NULL
92 SGSoundSample *find( const string& refname );
95 * request to stop playing all associated samples until further notice
100 * request to resume playing all associated samples
106 * request to start playing the associated samples
108 bool play( const string& refname, bool looping );
111 * tell the scheduler to play the indexed sample in a continuous
114 inline bool play_looped( const string& refname ) {
115 return play( refname, true );
119 * tell the scheduler to play the indexed sample once
121 inline bool play_once( const string& refname ) {
122 return play( refname, false );
126 * return true of the specified sound is currently being played
128 bool is_playing( const string& refname );
131 * request to stop playing the associated samples
133 bool stop( const string& refname );
136 * set overall volume for the application.
137 * @param must be between 0.0 and 1.0
139 void set_volume( float vol );
142 * set the velocities of all managed sound sources
144 void set_velocity( SGVec3d& vel );
147 * set the position of all managed sound sources
149 void set_position( SGGeod pos );
152 * set the orientation of all managed sound sources
154 void set_orientation( SGQuatd ori );
156 inline void tie_to_listener() { _tied_to_listener = true; }
166 bool _tied_to_listener;
170 SGQuatd _orientation;
174 bool testForALError(string s);
175 bool testForError(void *p, string s);
177 void update_sample_config( SGSoundSample *sound );
180 #endif // _SG_SAMPLE_GROUP_OPENAL_HXX