Python-OGRE + OGREAL: sound just stops


28-07-2008 22:58:04

Ok, I'm sure this really should be quite easy but I have been butting my head against it for a few days now. Probably I'm just approaching this the wrong way, but all I want to do is play a sound when a certain event happens; in this case, a mouse click. The thing is, it works just fine and plays the sound, but always stops after 100 plays. I assume this has something do with soundManager.maxSources being 100, but apparently using self.soundManager.destroySound(sound) doesn't do clear this out / do garbage collection the way I thought it did.

Basically here's the deal:


import ogre.sound.OgreAL as OgreAL
from Game.Audio import SFX

def __init__(self):
self.soundManager = OgreAL.soundManager()
self.sfx = SFX(self.soundManager)

def mouseClick(self, evt, buttonID):
soundFile = "sound.ogg"


class SFX(object):
def __init__(self, soundManager):
self.soundManager = soundManager

def play(self, soundFile):
s = self.soundManager.createSound("sfx", soundFile, False, False)

If I don't destroySound(s) the thing of course crashes after the first mouseClick, because the sound "sfx" already exists. However, even with destroying the sound it stops playing the sound (no crashing, just silence) after exactly 100 mouse clicks. I assume I'm doing something stupid here since I'm a n00b, but I can't figure out what it is! Ideas?


29-07-2008 09:11:01

Have you compiled OgreAL with threading enabled? the threaded version doesn't actually destroy any sounds at all, there's a bug there. Also where you have:def play(self, soundFile):
s = self.soundManager.createSound("sfx", soundFile, False, False)

would usually result in the sound not playing because play() does not block until it finishes, it would play() then destroy() in the next update, they're basically flag functions which actually get handled in the internal _update() function. It would start to play the sound but immediately destroy it, you would need to to test for end before calling destroySound().



29-07-2008 17:05:27

Actually I didn't compile it at all, as I don't have much in the way of dev tools on Windows. However, after trying a few things in the API documentation I figured out that adding


at the end seemed to do the trick.

Interestingly it plays fine, although now I seem to be having an issue similar to what another poster described here where there are two possible sound events (in this case, one for the firing and one for when a target is hit) and the "target hit" sound is occasionally playing in place of the "fire" sound if I click too fast. I may be able to work around that, though. I will also go ahead and throw in a test for end before the destroySound() and _releaseSource() for the sake of cleanliness.


29-07-2008 18:31:48

I posted a code snippet to hopefully correct that problem in the post, I'd recommend downloading the latest source code and compiling OgreAL yourself so you can debug/ammend it yourself, there are a few little bugs with it need patching in oreder to get it working reliably.

Download Visual C++ express as its free and get compiling...