[Question] Using seperate thread for sound updates

deshan

24-12-2009 05:40:05

Hi
If I use a seperate thread for updating

while(true)
{
mSoundManager->update(time);
}




Will It leads to strange output?

As I have heard that in games we can use multiple threads for handling graphics updatse, Phyiscs updates, Sound updates and AI updates.
I need your opinian.
If yes do you think how much frame rate is hould keep for mSoundManager updates.

stickymango

24-12-2009 09:51:05

Hi Deshan,

If your using the BOOST version of the lib ( OGGSOUND_THREADED= 1 ), which is the default, then the sound is already using multiple threads, you would still call SoundManager->update() in your main update function though, as all that function is doing is propogating any positional changes from the scenegraph to the sounds.

Unless you have lots of sounds, you probably won't notice any significant change in framerate, but you will benfit from the non-blocking feature of many of the audio function calls, meaning your app can carry on doing what it needs to. Also you'll be able to play audio in the background whilst loading scenes for example.

deshan

24-12-2009 14:16:12

but you will benfit from the non-blocking feature of many of the audio function calls, meaning your app can carry on doing what it needs to. Also you'll be able to play audio in the background whilst loading scenes for example.

Hi stickymango
Threaded version seems to be the best choice. I would go for it.

One more question
I really don't know about the BOOST threads. I can remember that I got an error while I am compiling with OGGSOUND_THREADED= 1.
So If I use separate threads is that OK?
Thanx for your support

stickymango

24-12-2009 21:20:54

I'd highly recommend using the threaded version of the library, read this topic about setting up with BOOST: viewtopic.php?f=19&t=8389

Any problems just post a query.

deshan

25-12-2009 07:02:38

Hi stickymango
The boost download that you have recommended http://www.boost-consulting.com/boost_1_34_1_setup.exe does not have
boost::this_thread or boost::posix_time
so it throw exception at this line
boost::this_thread::sleep(boost::posix_time::millisec(10)); in threadUpdate() function

Is this the patch?
static void threadUpdate()
{

struct boost::xtime timeout;
timeout.sec = 0;
timeout.nsec = 10;
while(!mShuttingDown)
{
OgreOggSoundManager::getSingleton()._updateBuffers();
OgreOggSoundManager::getSingleton()._processQueuedSounds();
//boost::this_thread::sleep(boost::posix_time::millisec(10));
boost::thread::sleep(timeout);

}
}


It just compiles without errors. seems OK for me.

EDIT : I have used the svn trunk
EDIT : No above won't be the patch. application is too damn slow :( . Still I need to know what's wrong with boost::this_thread or boost::posix_time

stickymango

25-12-2009 22:49:05

You could replace the boost sleep with windows Sleep(), otherwise use BOOST 1.38/1.40 and download thread and date_time and it should compile fine, I use 1.40 presently.