]> git.mxchange.org Git - flightgear.git/blobdiff - src/Sound/soundmgr.hxx
Patch from Julian Foad:
[flightgear.git] / src / Sound / soundmgr.hxx
index 78b09f639d1135e8329fe004cafbfa322422103f..d9e9dd8fb6d4eb5eb3cc90ce7bb0bfb9c9a2b089 100644 (file)
@@ -50,6 +50,8 @@ SG_USING_STD(string);
 // manages everything we need to know for an individual sound sample
 class FGSimpleSound {
 
+private:
+
     slSample *sample;
     slEnvelope *pitch_envelope;
     slEnvelope *volume_envelope;
@@ -62,15 +64,24 @@ public:
     FGSimpleSound( unsigned char *buffer, int len );
     ~FGSimpleSound();
 
+    void play( slScheduler *sched, bool looped );
+    void stop( slScheduler *sched, bool quick = true );
+
+    inline void play_once( slScheduler *sched ) { play( sched, false); }
+    inline void play_looped( slScheduler *sched ) { play( sched, true); }
+    inline bool is_playing( ) {
+        return ( sample->getPlayCount() > 0 );
+    }
+
     inline double get_pitch() const { return pitch; }
     inline void set_pitch( double p ) {
-       pitch = p;
-       pitch_envelope->setStep( 0, 0.01, pitch );
+       pitch = p;
+       pitch_envelope->setStep( 0, 0.01, pitch );
     }
     inline double get_volume() const { return volume; }
     inline void set_volume( double v ) {
-       volume = v;
-       volume_envelope->setStep( 0, 0.01, volume );
+       volume = v;
+       volume_envelope->setStep( 0, 0.01, volume );
     }
 
     inline slSample *get_sample() { return sample; }
@@ -79,6 +90,16 @@ public:
 };
 
 
+typedef struct {
+       int n;
+       slSample *sample;
+} sample_ref;
+
+typedef map < string, sample_ref * > sample_map;
+typedef sample_map::iterator sample_map_iterator;
+typedef sample_map::const_iterator const_sample_map_iterator;
+
+
 typedef map < string, FGSimpleSound * > sound_map;
 typedef sound_map::iterator sound_map_iterator;
 typedef sound_map::const_iterator const_sound_map_iterator;
@@ -89,7 +110,9 @@ class FGSoundMgr : public FGSubsystem
 
     slScheduler *audio_sched;
     smMixer *audio_mixer;
+
     sound_map sounds;
+    sample_map samples;
 
     SGTimeStamp last;
     double safety;
@@ -121,14 +144,29 @@ public:
     /**
      * Run the audio scheduler.
      */
-    void update();
+    void update(double dt);
+
+
+    /**
+     * Pause all sounds.
+     */
+    void pause ();
+
+
+    /**
+     * Resume all sounds.
+     */
+    void resume ();
 
 
     // is audio working?
-    inline bool is_working() const { return !audio_sched->not_working(); }
+    inline bool is_working() const { return !audio_sched->notWorking(); }
 
     // add a sound effect, return true if successful
-    bool add( FGSimpleSound *sound, const string& refname );
+    bool add( FGSimpleSound *sound, const string& refname);
+
+    // add a sound file, return the sample if successful, else return NULL
+    FGSimpleSound *add( const string& refname, const string& file = "" );
 
     // remove a sound effect, return true if successful
     bool remove( const string& refname );
@@ -152,6 +190,9 @@ public:
 
     // immediate stop playing the sound
     bool stop( const string& refname );
+
+    // return the audio scheduler 
+    inline slScheduler *get_scheduler( ) { return audio_sched; };
 };