[OpenAL] Ambient music - what position?

Started by
20 comments, last by Kenbar 18 years, 7 months ago
Hi all, Was wondering when dealing with 3d sound in openal, where you position music you want to be at a constant volume (ie ambient noises like rain, music that doesn't change as you move listener around, etc). I guess for ambient music you just constantly update the position of the sound to be a little behind the listener? Or at the same spot? Cheers, Paul
Anything posted is personal opinion which does not in anyway reflect or represent my employer. Any code and opinion is expressed “as is” and used at your own risk – it does not constitute a legal relationship of any kind.
Advertisement
What I try to do is break up the ambient noise into individual sounds (e.g. crickets, water splashing, etc..) and place them each where they would make sense (e.g. in grass, by a pool, etc..)

I'm not too familiar with OpenAL, but is there a way to play audio without it's volume being attenuated based on it's position?
pixelwrench.com | [email="matt[nospam]@pixelwrench[nospam]com"]email[/email] lethalhamster: gamedev keeps taking my money, but im too lazy to not let them
In OpenAL, there are two ways you can make the ambient sound or music appear to be the same volume wherever the player is (other than using a stero sample, which, the last time I checked anyway, couldn't be played positionally in AL, so appears omnipresent whatever you do).

The first is to set the source position relative to the player with the following call:

alSourcei(alSourceID, AL_SOURCE_RELATIVE, AL_TRUE);alSource3f(alSourceID, AL_POSITION, 0.0f, 0.0f, 0.0f);


The relative call makes the position of the source relative to the listener, so in this case, with no offset, the source will seem to be omnipresent whereever you go. If you passed a source position of 1.0f, 0.0f, 0.0f, for example, the source would be played to the left (or right depending ;) ) wherever the player moves to.

I'm pretty sure the above is the most commonly used way of doing it (thats what I use anyway;) ).

Another is, as you have said, to constantly change the sources position as the players position moves. But this, when compared to the above method, seems a bit OTT.

Changing the source's attenuation will not make the sound omnipresent. If you made a call to remove all attenuation from the source with

alDistanceModel(AL_NONE);


this would stop the sound from going quieter as the player moved away, but it would still be positional. So if you moved to the left, the sound would only come through the right speaker, and would be the same volume no matter how far you moved away.

Hope that helps some
Spree
When I designed an audio engine for a project, I got around these concepts by creating different classes of sound - ie, there was 3D sound generated within the game world, like a gunshot, ambient sound defined in the game world, like, say, water running from a tap, and then there was what I called "HUD sounds". Sounds that were generated by the game world, but not processed in 3D. Things like the sounds of the HUD beeps, universal sound ("The Game will be over in 2 minutes"), and omnipresent "everybody hears it" sounds, which are not processed in 3D space, but instead in 2D in the client of each player.

That was just my take. It was mainly my way of defining what sounds would be created and heard within the multi-player world, like a footstep or gunshot, and what sounds were "personal", ie, never intended to be considered in the 3D space.

I suppose you could treat music and omnipresent ambience that way, in my structure. I dont know how people typically structure their audio engines. It was just me coming up with a classification system.
Something strange happends when y play Stereo Ogg music with openal and try to move the source dinamically, the strange thing is that it doesnt move...but if i change the music into MONO ogg, it works....does anybody knwo why is that?
Quote:Original post by hoofmen
Something strange happends when y play Stereo Ogg music with openal and try to move the source dinamically, the strange thing is that it doesnt move...but if i change the music into MONO ogg, it works....does anybody knwo why is that?


Stereo samples will not play positionally in OpenAL, only mono samples can. I'm not sure why, but I assume its because of the underling technology, and not a consious decision on OpenAL's part.

It really isnt a problem though. If you could play a stereo sample positionally, you wouldn't get the benifits of stereo sound anyway, it would sound just like a mono sample.

Spree
Quote:Original post by hoofmen
Something strange happends when y play Stereo Ogg music with openal and try to move the source dinamically, the strange thing is that it doesnt move...but if i change the music into MONO ogg, it works....does anybody knwo why is that?


The problem is: what would you expect to happen?
OpenAL does not support stereo samples in 3D because what it should do is hard to define in 3D. a single sound can be adjusted by placement and distance but a stereo sound already has different sounds specified for your left/right channels, so what would happen if it moved to the left?
Props to all that replied. [grin]

One more quick question which I will no doubt find out myself soon enough - does openal throw any sort of exception if you try and position a stereo sample in 3d? Or does it just ignore the request?

And as I have a few OpenAL gurus attention in this thread, may be you know if there is any strategy that should be taken incase OpenAL looses a device, or any error to check for? I've managed to get several openal implementations to stop working if I ctrl+alt+del, then bring up the task manager (2k) a few times. See thread http://www.gamedev.net/community/forums/topic.asp?topic_id=336537

Cheers!
Anything posted is personal opinion which does not in anyway reflect or represent my employer. Any code and opinion is expressed “as is” and used at your own risk – it does not constitute a legal relationship of any kind.
If you attempt to play a stereo sample positionally, OpenAL will not throw an exception or crash, it will just play it, without any positional info. So if you have a stero music file, you could play it anywhere in the world, and it would still come out of both speakers.

As for your losing device. I'm afraid I am going to have to go along with the replies to your previous thread, and say its never happened to me either. I have ctr-alt-del and alt-tabbed out of applications (both windowed and full screen) and never had this error. I was under the impression that OpenAL is not meant to suffer from lost devices.

I have just had a quick look through the AL specification (both 1.0 and 1.1) and there is no discussion about lost devices their either.

If you don't get a satisfactory reply on here, subscribe to the OpenAL Mailing List, the help on there is usually top notch, especially from Garin Hiebert.

Spree
From what you've said you won't be able to do this in OpenAL, but other engines have a nice panning feature for stereo sources whereby when you are close to the source you have wide stereo but as you move away it is reduced to mono for greater directionality.

This topic is closed to new replies.

Advertisement