changes for new audio

This commit is contained in:
Dave Schuyler 2001-07-11 00:04:46 +00:00
parent fdaaef70c3
commit c99ef1337b
3 changed files with 44 additions and 46 deletions

View File

@ -32,10 +32,10 @@ class SoundInterval(Interval):
if duration == 0.0:
if self.wantSound:
duration = self.sound.length()
if (duration == 0):
self.notify.warning('zero length duration!')
# MPG - hack for Miles bug
duration += 1.5
if (duration == 0):
self.notify.warning('zero length duration!')
# MPG - hack for Miles bug
duration += 1.5
else:
# This will screw up any intervals that base their
# time on the duration of this sound interval
@ -61,7 +61,7 @@ class SoundInterval(Interval):
# Update sound based on current time
if (t >= self.getDuration()):
# If end of sound reached or stop event received, stop sound
AudioManager.stop(self.sound)
self.sound.stop()
self.ignore(self.stopEvent)
elif (event == IVAL_INIT):
# IVAL_INIT event, start new sound
@ -70,10 +70,12 @@ class SoundInterval(Interval):
if (t < 0.1):
t = 0.0
# Start sound
AudioManager.play(self.sound, t, self.loop)
self.sound.setTime(t)
self.sound.setLoop(self.loop)
self.sound.play()
# Accept event to kill sound
self.acceptOnce(self.stopEvent,
lambda s = self: AudioManager.stop(s.sound))
lambda s = self: s.sound.stop())
# Print debug information
self.notify.debug('updateFunc() - %s: t = %f' % (self.name, t))

View File

@ -85,10 +85,10 @@ class Loader:
return ModelPool.loadModel(modelPath)
def unloadModel(self, modelPath):
"""unloadModel(self, string)
"""
Loader.notify.debug("Unloading model: %s" % (modelPath))
ModelPool.releaseModel(modelPath)
"""unloadModel(self, string)
"""
Loader.notify.debug("Unloading model: %s" % (modelPath))
ModelPool.releaseModel(modelPath)
# font loading funcs
def loadFont(self, modelPath, priority = 0):
@ -132,10 +132,10 @@ class Loader:
return texture
def unloadTexture(self, texture):
"""unloadTexture(self, texture)
"""
"""unloadTexture(self, texture)
"""
Loader.notify.debug("Unloading texture: %s" % (texture) )
TexturePool.releaseTexture(texture)
TexturePool.releaseTexture(texture)
# sound loading funcs
def loadSound(self, soundPath):
@ -145,13 +145,13 @@ class Loader:
Loader.notify.debug("Loading sound: %s" % (soundPath) )
if phaseChecker:
phaseChecker(soundPath)
sound = AudioPool.loadSound(soundPath)
sound = base.effectsAudioManager.getSound(soundPath)
return sound
def unloadSound(self, sound):
"""unloadSound(self, sound)
"""
"""unloadSound(self, sound)
"""
if sound:
Loader.notify.debug("Unloading sound: %s" % (sound) )
AudioPool.releaseSound(sound)
del sound

View File

@ -37,9 +37,10 @@ class ShowBase:
self.wantTk = self.config.GetBool('want-tk', 0)
self.wantAnySound = self.config.GetBool('want-sound', 1)
if not self.wantAnySound:
AudioManager.setAllSoundActive(0)
self.wantSfx = AudioManager.getSfxActive()
self.wantMusic = AudioManager.getMusicActive()
self.effectsAudioManager.setActive(0)
self.musicAudioManager.setActive(0)
self.wantSfx = self.config.GetBool('audio-sfx-active', 1)
self.wantMusic = self.config.GetBool('audio-music-active', 1)
if not (self.wantSfx or self.wantMusic):
self.wantAnySound = None
self.wantDIRECT = self.config.GetBool('want-directtools', 0)
@ -275,61 +276,56 @@ class ShowBase:
def createAudioManager(self):
if self.wantAnySound:
AudioManager.spawnUpdate()
self.effectsAudioManager = AudioManager.createAudioManager()
self.musicAudioManager = AudioManager.createAudioManager()
def loadSfx(self, name):
if (name and base.wantSfx):
sound=loader.loadSound(name)
if sound:
sound.setCategory(sound.EFFECT)
sound=self.effectsAudioManager.getSound(name)
return sound
def loadMusic(self, name):
if (name and base.wantMusic):
sound=loader.loadSound(name)
if sound:
sound.setCategory(sound.MUSIC)
sound=self.musicAudioManager.getSound(name)
return sound
def unloadSfx(self, sfx):
if sfx:
loader.unloadSound(sfx)
del sfx
def unloadMusic(self, music):
if music:
loader.unloadSound(music)
del music
def playSfx(self, sfx, looping = 0, interupt = 1, volume = None,
time = 0.):
if (sfx and base.wantSfx):
if not interupt:
if not (sfx.status() == AudioSound.PLAYING):
AudioManager.play(sfx, time, looping)
else:
AudioManager.play(sfx, time, looping)
if volume:
AudioManager.setVolume(sfx, volume)
if volume != None:
sfx.setVolume(volume)
if interupt or (sfx.status() != AudioSound.PLAYING):
sfx.setTime(time)
sfx.setLoop(looping)
sfx.play()
def playMusic(self, music, looping = 0, interupt = 1, volume = None,
restart = None, time = 0.):
if (music and base.wantMusic):
if not interupt:
if not (music.status() == AudioSound.PLAYING):
AudioManager.play(music, time, looping)
else:
AudioManager.play(music, time, looping)
if volume:
AudioManager.setVolume(music, volume)
if interupt or (music.status() != AudioSound.PLAYING):
music.setTime(time)
music.setLoop(looping)
music.play()
if volume != None:
music.setVolume(volume)
if restart:
restart[0].accept("restart-music", restart[1])
def stopSfx(self, sfx):
if (sfx and base.wantSfx):
AudioManager.stop(sfx)
sfx.stop()
def stopMusic(self, music, restart = None):
if (music and base.wantMusic):
AudioManager.stop(music)
music.stop()
if restart:
restart[0].ignore("restart-music")