Multiple Cameras = Multiple Listeners?

frier

02-11-2007 07:56:36

Hi, ive just started using OgreAL.

I was reading that a Listener in OgreAL is used to determine distance between itself and other audio devices, so it can achieve a Doppler affect, have i understood this correctly?

My problem is i have up to 4 cameras in my game running at one time, so does this mean i need 4 different Listeners attached to the 4 different camera nodes? how do i do this?

i tried to use createListener but it says i shouldn't use it directly.

Aquatix

02-11-2007 14:05:30

Hi, frier!
Actually there can only be 1 Listener at any given time. And, why would you want more anyway? Even if you have 100 cameras active, still you just attach the listener to the camera which is responsible for you main "eye" view.

frier

02-11-2007 15:09:54

Hi Aquatix, thanks for replying, yes i have about 4 active cameras, look at the following.


Id assume i need 4 listeners for each active camera? how would i setup OgreAL to suit this type of camera system?

<excuse me, GUI looks a bit messy ATM, just trying some stuff out :S>

CaseyB

02-11-2007 16:23:58

firstly, let me say that your game is looking pretty sweet! Secondly, the fact that OgreAL::Listener is a singleton is based on the fact that OpenAL only supports a single listener per context. This is from the OpenAL Programmer's Guide:
Use of OpenAL revolves around the use of three fundamental objects – Buffers, Sources, and a Listener. A buffer can be filled with audio data, and can then be attached to a source. The source can then be positioned and played. How the source is heard is determined by its position and orientation relative to the Listener object (there is only one Listener). Creating a number of sources and buffers and a single listener and then updating the positions and orientations of the sources and listener dynamically can present a convincing 3D audio world.
Objects
Here is a diagram showing the fundamental OpenAL objects and their relationships to the context and device objects:

When initializing OpenAL, at least one device has to be opened. Within that device, at least one context will be created. Within that context, one listener object is implied, and a multitude of source objects can be created. Each source can have one or more buffers objects attached to it. Buffer objects are not part of a specific context – they are shared among all contexts on one device.

OgreAL doesn't support multiple contexts, never really thought about it actually, but seeing how you are looking to use sounds it seems like it really should, somehow. What you're going to need to do is create a context for each player camera and have the listener for that context follow that camera. I am sorry to say that OgreAL can't help you here, other than being a reference for setting up OpenAL.

Aquatix

02-11-2007 19:05:25

Just a suggestion - maybe use 1 listener and then just apply the sounds to the same node, where the listener is. Since you have 4 players (right?), then there is not much you can do to provide 100% realistic 3d audio output for them (unless they all wear headphones and the sound card supports 4 channels). So, basically there isn't even a need to have 4 separate listeners, just have 1 "abstract" listener to simulate the sounding.
P.S. the game looks really sweet! Feels like a mix of the old school arcade with the modern tech.

CaseyB

02-11-2007 21:05:57

I am thinking about making the SoundManager not a singleton and each SoundManager will have a context, so there will be 1 Listener per SoundManager, and each Sound Manager would have different Sounds. This means that the SoundManager would need a static reference to the device. This isn't going to happen for a while since it's a breaking change, there are a lot of other things that need to be done for the next release, then I'll make this change in SVN.

frier

03-11-2007 05:00:07

First of all thanks for your kind words about our game, there are only 2 of us making it and we're game development students from Australia and enjoying it very much.

CaseyB

ok i see the problem now from that informative OpenAL blurb you posted, i actually need these "contexts".

I am thinking about making the SoundManager not a singleton and each SoundManager will have a context,

I was going try that, though it says i only can have one sound manager somewhere, but... Does OgreAL stop me from making more? i was worried that sounds from 1 sound manager wont transmitt into another sound manager, if you know what i mean, BUT i just read this part


Buffer objects are not part of a specific context – they are shared among all contexts on one device.


so the sounds can be used through out all contexts, butttt the "sources" wont be all the same throughout all the soundmanagers, so id have to update 4 sound managers.(im just thinking out loud i guess, im pretty newby when it comes to sound)

Aquatix

Yeah this sounds like what i might have to do, i dont have much time and I'm coding everything solo right now.

1) Create Node
2) Create listener, Attach listener to Node
3) Delicious Cake

Guess thats how i see it anyways, all the sound will sound like its just there in front of you, but thats fine for now, i guess id just be just missing out on Doppler effects as the bugs ride past(our games about cybernetic racing bugs). i dont see many other downfalls?

General Question
Another Quick Question, i need to change the cars motors pitch as it increases speed, how would i do this.I guess i need to change the pitch of individual sounds, but how?(is this part of the doppler effect)

Thanks for your help guys!

-FrieR

CaseyB

03-11-2007 05:19:50

The Doppler Effect only happens when they go whizzing by, to change the pitch you can call Sound::setPitch(). You can't create multiple SoundManagers at the moment, so you would need to either use the trick that Aquatix suggested or do a good bit of the sound code yourself.

I am really glad you brought this up though, it will help me make OgreAL even more flexible.