mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-05 11:28:17 -04:00
changes for new audio
This commit is contained in:
parent
fdaaef70c3
commit
c99ef1337b
@ -61,7 +61,7 @@ class SoundInterval(Interval):
|
|||||||
# Update sound based on current time
|
# Update sound based on current time
|
||||||
if (t >= self.getDuration()):
|
if (t >= self.getDuration()):
|
||||||
# If end of sound reached or stop event received, stop sound
|
# If end of sound reached or stop event received, stop sound
|
||||||
AudioManager.stop(self.sound)
|
self.sound.stop()
|
||||||
self.ignore(self.stopEvent)
|
self.ignore(self.stopEvent)
|
||||||
elif (event == IVAL_INIT):
|
elif (event == IVAL_INIT):
|
||||||
# IVAL_INIT event, start new sound
|
# IVAL_INIT event, start new sound
|
||||||
@ -70,10 +70,12 @@ class SoundInterval(Interval):
|
|||||||
if (t < 0.1):
|
if (t < 0.1):
|
||||||
t = 0.0
|
t = 0.0
|
||||||
# Start sound
|
# 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
|
# Accept event to kill sound
|
||||||
self.acceptOnce(self.stopEvent,
|
self.acceptOnce(self.stopEvent,
|
||||||
lambda s = self: AudioManager.stop(s.sound))
|
lambda s = self: s.sound.stop())
|
||||||
# Print debug information
|
# Print debug information
|
||||||
self.notify.debug('updateFunc() - %s: t = %f' % (self.name, t))
|
self.notify.debug('updateFunc() - %s: t = %f' % (self.name, t))
|
||||||
|
|
||||||
|
@ -145,7 +145,7 @@ class Loader:
|
|||||||
Loader.notify.debug("Loading sound: %s" % (soundPath) )
|
Loader.notify.debug("Loading sound: %s" % (soundPath) )
|
||||||
if phaseChecker:
|
if phaseChecker:
|
||||||
phaseChecker(soundPath)
|
phaseChecker(soundPath)
|
||||||
sound = AudioPool.loadSound(soundPath)
|
sound = base.effectsAudioManager.getSound(soundPath)
|
||||||
return sound
|
return sound
|
||||||
|
|
||||||
def unloadSound(self, sound):
|
def unloadSound(self, sound):
|
||||||
@ -153,5 +153,5 @@ class Loader:
|
|||||||
"""
|
"""
|
||||||
if sound:
|
if sound:
|
||||||
Loader.notify.debug("Unloading sound: %s" % (sound) )
|
Loader.notify.debug("Unloading sound: %s" % (sound) )
|
||||||
AudioPool.releaseSound(sound)
|
del sound
|
||||||
|
|
||||||
|
@ -37,9 +37,10 @@ class ShowBase:
|
|||||||
self.wantTk = self.config.GetBool('want-tk', 0)
|
self.wantTk = self.config.GetBool('want-tk', 0)
|
||||||
self.wantAnySound = self.config.GetBool('want-sound', 1)
|
self.wantAnySound = self.config.GetBool('want-sound', 1)
|
||||||
if not self.wantAnySound:
|
if not self.wantAnySound:
|
||||||
AudioManager.setAllSoundActive(0)
|
self.effectsAudioManager.setActive(0)
|
||||||
self.wantSfx = AudioManager.getSfxActive()
|
self.musicAudioManager.setActive(0)
|
||||||
self.wantMusic = AudioManager.getMusicActive()
|
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):
|
if not (self.wantSfx or self.wantMusic):
|
||||||
self.wantAnySound = None
|
self.wantAnySound = None
|
||||||
self.wantDIRECT = self.config.GetBool('want-directtools', 0)
|
self.wantDIRECT = self.config.GetBool('want-directtools', 0)
|
||||||
@ -275,61 +276,56 @@ class ShowBase:
|
|||||||
|
|
||||||
def createAudioManager(self):
|
def createAudioManager(self):
|
||||||
if self.wantAnySound:
|
if self.wantAnySound:
|
||||||
AudioManager.spawnUpdate()
|
self.effectsAudioManager = AudioManager.createAudioManager()
|
||||||
|
self.musicAudioManager = AudioManager.createAudioManager()
|
||||||
|
|
||||||
def loadSfx(self, name):
|
def loadSfx(self, name):
|
||||||
if (name and base.wantSfx):
|
if (name and base.wantSfx):
|
||||||
sound=loader.loadSound(name)
|
sound=self.effectsAudioManager.getSound(name)
|
||||||
if sound:
|
|
||||||
sound.setCategory(sound.EFFECT)
|
|
||||||
return sound
|
return sound
|
||||||
|
|
||||||
def loadMusic(self, name):
|
def loadMusic(self, name):
|
||||||
if (name and base.wantMusic):
|
if (name and base.wantMusic):
|
||||||
sound=loader.loadSound(name)
|
sound=self.musicAudioManager.getSound(name)
|
||||||
if sound:
|
|
||||||
sound.setCategory(sound.MUSIC)
|
|
||||||
return sound
|
return sound
|
||||||
|
|
||||||
def unloadSfx(self, sfx):
|
def unloadSfx(self, sfx):
|
||||||
if sfx:
|
if sfx:
|
||||||
loader.unloadSound(sfx)
|
del sfx
|
||||||
|
|
||||||
def unloadMusic(self, music):
|
def unloadMusic(self, music):
|
||||||
if music:
|
if music:
|
||||||
loader.unloadSound(music)
|
del music
|
||||||
|
|
||||||
def playSfx(self, sfx, looping = 0, interupt = 1, volume = None,
|
def playSfx(self, sfx, looping = 0, interupt = 1, volume = None,
|
||||||
time = 0.):
|
time = 0.):
|
||||||
if (sfx and base.wantSfx):
|
if (sfx and base.wantSfx):
|
||||||
if not interupt:
|
if volume != None:
|
||||||
if not (sfx.status() == AudioSound.PLAYING):
|
sfx.setVolume(volume)
|
||||||
AudioManager.play(sfx, time, looping)
|
if interupt or (sfx.status() != AudioSound.PLAYING):
|
||||||
else:
|
sfx.setTime(time)
|
||||||
AudioManager.play(sfx, time, looping)
|
sfx.setLoop(looping)
|
||||||
if volume:
|
sfx.play()
|
||||||
AudioManager.setVolume(sfx, volume)
|
|
||||||
|
|
||||||
def playMusic(self, music, looping = 0, interupt = 1, volume = None,
|
def playMusic(self, music, looping = 0, interupt = 1, volume = None,
|
||||||
restart = None, time = 0.):
|
restart = None, time = 0.):
|
||||||
if (music and base.wantMusic):
|
if (music and base.wantMusic):
|
||||||
if not interupt:
|
if interupt or (music.status() != AudioSound.PLAYING):
|
||||||
if not (music.status() == AudioSound.PLAYING):
|
music.setTime(time)
|
||||||
AudioManager.play(music, time, looping)
|
music.setLoop(looping)
|
||||||
else:
|
music.play()
|
||||||
AudioManager.play(music, time, looping)
|
if volume != None:
|
||||||
if volume:
|
music.setVolume(volume)
|
||||||
AudioManager.setVolume(music, volume)
|
|
||||||
if restart:
|
if restart:
|
||||||
restart[0].accept("restart-music", restart[1])
|
restart[0].accept("restart-music", restart[1])
|
||||||
|
|
||||||
def stopSfx(self, sfx):
|
def stopSfx(self, sfx):
|
||||||
if (sfx and base.wantSfx):
|
if (sfx and base.wantSfx):
|
||||||
AudioManager.stop(sfx)
|
sfx.stop()
|
||||||
|
|
||||||
def stopMusic(self, music, restart = None):
|
def stopMusic(self, music, restart = None):
|
||||||
if (music and base.wantMusic):
|
if (music and base.wantMusic):
|
||||||
AudioManager.stop(music)
|
music.stop()
|
||||||
if restart:
|
if restart:
|
||||||
restart[0].ignore("restart-music")
|
restart[0].ignore("restart-music")
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user