Multiple Objects with same sound


06-07-2007 20:24:46

I'm trying to attach a sound object to many projectiles. The projectiles constantly emit a windy sound so when they fly by the player, they make a whooshing sound.

In the constructor of the class representing the projectile I have:

OgreAL::SoundManager *soundManager;
soundManager = OgreAL::SoundManager::getSingletonPtr();
OgreAL::Sound *sound;
if (!soundManager->hasSound("9992"))
sound = soundManager->createSound("9992", "wind.wav", true);

sound = soundManager->getSound("9992");

However I get the error:
An exception has been thrown!
Error #: 4
Function: SceneNode::attachObject
Description: Object already attached to a SceneNode or a Bone.

I think what it's saying is I'm trying to attach a single sound node to many different projectiles. Is there an alternative solution that would give me the same effect?


06-07-2007 20:32:59

You would need to create multiple, unique instances that all source from the same sound file. OgreAL is smart enough to use the same sound buffer so this won't hog a bunch of memory, but you are not yet able to create more sources than your audio hardware allows.


09-07-2007 19:20:45

Thanks for the help. That makes a lot of sense. I'm kind of new to Ogre, so I'm not sure how to do that. How do I source from a single sound file from multiple objects? Because I thought that's what I was doing with the original code.

In my mind the code says:
-attach a sound to an object
-If any other object needs that sound, just grab it and play

So how would I modify my code to fit your solution?