瀏覽代碼

changed get_time()

Dave Schuyler 23 年之前
父節點
當前提交
328ba938c0
共有 3 個文件被更改,包括 32 次插入9 次删除
  1. 13 1
      panda/src/audio/audioSound.h
  2. 6 6
      panda/src/audiotraits/milesAudioSound.cxx
  3. 13 2
      panda/src/audiotraits/milesAudioSound.h

+ 13 - 1
panda/src/audio/audioSound.h

@@ -36,6 +36,9 @@ PUBLISHED:
   // volume, and balance, prior to calling play().  You may
   // set them while they're playing, but it's implementation
   // specific whether you get the results.
+  // - Calling play() a second time on the same sound before it is
+  //   finished will start the sound again (creating a skipping or
+  //   stuttering effect).
   virtual void play() = 0;
   virtual void stop() = 0;
   
@@ -49,8 +52,17 @@ PUBLISHED:
   virtual void set_loop_count(unsigned long loop_count=1) = 0;
   virtual unsigned long get_loop_count() const = 0;
   
-  // start_time: 0 = begining; length() = end.
+  // start_time in seconds: 0 = beginning; length() = end.
   // inits to 0.0.
+  // - Unlike the other get_* and set_* calls for a sound, the
+  //   current time position will change while the sound is playing.
+  //   To play the same sound from a time offset a second time,
+  //   explicitly set the time position again.  When looping, the
+  //   second and later loops will start from the beginning of the
+  //   sound.
+  // - If a sound is playing, calling get_time() repeatedly will
+  //   return different results over time.  e.g.:
+  //   float percent_complete = s.get_time() / s.length();
   virtual void set_time(float start_time=0.0) = 0;
   virtual float get_time() const = 0;
   

+ 6 - 6
panda/src/audiotraits/milesAudioSound.cxx

@@ -58,7 +58,7 @@ MilesAudioSound::
 MilesAudioSound(MilesAudioManager* manager,
     HAUDIO audio, string file_name, float length)
     : _manager(manager), _file_name(file_name),
-    _start_time(0), _volume(1.0f), _balance(0),
+    _volume(1.0f), _balance(0),
     _loop_count(1), _length(length),
     _active(true), _paused(false) {
   nassertv(audio);
@@ -90,7 +90,6 @@ play() {
         // stop any other sound that parent mgr is playing
         _manager->stop_all_sounds();
     }
-
     // Start playing:
     if (AIL_quick_play(_audio, _loop_count)) {
       audio_debug("  started sound " << _file_name );
@@ -170,15 +169,16 @@ get_loop_count() const {
 void MilesAudioSound::
 set_time(float start_time) {
   miles_audio_debug("set_time(start_time="<<start_time<<")");
-  _start_time=start_time;
-  S32 milisecond_start_time=S32(1000*_start_time);
+  S32 milisecond_start_time=S32(1000*start_time);
   AIL_quick_set_ms_position(_audio, milisecond_start_time);
 }
 
 float MilesAudioSound::
 get_time() const {
-  miles_audio_debug("get_time() returning "<<_start_time);
-  return _start_time;
+  S32 milisecond_start_time=AIL_quick_ms_position(_audio);
+  float start_time=float(milisecond_start_time*.001);
+  miles_audio_debug("get_time() returning "<<start_time);
+  return start_time;
 }
 
 void MilesAudioSound::

+ 13 - 2
panda/src/audiotraits/milesAudioSound.h

@@ -35,6 +35,9 @@ public:
   // volume, and balance, prior to calling play().  You may
   // set them while they're playing, but it's implementation
   // specific whether you get the results.
+  // - Calling play() a second time on the same sound before it is
+  //   finished will start the sound again (creating a skipping or
+  //   stuttering effect).
   void play();
   void stop();
 
@@ -48,8 +51,17 @@ public:
   void set_loop_count(unsigned long loop_count=1);
   unsigned long get_loop_count() const;
   
-  // 0 = begining; length() = end.
+  // start_time in seconds: 0 = beginning; length() = end.
   // inits to 0.0.
+  // - Unlike the other get_* and set_* calls for a sound, the
+  //   current time position will change while the sound is playing.
+  //   To play the same sound from a time offset a second time,
+  //   explicitly set the time position again.  When looping, the
+  //   second and later loops will start from the beginning of the
+  //   sound.
+  // - If a sound is playing, calling get_time() repeatedly will
+  //   return different results over time.  e.g.:
+  //   float percent_complete = s.get_time() / s.length();
   void set_time(float start_time=0.0f);
   float get_time() const;
   
@@ -85,7 +97,6 @@ protected:
 private:
   HAUDIO _audio;
   PT(MilesAudioManager) _manager;
-  float _start_time; // 0..length()
   float _volume; // 0..1.0
   float _balance; // -1..1
   mutable float _length; // in seconds.