From d787afb6a4035e2a9bc78a13eefb2775e7786d1f Mon Sep 17 00:00:00 2001 From: David Rose Date: Tue, 6 Jan 2004 20:46:57 +0000 Subject: [PATCH] ensure sounds aren't played past their duration --- direct/src/interval/SoundInterval.py | 15 +++++++++++---- panda/src/audiotraits/milesAudioSound.cxx | 10 ++++++++++ 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/direct/src/interval/SoundInterval.py b/direct/src/interval/SoundInterval.py index 9b498c0997..945c1d9f04 100644 --- a/direct/src/interval/SoundInterval.py +++ b/direct/src/interval/SoundInterval.py @@ -28,13 +28,17 @@ class SoundInterval(Interval.Interval): SoundInterval.soundNum += 1 # Record instance variables self.sound = sound + if sound: + self.soundDuration = sound.length() + else: + self.soundDuration = 0 self.fLoop = loop self.volume = volume self.startTime = startTime self.node = node # If no duration given use sound's duration as interval's duration if float(duration) == 0.0 and self.sound != None: - duration = max(self.sound.length() - self.startTime, 0) + duration = max(self.soundDuration - self.startTime, 0) #if (duration == 0): # self.notify.warning('zero length duration!') # MPG - hack for Miles bug @@ -54,14 +58,17 @@ class SoundInterval(Interval.Interval): t1 = t + self.startTime if (t1 < 0.1): t1 = 0.0 - base.sfxPlayer.playSfx(self.sound, self.fLoop, 1, self.volume, t1, self.node) + if t1 < self.soundDuration: + base.sfxPlayer.playSfx(self.sound, self.fLoop, 1, self.volume, t1, self.node) self.state = CInterval.SStarted - self.currT = t1 + self.currT = t def privStep(self, t): if self.state == CInterval.SPaused: # Restarting from a pause. - base.sfxPlayer.playSfx(self.sound, self.fLoop, 1, self.volume, t, self.node) + t1 = t + self.startTime + if t1 < self.soundDuration: + base.sfxPlayer.playSfx(self.sound, self.fLoop, 1, self.volume, t1, self.node) self.state = CInterval.SStarted self.currT = t diff --git a/panda/src/audiotraits/milesAudioSound.cxx b/panda/src/audiotraits/milesAudioSound.cxx index 8751160898..3286179e1b 100644 --- a/panda/src/audiotraits/milesAudioSound.cxx +++ b/panda/src/audiotraits/milesAudioSound.cxx @@ -314,6 +314,16 @@ get_loop_count() const { void MilesAudioSound:: set_time(float time) { miles_audio_debug("set_time(time="< max_time) { + milesAudio_cat.warning() + << "set_time(" << time << ") requested for sound of length " + << max_time << "\n"; + time = max_time; + } + S32 milisecond_time=S32(1000*time); AIL_quick_set_ms_position(_audio, milisecond_time); }