3D Sound in the environment


15-05-2008 10:53:13


I know, it has been asked several times before, but even after searching through the forum i didn't get an good answere.

The problem is, that when i set a sound in the environment and attach it to a scenenode, it works fine, but it fades away very slowly, so i have to go really very far away to get it to the point, that i nearly can't hear it.

I used the same standart code like in the example.
My Unit scale is 1meter=1unit.
Can anybody tell me with a few lines of code, how i can create a sound, that is at the Position of a scenenode (let's say scenenode with the name node and with the position Vector3(10,10,10) ) and i want, that when the listener is 10 meters away, you can't hear it anymore. In between the sound should fade out.

I tried several parameters for rollof, refdistance and maxdistance but could't figure out fitting parameters.

Another question is: when i am too far from the source (let's say in the example 12 meters away) is the sound then cutted off, so, that it isn't calculated or transmitted to the soundcard anymore or do i have to make this on my own ?

Thank ou for your help.


15-05-2008 12:34:28

Its not easy to find parameters that fit unfortunately, I'm sure you can eventually find something that may work OK but thats about the best you can do. What I did was amend OgreAL to linearly scale the gain based on the min/max distances and it also handled starting/stopping the sound file to prevent wasted resources.

In DirectSound theres a flag for stopping a sound consuming resources beyond its max distance, however OgreAL doesn't seem to expose it so you can't set it. In any case it would likely cause noticeable cutting in/out of sound files unless you can work out the correct falloff parameters.

My advice would be to subclass/extend the OgreALSound class to handle fading on its own using whatever falloff method you need, linear works just perfect for me and is simple to use.



28-05-2008 19:28:03


I faced the same problem, and i ended up by changing the distance model to a linear one, as stickymango advised. With this, you can set the ReferenceDistance to 0 and the MaxDistance to the value you want to hear the sound. This will fade in a linear fashion between your sound source and your listener. Here is a code sample:

// Change the distance model for the current context

Sound* sound = soundManager->createSound("roar", "roar.wav", true);

// Lowest distance where the sound should start to fade out.
// For example, if you set it to 1000, the sound volume will stay to its maximum between 0 and 1000, and then will
// fadeout between 1000 and 2000.

// Maximum distance for the sound to be heard

I hope this help.


29-05-2008 12:13:52

Ah yes, I remember that there was various distance models within OpenAL but they weren't exposed through OgreAL, using a linear distance model as suggested should do the trick.