Original Post
EDIT: LESSON LEARNED: If you aint getting 3d sound, check that the sounds are in mono format and NOT in stereo. Took me a couple of hours to figure out! --original post-- I just got a hold of a Python binding for OpenAL. It has a very nice interface, just two classes, SoundEngine and SoundSource. The following program... ... does what you'd expect, namely it loops a sound, which is to the right in the beginning, but moves to the center and finally just sounds in the left speaker and becomes more and more vague. So I tried to implement a basic sound manager for my game based on that program. But, for some reason, the sounds don't change positions (and therefore always play at the same volume level). Since the program above works, I'm guessing that it is not the binding that is to blame, but something I'm doing in my code. Probably doing something in the wrong order, or something. Anyone experienced the same thing? Here is the class: setListenerPosition() gets called every frame, and the position argument is correct (I've checked). The pos parameter in playSound also checks out with the positions of the objects.. [Edited by - Srekel on August 7, 2005 8:20:20 AM]
import libal
eng = libal.SoundEngine(22000)
eng.SetListenerPosition(0,0,0)
s1 = libal.SoundSource("punch.wav")
s1.SetPosition(10,0,0)
s1.Play(True) ### play and loop
x = 1
while 1:
x += .0001
eng.SetListenerPosition(x,0,0)
class SoundManagerOpenAL:
def __init__(self):
### Initialize engine
### The parameter is currently a guess since no real
### documentation exists
self.soundEngine = libal.SoundEngine(22000)
self.soundEngine.SetListenerPosition(0, 0, 0)
self.pathToSounds = "../media/sounds/"
self.sounds = {}
print "SM: SOUNDMANAGER INITIALIZED!"
def setListenerPosition(self, pos):
self.soundEngine.SetListenerPosition(pos[X], pos[Y], pos[Z])
def addSound(self, name):
if name not in self.sounds.keys() and name is not None:
try:
self.sounds[name] = libal.SoundSource(self.pathToSounds + name)
self.sounds[name].SetPosition(1,1,1)
except:
print "SM: Could not add sound", name
def playSound(self, name, loop, pos):
if name is not None:
self.sounds[name].SetPosition(pos[X], pos[Y], pos[Z])
self.sounds[name].Play(loop)
else:
print "SM: Can not play None-sound!"