|
@@ -22,8 +22,14 @@ class SoundInterval(Interval.Interval):
|
|
|
# seems to be some timing in the audio such that the stop doesn't
|
|
# seems to be some timing in the audio such that the stop doesn't
|
|
|
# kill the looping sound until the next time around if duration
|
|
# kill the looping sound until the next time around if duration
|
|
|
# of the interval equals duration of the sound
|
|
# of the interval equals duration of the sound
|
|
|
|
|
+ # seamlessloop will let the audio system loop the sound rather
|
|
|
|
|
+ # than explicitly restarting the sound every time around. This
|
|
|
|
|
+ # prevents a skip in the sound at every repetition (the gap in
|
|
|
|
|
+ # the sound is caused by the delay between the end of the sound
|
|
|
|
|
+ # and the next taskMgr cycle)
|
|
|
def __init__(self, sound, loop = 0, duration = 0.0, name = None,
|
|
def __init__(self, sound, loop = 0, duration = 0.0, name = None,
|
|
|
- volume = 1.0, startTime = 0.0, node=None):
|
|
|
|
|
|
|
+ volume = 1.0, startTime = 0.0, node=None,
|
|
|
|
|
+ seamlessLoop=True):
|
|
|
"""__init__(sound, loop, name)
|
|
"""__init__(sound, loop, name)
|
|
|
"""
|
|
"""
|
|
|
# Generate unique name
|
|
# Generate unique name
|
|
@@ -39,6 +45,10 @@ class SoundInterval(Interval.Interval):
|
|
|
self.volume = volume
|
|
self.volume = volume
|
|
|
self.startTime = startTime
|
|
self.startTime = startTime
|
|
|
self.node = node
|
|
self.node = node
|
|
|
|
|
+ self._seamlessLoop = seamlessLoop
|
|
|
|
|
+ if self._seamlessLoop:
|
|
|
|
|
+ self._fLoop = True
|
|
|
|
|
+ self._soundPlaying = False
|
|
|
# If no duration given use sound's duration as interval's duration
|
|
# If no duration given use sound's duration as interval's duration
|
|
|
if float(duration) == 0.0 and self.sound != None:
|
|
if float(duration) == 0.0 and self.sound != None:
|
|
|
duration = max(self.soundDuration - self.startTime, 0)
|
|
duration = max(self.soundDuration - self.startTime, 0)
|
|
@@ -70,14 +80,15 @@ class SoundInterval(Interval.Interval):
|
|
|
Interval.Interval.__init__(self, name, duration)
|
|
Interval.Interval.__init__(self, name, duration)
|
|
|
|
|
|
|
|
def privInitialize(self, t):
|
|
def privInitialize(self, t):
|
|
|
- # If its within a 10th of a second of the start,
|
|
|
|
|
|
|
+ # If it's within a 10th of a second of the start,
|
|
|
# start at the beginning
|
|
# start at the beginning
|
|
|
t1 = t + self.startTime
|
|
t1 = t + self.startTime
|
|
|
if (t1 < 0.1):
|
|
if (t1 < 0.1):
|
|
|
t1 = 0.0
|
|
t1 = 0.0
|
|
|
- if t1 < self.soundDuration:
|
|
|
|
|
|
|
+ if (t1 < self.soundDuration) and not (self._seamlessLoop and self._soundPlaying):
|
|
|
base.sfxPlayer.playSfx(
|
|
base.sfxPlayer.playSfx(
|
|
|
self.sound, self.fLoop, 1, self.volume, t1, self.node)
|
|
self.sound, self.fLoop, 1, self.volume, t1, self.node)
|
|
|
|
|
+ self._soundPlaying = True
|
|
|
self.state = CInterval.SStarted
|
|
self.state = CInterval.SStarted
|
|
|
self.currT = t
|
|
self.currT = t
|
|
|
|
|
|
|
@@ -91,18 +102,31 @@ class SoundInterval(Interval.Interval):
|
|
|
self.state = CInterval.SStarted
|
|
self.state = CInterval.SStarted
|
|
|
self.currT = t
|
|
self.currT = t
|
|
|
|
|
|
|
|
|
|
+ def finish(self, *args, **kArgs):
|
|
|
|
|
+ self._inFinish = True
|
|
|
|
|
+ Interval.Interval.finish(self, *args, **kArgs)
|
|
|
|
|
+ del self._inFinish
|
|
|
|
|
+
|
|
|
def privFinalize(self):
|
|
def privFinalize(self):
|
|
|
- if self.sound != None:
|
|
|
|
|
|
|
+ # if we're just coming to the end of a seamlessloop, leave the sound alone,
|
|
|
|
|
+ # let the audio subsystem loop it
|
|
|
|
|
+ if (self._seamlessLoop and self._soundPlaying and self.getLoop()
|
|
|
|
|
+ and not hasattr(self, '_inFinish')):
|
|
|
|
|
+ return
|
|
|
|
|
+ elif self.sound != None:
|
|
|
self.sound.stop()
|
|
self.sound.stop()
|
|
|
|
|
+ self._soundPlaying = False
|
|
|
self.currT = self.getDuration()
|
|
self.currT = self.getDuration()
|
|
|
self.state = CInterval.SFinal
|
|
self.state = CInterval.SFinal
|
|
|
|
|
|
|
|
def privInterrupt(self):
|
|
def privInterrupt(self):
|
|
|
if self.sound != None:
|
|
if self.sound != None:
|
|
|
self.sound.stop()
|
|
self.sound.stop()
|
|
|
|
|
+ self._soundPlaying = False
|
|
|
self.state = CInterval.SPaused
|
|
self.state = CInterval.SPaused
|
|
|
|
|
|
|
|
def loop(self, startT = 0.0, endT = -1.0, playRate = 1.0, stagger=False):
|
|
def loop(self, startT = 0.0, endT = -1.0, playRate = 1.0, stagger=False):
|
|
|
|
|
+ self.fLoop = 1
|
|
|
Interval.Interval.loop(self, startT, endT, playRate)
|
|
Interval.Interval.loop(self, startT, endT, playRate)
|
|
|
if stagger:
|
|
if stagger:
|
|
|
self.setT(random.random() * self.getDuration())
|
|
self.setT(random.random() * self.getDuration())
|