Browse Source

audio: sound.set_time() should take effect immediately

Fixes #770
rdb 6 years ago
parent
commit
bbb334abea
2 changed files with 10 additions and 7 deletions
  1. 3 5
      panda/src/audio/audioSound.h
  2. 7 2
      panda/src/audiotraits/openalAudioSound.cxx

+ 3 - 5
panda/src/audio/audioSound.h

@@ -47,11 +47,9 @@ PUBLISHED:
    * concept) to the seek position within a file.  The value starts at 0.0 (the
    * concept) to the seek position within a file.  The value starts at 0.0 (the
    * default) and ends at the value given by the length() method.
    * default) and ends at the value given by the length() method.
    *
    *
-   * The current time position will not change while the sound is playing; you
-   * must call play() again to effect the change.  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.
+   * In the past, this call did nothing if the sound was currently playing, and
+   * it was necessary to call play() to effect the change.  This is no longer
+   * the case; the time change takes effect immediately.
    *
    *
    * If a sound is playing, calling get_time() repeatedly will return different
    * If a sound is playing, calling get_time() repeatedly will return different
    * results over time.  e.g.
    * results over time.  e.g.

+ 7 - 2
panda/src/audiotraits/openalAudioSound.cxx

@@ -564,13 +564,18 @@ push_fresh_buffers() {
 }
 }
 
 
 /**
 /**
- * The next time you call play, the sound will start from the specified
- * offset.
+ * Sets the offset within the sound.  If the sound is currently playing, its
+ * position is updated immediately.
  */
  */
 void OpenALAudioSound::
 void OpenALAudioSound::
 set_time(PN_stdfloat time) {
 set_time(PN_stdfloat time) {
   ReMutexHolder holder(OpenALAudioManager::_lock);
   ReMutexHolder holder(OpenALAudioManager::_lock);
   _start_time = time;
   _start_time = time;
+
+  if (is_playing()) {
+    // Ensure that the position is updated immediately.
+    play();
+  }
 }
 }
 
 
 /**
 /**