1 // soundmgr.hxx -- Sound effect management class
3 // Sound manager initially written by David Findlay
4 // <david_j_findlay@yahoo.com.au> 2001
6 // C++-ified by Curtis Olson, started March 2001.
8 // Copyright (C) 2001 Curtis L. Olson - curt@flightgear.org
10 // This program is free software; you can redistribute it and/or
11 // modify it under the terms of the GNU General Public License as
12 // published by the Free Software Foundation; either version 2 of the
13 // License, or (at your option) any later version.
15 // This program is distributed in the hope that it will be useful, but
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 // General Public License for more details.
20 // You should have received a copy of the GNU General Public License
21 // along with this program; if not, write to the Free Software
22 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 * Provides a sound manager class to keep track of
29 * multiple sounds and manage playing them with different effects and
33 #ifndef _SG_SOUNDMGR_OPENAL_HXX
34 #define _SG_SOUNDMGR_OPENAL_HXX 1
37 # error This library requires C++
40 #include <simgear/compiler.h>
45 #if defined( __APPLE__ )
46 # include <OpenAL/al.h>
51 #include "sample_openal.hxx"
57 typedef map < string, SGSoundSample * > sample_map;
58 typedef sample_map::iterator sample_map_iterator;
59 typedef sample_map::const_iterator const_sample_map_iterator;
63 * Manage a collection of SGSoundSample instances
68 // Position of the listener.
69 ALfloat listener_pos[3];
71 // Velocity of the listener.
72 ALfloat listener_vel[3];
74 // Orientation of the listener. (first 3 elements are "at", second
76 ALfloat listener_ori[6];
90 * (re) initialize the sound manager.
96 * Bind properties for the sound manager.
102 * Unbind properties for the sound manager.
108 * Run the audio scheduler.
110 void update(double dt);
128 inline bool is_working() const { return working; }
131 * reinitialize the sound manager
133 inline void reinit() { init(); }
136 * add a sound effect, return true if successful
138 bool add( SGSoundSample *sound, const string& refname);
141 * remove a sound effect, return true if successful
143 bool remove( const string& refname );
146 * return true of the specified sound exists in the sound manager system
148 bool exists( const string& refname );
151 * return a pointer to the SGSoundSample if the specified sound
152 * exists in the sound manager system, otherwise return NULL
154 SGSoundSample *find( const string& refname );
157 * tell the scheduler to play the indexed sample in a continuous
160 bool play_looped( const string& refname );
163 * tell the scheduler to play the indexed sample once
165 bool play_once( const string& refname );
168 * return true of the specified sound is currently being played
170 bool is_playing( const string& refname );
173 * immediate stop playing the sound
175 bool stop( const string& refname );
178 * set the position of the listener (in opengl coordinates)
180 inline void set_listener_pos( ALfloat *pos ) {
181 listener_pos[0] = pos[0];
182 listener_pos[1] = pos[1];
183 listener_pos[2] = pos[2];
184 alListenerfv( AL_POSITION, listener_pos );
188 * set the velocity of the listener (in opengl coordinates)
190 inline void set_listener_vel( ALfloat *vel ) {
191 listener_vel[0] = vel[0];
192 listener_vel[1] = vel[1];
193 listener_vel[2] = vel[2];
194 alListenerfv( AL_VELOCITY, listener_vel );
198 * set the orientation of the listener (in opengl coordinates)
200 * Description: ORIENTATION is a pair of 3-tuples representing the
201 * 'at' direction vector and 'up' direction of the Object in
202 * Cartesian space. AL expects two vectors that are orthogonal to
203 * each other. These vectors are not expected to be normalized. If
204 * one or more vectors have zero length, implementation behavior
205 * is undefined. If the two vectors are linearly dependent,
206 * behavior is undefined.
208 inline void set_listener_orientation( ALfloat *ori ) {
209 listener_ori[0] = ori[0];
210 listener_ori[1] = ori[1];
211 listener_ori[2] = ori[2];
212 listener_ori[3] = ori[3];
213 listener_ori[4] = ori[4];
214 listener_ori[5] = ori[5];
215 alListenerfv( AL_ORIENTATION, listener_ori );
219 * set the positions of all managaged sound sources
221 void set_source_pos_all( ALfloat *pos );
224 * set the velocities of all managaged sound sources
226 void set_source_vel_all( ALfloat *pos );
230 #endif // _SG_SOUNDMGR_OPENAL_HXX