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.
34 #include <simgear/compiler.h>
42 #include <simgear/timing/timestamp.hxx>
44 #include <Main/fgfs.hxx>
50 // manages everything we need to know for an individual sound sample
56 slEnvelope *pitch_envelope;
57 slEnvelope *volume_envelope;
64 FGSimpleSound( string file );
65 FGSimpleSound( unsigned char *buffer, int len );
68 void play_once( slScheduler *sched );
69 void play_looped( slScheduler *sched );
71 inline void play( slScheduler *sched, bool looped ) {
72 if (looped) play_looped( sched );
73 else play_once( sched );
75 inline void stop( slScheduler *sched ) {
76 sched->stopSample( sample );
78 inline bool is_playing( ) {
79 return (sample->getPlayCount() > 0 );
82 inline double get_pitch() const { return pitch; }
83 inline void set_pitch( double p ) {
85 pitch_envelope->setStep( 0, 0.01, pitch );
87 inline double get_volume() const { return volume; }
88 inline void set_volume( double v ) {
90 volume_envelope->setStep( 0, 0.01, volume );
93 inline slSample *get_sample() { return sample; }
94 inline slEnvelope *get_pitch_envelope() { return pitch_envelope; }
95 inline slEnvelope *get_volume_envelope() { return volume_envelope; }
104 typedef map < string, sample_ref * > sample_map;
105 typedef sample_map::iterator sample_map_iterator;
106 typedef sample_map::const_iterator const_sample_map_iterator;
109 typedef map < string, FGSimpleSound * > sound_map;
110 typedef sound_map::iterator sound_map_iterator;
111 typedef sound_map::const_iterator const_sound_map_iterator;
114 class FGSoundMgr : public FGSubsystem
117 slScheduler *audio_sched;
118 smMixer *audio_mixer;
133 * Initialize the sound manager.
139 * Bind properties for the sound manager.
145 * Unbind properties for the sound manager.
151 * Run the audio scheduler.
157 inline bool is_working() const { return !audio_sched->notWorking(); }
159 // add a sound effect, return true if successful
160 bool add( FGSimpleSound *sound, const string& refname);
162 // add a sound file, return the sample if successful, else return NULL
163 FGSimpleSound *add( const string& refname, const string& file = "" );
165 // remove a sound effect, return true if successful
166 bool remove( const string& refname );
168 // return true of the specified sound exists in the sound manager system
169 bool exists( const string& refname );
171 // return a pointer to the FGSimpleSound if the specified sound
172 // exists in the sound manager system, otherwise return NULL
173 FGSimpleSound *find( const string& refname );
175 // tell the scheduler to play the indexed sample in a continuous
177 bool play_looped( const string& refname );
179 // tell the scheduler to play the indexed sample once
180 bool play_once( const string& refname );
182 // return true of the specified sound is currently being played
183 bool is_playing( const string& refname );
185 // immediate stop playing the sound
186 bool stop( const string& refname );
188 // return the audio scheduler
189 inline slScheduler *get_scheduler( ) { return audio_sched; };
193 #endif // _SOUNDMGR_HXX