]> git.mxchange.org Git - flightgear.git/commitdiff
Patches from Erik.
authorcurt <curt>
Mon, 11 Mar 2002 22:55:52 +0000 (22:55 +0000)
committercurt <curt>
Mon, 11 Mar 2002 22:55:52 +0000 (22:55 +0000)
src/Sound/fg_sound.cxx
src/Sound/soundmgr.cxx
src/Sound/soundmgr.hxx

index 9d193cc0c43ad9729f27f2d08a999e76f83f194c..6fe6d37a76ed7f6ec2e5e046cbbceb4e341cc789 100644 (file)
@@ -279,7 +279,7 @@ FGSound::update (int dt)
       //
       // If the state changes to false, stop playing.
       //
-      if (check == 0) {
+      if (!check) {
          _active = false;
          if (mgr->is_playing(_name)) {
             SG_LOG(SG_GENERAL, SG_INFO, "Stopping sound: " << _name);
@@ -298,7 +298,7 @@ FGSound::update (int dt)
    } else {            // FLIPFLOP, RAISE, FALL
 
       bool check = (int)(_offset + _property->getFloatValue() * _factor);
-      if ((bool)check == _active)
+      if (check == _active)
             return;
 
       //
@@ -390,9 +390,9 @@ FGSound::update (int dt)
    _active = !_active;
 
    if (_mode == FGSound::ONCE)
-      mgr->play_once(_name);
+      _sample->play(mgr->get_scheduler(), false);
    else
-      mgr->play_looped(_name);
+      _sample->play(mgr->get_scheduler(), true);
 
    SG_LOG(SG_GENERAL, SG_INFO, "Starting audio playback for: " << _name);
    SG_LOG(SG_GENERAL, SG_BULK,
index aa4b6f4f0d8c4acc846c2006850dfa164823e2f8..eb51afac65d836bdd020673c2d0e259743f44f5c 100644 (file)
 #define FG_SOUND_SAFETY_MULT 3
 #define FG_MAX_SOUND_SAFETY ( 1.0 / FG_SOUND_SAFETY_MULT )
 
+//
+// SimpleSound
+//
+
 // constructor
 FGSimpleSound::FGSimpleSound( string file ) {
     SGPath slfile( globals->get_fg_root() );
@@ -60,6 +64,22 @@ FGSimpleSound::~FGSimpleSound() {
     delete sample;
 }
 
+void FGSimpleSound::play_once( slScheduler *sched ) {
+    sched->stopSample(sample);
+    sched->playSample(sample);
+    sched->addSampleEnvelope(sample, 0, 0, pitch_envelope, SL_PITCH_ENVELOPE);
+    sched->addSampleEnvelope(sample, 0, 1, volume_envelope, SL_VOLUME_ENVELOPE);
+}
+
+void FGSimpleSound::play_looped( slScheduler *sched ) {
+    sched->loopSample(sample);
+    sched->addSampleEnvelope(sample, 0, 0, pitch_envelope, SL_PITCH_ENVELOPE);
+    sched->addSampleEnvelope(sample, 0, 1, volume_envelope, SL_VOLUME_ENVELOPE);
+}
+
+//
+// Sound Manager
+//
 
 // constructor
 FGSoundMgr::FGSoundMgr() {
@@ -294,66 +314,46 @@ FGSimpleSound *FGSoundMgr::find( const string& refname ) {
 // tell the scheduler to play the indexed sample in a continuous
 // loop
 bool FGSoundMgr::play_looped( const string& refname ) {
-    sound_map_iterator it = sounds.find( refname );
-    if ( it != sounds.end() ) {
-       FGSimpleSound *sample = it->second;
-       audio_sched->loopSample( sample->get_sample() );
-       audio_sched->addSampleEnvelope( sample->get_sample(), 0, 0, 
-                                       sample->get_pitch_envelope(),
-                                       SL_PITCH_ENVELOPE );
-       audio_sched->addSampleEnvelope( sample->get_sample(), 0, 1, 
-                                       sample->get_volume_envelope(),
-                                       SL_VOLUME_ENVELOPE );
-       
-       return true;
-    } else {
-       return false;
-    }
+   FGSimpleSound *sample;
+
+    if ((sample = find( refname )) == NULL)
+       return false;
+
+    sample->play(audio_sched, true);
+    return true;
 }
 
 
 // tell the scheduler to play the indexed sample once
 bool FGSoundMgr::play_once( const string& refname ) {
-    sound_map_iterator it = sounds.find( refname );
-    if ( it != sounds.end() ) {
-       FGSimpleSound *sample = it->second;
-       audio_sched->stopSample( sample->get_sample() );
-       audio_sched->playSample( sample->get_sample() );
-       audio_sched->addSampleEnvelope( sample->get_sample(), 0, 0, 
-                                       sample->get_pitch_envelope(),
-                                       SL_PITCH_ENVELOPE );
-       audio_sched->addSampleEnvelope( sample->get_sample(), 0, 1, 
-                                       sample->get_volume_envelope(),
-                                       SL_VOLUME_ENVELOPE );
-       
-       return true;
-    } else {
-       return false;
-    }
+    FGSimpleSound *sample;
+
+    if ((sample = find( refname )) == NULL)
+       return false;
+
+    sample->play(audio_sched, false);
+    return true;
 }
 
 
 // return true of the specified sound is currently being played
 bool FGSoundMgr::is_playing( const string& refname ) {
-    sound_map_iterator it = sounds.find( refname );
-    if ( it != sounds.end() ) {
-       FGSimpleSound *sample = it->second;
-       return (sample->get_sample()->getPlayCount() > 0 );
-       return true;
-    } else {
-       return false;
-    }
+    FGSimpleSound *sample;
+
+    if ((sample = find( refname )) == NULL)
+       return false;
+
+    return sample->is_playing();
 }
 
 
 // immediate stop playing the sound
 bool FGSoundMgr::stop( const string& refname ) {
-    sound_map_iterator it = sounds.find( refname );
-    if ( it != sounds.end() ) {
-       FGSimpleSound *sample = it->second;
-       audio_sched->stopSample( sample->get_sample() );
-       return true;
-    } else {
-       return false;
-    }
+    FGSimpleSound *sample;
+
+    if ((sample = find( refname )) == NULL)
+       return false;
+
+    audio_sched->stopSample( sample->get_sample() );
+    return true;
 }
index 2c756390528eb2312d9abe80e822be7130b8ccb5..d47e9730a1f292d2a2c25de9a5e3ee5c857e76dc 100644 (file)
@@ -50,11 +50,14 @@ 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;
     double pitch;
     double volume;
+    int clients;
 
 public:
 
@@ -62,15 +65,29 @@ public:
     FGSimpleSound( unsigned char *buffer, int len );
     ~FGSimpleSound();
 
+    void play_once( slScheduler *sched );
+    void play_looped( slScheduler *sched );
+
+    inline void play( slScheduler *sched, bool looped ) {
+       if (looped) play_looped( sched );
+       else play_once( sched );
+    }
+    inline void stop( slScheduler *sched ) {
+        sched->stopSample( sample );
+    }
+    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; }
@@ -167,6 +184,9 @@ public:
 
     // immediate stop playing the sound
     bool stop( const string& refname );
+
+    // return the audio scheduler 
+    inline slScheduler *get_scheduler( ) { return audio_sched; };
 };