# HG changeset patch # User prock@33b003aa-7bff-0310-803a-e67f0ece8222 # Date 1273873256 0 # Node ID 6614a54463527b527414f6492588f6f9aca0fbfa # Parent 5e6ff32a46fba96add4a4564327ba64d1444df1d Positional sounds now work. There are some odd things happening when the sound does not have positional data and I assign the listeners position to the emitters position. There is a little more work required here. diff -r 5e6ff32a46fb -r 6614a5446352 engine/python/fife/extensions/soundmanager.py --- a/engine/python/fife/extensions/soundmanager.py Fri May 14 20:28:05 2010 +0000 +++ b/engine/python/fife/extensions/soundmanager.py Fri May 14 21:40:56 2010 +0000 @@ -192,6 +192,8 @@ self._fifesoundmanager = self._engine.getSoundManager() self._fifesoundmanager.init() + + self._fifesoundmanager.setListenerOrientation(0,1,0) # basic rolloff used for positional sounds self._rolloff = 1 @@ -272,13 +274,21 @@ if clip.looping: repeat = 0 - def real_callback(c, e, g): - c() - e.stop() - e.setGain(float(g)/255.0) - e.play() + def real_callback(clip): + clip.callback() + clip.fifeemitter.stop() + clip.fifeemitter.setGain(float(clip.gain)/255.0) + if self.listenerposition and clip.position: + # Use 1 as z coordinate, no need to specify it + clip.fifeemitter.setPosition(clip.position[0], clip.position[1], 1) + clip.fifeemitter.setRolloff(clip.rolloff) + elif self.listenerposition and not clip.position: + clip.fifeemitter.setPosition(self._listenerposition[0], self._listenerposition[1], 1) + clip.fifeemitter.setRolloff(self.rolloff) + + clip.fifeemitter.play() - clip.callback = cbwa(real_callback, clip.callback, clip.fifeemitter, clip.gain) + clip.callback = cbwa(real_callback, clip) else: repeat = 1 @@ -287,12 +297,20 @@ else: if clip.looping: - def real_callback(e, g): - e.stop() - e.setGain(float(g)/255.0) - e.play() + def real_callback(clip): + clip.fifeemitter.stop() + clip.fifeemitter.setGain(float(clip.gain)/255.0) + if self.listenerposition and clip.position: + # Use 1 as z coordinate, no need to specify it + clip.fifeemitter.setPosition(clip.position[0], clip.position[1], 1) + clip.fifeemitter.setRolloff(clip.rolloff) + elif self.listenerposition and not clip.position: + clip.fifeemitter.setPosition(self._listenerposition[0], self._listenerposition[1], 1) + clip.fifeemitter.setRolloff(self.rolloff) + + clip.fifeemitter.play() - clip.callback = cbwa(real_callback, clip.fifeemitter, clip.gain) + clip.callback = cbwa(real_callback, clip) clip.timer = fife_timer.Timer(clip.duration, clip.callback, 0) clip.fifeemitter.setGain(float(clip.gain)/255.0) @@ -302,7 +320,7 @@ clip.fifeemitter.setPosition(clip.position[0], clip.position[1], 1) clip.fifeemitter.setRolloff(clip.rolloff) elif self.listenerposition and not clip.position: - clip.fifeemitter.setPosition(self.listenerposition[0], self.listenerposition[1], 1) + clip.fifeemitter.setPosition(self._listenerposition[0], self._listenerposition[1], 1) clip.fifeemitter.setRolloff(self.rolloff) clip.fifeemitter.play() @@ -358,7 +376,7 @@ def _setListenerPosition(self, position): self._listenerposition = position - self._fifesoundmanager.setListenerPosition(self._listenerposition[0], self._listenerposition[1], 1) + self._fifesoundmanager.setListenerPosition(self._listenerposition[0], self._listenerposition[1], 10) rolloff = property(_getRolloff, _setRolloff) listenerposition = property(_getListenerPosition, _setListenerPosition)