ensure sounds aren't played past their duration

This commit is contained in:
David Rose 2004-01-06 20:46:57 +00:00
parent 7935486194
commit d787afb6a4
2 changed files with 21 additions and 4 deletions

View File

@ -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

View File

@ -314,6 +314,16 @@ get_loop_count() const {
void MilesAudioSound::
set_time(float time) {
miles_audio_debug("set_time(time="<<time<<")");
// Ensure we don't inadvertently run off the end of the sound.
float max_time = length();
if (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);
}