Streaming audio with Ogre + discussion about threads.
Posted: Mon Jul 07, 2014 12:35 pm
Hi everyone.
I'm not really sure whether this should be in Ogre Help or non-Ogre help. I'm going to go with non-Ogre help.
I've managed to get a grip on streaming audio with Ogg Vorbis and OpenAL, and I was looking for some opinions on the best way to integrate that into Ogre.
As far as I can see it, my options are:-
(1) Do it quick and dirty, call my stream's update function from my Ogre handler class' frameRenderingQueued().
(2) Create my own implementation of FrameListener to handle my audio stream, register it with Ogre::Root and use its frameRenderingQueued() function to call the stream update.
(3) Run them in separate threads.
Every fibre of my programming instinct rejects option 1, not least because my Ogre handler class shouldn't know anything about audio streams.
I'm thinking I might have to do both 2 and 3. Updating the stream in my render thread maybe wouldn't be such a big deal (depending on how big my stream buffer is?), but if I'm going to need another thread anyway for playing the stream, it would make sense to update the stream in that thread, too. Is that right? But if I'm running it in a separate thread, is there any point in even using a FrameListener? I was never very confident with threads even in Java, and I've never actually used them in C++ (I have in C, but that was (a) once, (b) a long time ago and only half-remembered, and (c) on Solaris, using POSIX threads which Windows doesn't support natively), so any advice would be welcome.
Or am I completely on the wrong track? What did (the now-seemingly-defunct?) OgreAL do?
Thanks.
BTW: I have to admit I have done this a bit backwards, and learned about streaming before learning about loading sounds in their entirety.
I'm not really sure whether this should be in Ogre Help or non-Ogre help. I'm going to go with non-Ogre help.
I've managed to get a grip on streaming audio with Ogg Vorbis and OpenAL, and I was looking for some opinions on the best way to integrate that into Ogre.
As far as I can see it, my options are:-
(1) Do it quick and dirty, call my stream's update function from my Ogre handler class' frameRenderingQueued().
(2) Create my own implementation of FrameListener to handle my audio stream, register it with Ogre::Root and use its frameRenderingQueued() function to call the stream update.
(3) Run them in separate threads.
Every fibre of my programming instinct rejects option 1, not least because my Ogre handler class shouldn't know anything about audio streams.
I'm thinking I might have to do both 2 and 3. Updating the stream in my render thread maybe wouldn't be such a big deal (depending on how big my stream buffer is?), but if I'm going to need another thread anyway for playing the stream, it would make sense to update the stream in that thread, too. Is that right? But if I'm running it in a separate thread, is there any point in even using a FrameListener? I was never very confident with threads even in Java, and I've never actually used them in C++ (I have in C, but that was (a) once, (b) a long time ago and only half-remembered, and (c) on Solaris, using POSIX threads which Windows doesn't support natively), so any advice would be welcome.
Or am I completely on the wrong track? What did (the now-seemingly-defunct?) OgreAL do?
Thanks.
BTW: I have to admit I have done this a bit backwards, and learned about streaming before learning about loading sounds in their entirety.