]> git.mxchange.org Git - simgear.git/blob - simgear/sound/soundmgr_openal.hxx
02b732d849e29371a9ca8f2593d2f5dded4b03c8
[simgear.git] / simgear / sound / soundmgr_openal.hxx
1 // soundmgr.hxx -- Sound effect management class
2 //
3 // Sound manager initially written by David Findlay
4 // <david_j_findlay@yahoo.com.au> 2001
5 //
6 // C++-ified by Curtis Olson, started March 2001.
7 //
8 // Copyright (C) 2001  Curtis L. Olson - curt@flightgear.org
9 //
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.
14 //
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.
19 //
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.
23 //
24 // $Id$
25
26 /**
27  * \file soundmgr.hxx
28  * Provides a sound manager class to keep track of
29  * multiple sounds and manage playing them with different effects and
30  * timings.
31  */
32
33 #ifndef _SG_SOUNDMGR_OPENAL_HXX
34 #define _SG_SOUNDMGR_OPENAL_HXX 1
35
36 #ifndef __cplusplus
37 # error This library requires C++
38 #endif
39
40 #include <simgear/compiler.h>
41
42 #include STL_STRING
43 #include <map>
44
45 #include <AL/al.h>
46
47 #include "sample_openal.hxx"
48
49 SG_USING_STD(map);
50 SG_USING_STD(string);
51
52
53 typedef map < string, SGSoundSample * > sample_map;
54 typedef sample_map::iterator sample_map_iterator;
55 typedef sample_map::const_iterator const_sample_map_iterator;
56
57
58 /**
59  * Manage a collection of SGSoundSample instances
60  */
61 class SGSoundMgr
62 {
63
64     // Position of the listener.
65     ALfloat listener_pos[3];
66
67     // Velocity of the listener.
68     ALfloat listener_vel[3];
69
70     // Orientation of the listener. (first 3 elements are "at", second
71     // 3 are "up")
72     ALfloat listener_ori[6];
73
74     sample_map samples;
75
76     bool working;
77     double safety;
78
79 public:
80
81     SGSoundMgr();
82     ~SGSoundMgr();
83
84
85     /**
86      * (re) initialize the sound manager.
87      */
88     void init();
89
90
91     /**
92      * Bind properties for the sound manager.
93      */
94     void bind();
95
96
97     /**
98      * Unbind properties for the sound manager.
99      */
100     void unbind();
101
102
103     /**
104      * Run the audio scheduler.
105      */
106     void update(double dt);
107
108
109     /**
110      * Pause all sounds.
111      */
112     void pause();
113
114
115     /**
116      * Resume all sounds.
117      */
118     void resume();
119
120
121     /**
122      * is audio working?
123      */
124     inline bool is_working() const { return working; }
125
126     /**
127      * reinitialize the sound manager
128      */
129     inline void reinit() { init(); }
130
131     /**
132      * add a sound effect, return true if successful
133      */
134     bool add( SGSoundSample *sound, const string& refname);
135
136     /** 
137      * remove a sound effect, return true if successful
138      */
139     bool remove( const string& refname );
140
141     /**
142      * return true of the specified sound exists in the sound manager system
143      */
144     bool exists( const string& refname );
145
146     /**
147      * return a pointer to the SGSoundSample if the specified sound
148      * exists in the sound manager system, otherwise return NULL
149      */
150     SGSoundSample *find( const string& refname );
151
152     /**
153      * tell the scheduler to play the indexed sample in a continuous
154      * loop
155      */
156     bool play_looped( const string& refname );
157
158     /**
159      * tell the scheduler to play the indexed sample once
160      */
161     bool play_once( const string& refname );
162
163     /**
164      * return true of the specified sound is currently being played
165      */
166     bool is_playing( const string& refname );
167
168     /**
169      * immediate stop playing the sound
170      */
171     bool stop( const string& refname );
172 };
173
174
175 #endif // _SG_SOUNDMGR_OPENAL_HXX
176
177