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.
27 #ifndef _SG_SOUNDMGR_HXX
28 #define _SG_SOUNDMGR_HXX 1
31 # error This library requires C++
34 #include <simgear/compiler.h>
35 #include <simgear/timing/timestamp.hxx>
47 // manages everything we need to know for an individual sound sample
53 slEnvelope *pitch_envelope;
54 slEnvelope *volume_envelope;
60 SimpleSound( const char *path, const char *file = NULL );
61 SimpleSound( unsigned char *buffer, int len );
64 void play( slScheduler *sched, bool looped );
65 void stop( slScheduler *sched, bool quick = true );
67 inline void play_once( slScheduler *sched ) { play( sched, false); }
68 inline void play_looped( slScheduler *sched ) { play( sched, true); }
69 inline bool is_playing( ) {
70 return ( sample->getPlayCount() > 0 );
73 inline double get_pitch() const { return pitch; }
74 inline void set_pitch( double p ) {
76 pitch_envelope->setStep( 0, 0.01, pitch );
78 inline double get_volume() const { return volume; }
79 inline void set_volume( double v ) {
81 volume_envelope->setStep( 0, 0.01, volume );
84 inline slSample *get_sample() { return sample; }
85 inline slEnvelope *get_pitch_envelope() { return pitch_envelope; }
86 inline slEnvelope *get_volume_envelope() { return volume_envelope; }
95 typedef map < string, sample_ref * > sample_map;
96 typedef sample_map::iterator sample_map_iterator;
97 typedef sample_map::const_iterator const_sample_map_iterator;
100 typedef map < string, SimpleSound * > sound_map;
101 typedef sound_map::iterator sound_map_iterator;
102 typedef sound_map::const_iterator const_sound_map_iterator;
108 slScheduler *audio_sched;
109 smMixer *audio_mixer;
123 * (re) initialize the sound manager.
129 * Bind properties for the sound manager.
135 * Unbind properties for the sound manager.
141 * Run the audio scheduler.
143 void update(double dt);
159 inline bool is_working() const { return !audio_sched->notWorking(); }
161 // reinitialize the sound manager
162 inline void reinit() { init(); }
164 // add a sound effect, return true if successful
165 bool add( SimpleSound *sound, const string& refname);
167 // add a sound file, return the sample if successful, else return NULL
168 SimpleSound *add( const string& refname,
169 const char *path, const char *file = NULL );
171 // remove a sound effect, return true if successful
172 bool remove( const string& refname );
174 // return true of the specified sound exists in the sound manager system
175 bool exists( const string& refname );
177 // return a pointer to the SimpleSound if the specified sound
178 // exists in the sound manager system, otherwise return NULL
179 SimpleSound *find( const string& refname );
181 // tell the scheduler to play the indexed sample in a continuous
183 bool play_looped( const string& refname );
185 // tell the scheduler to play the indexed sample once
186 bool play_once( const string& refname );
188 // return true of the specified sound is currently being played
189 bool is_playing( const string& refname );
191 // immediate stop playing the sound
192 bool stop( const string& refname );
194 // return the audio scheduler
195 inline slScheduler *get_scheduler( ) { return audio_sched; };
199 #endif // _SG_SOUNDMGR_HXX