Question

For the love of everything, I have been at this for three hours.

OpenAL, when I move the listener, completely breaks the attenuation. I have NO idea why.

If I do not change listener settings, it works fine. But unfortunately, that is not a viable solution in a 3d game.

I have tried everything from normalizing the positions and velocities of all sound making components, to manually setting all of the attenuation settings. But changing any setting on the listener, without fail, always breaks the attenuation. I will hear sounds that are 100's of units away from me if I move the listener, as if its position has no effect.

I have even used the alGet parameters to check and see if the values are going through correctly. They are.

Each unit in the game is 1x1, so in many cases two entities will be around 100 units apart.

    alListener3f(AL_POSITION, pos.x, pos.y, pos.z);
    alListener3f(AL_VELOCITY, vel.x, vel.y, vel.z);
    alListener(AL_ORIENTATION, system.listener.getOrientationBuffer());
    alListenerf(AL_GAIN, system.listener.getMasterGain());

That is all the code in charge of changing the listener. The Master gain is 0.5f as instructed and the sounds themselves are 0.5 as well. The distance model is AL_LINEAR_DISTANCE_CLAMPED, and the reference distance is 1f, and the max distance is 2f. Still, the attenuation does not work and placement makes no difference. When in LINEAR_DISTANCE_CLAMPED mode, the distances do not work regardless. If I leave it as the default model, it will atleast work when I do not move the listener.

The orientation has been left as default (0, 0, -1f, 0, 1f, 0f)

No, my sound drivers are fine and this computer was built less than a month ago with the newest parts.

And yes, the sounds are in mono format.

Someone please help me.

Was it helpful?

Solution

I finally managed to solve my problem after some experimentation.

Setting a rolloff value that is below 1f seems to keep the sound from fading out after setting the max distance. You'll also want to make sure you're properly setting up your orientation to match your coordinate system; luckily mine was already designed to work with the default one, but be sure you do that. It's very important.

So, to make sure attenuation works correctly with reference and max angles, do the following:

  1. Set your distance model to AL_LINEAR_DISTANCE_CLAMPED
  2. Set your listener data to the correct values (orientation is fully set up)
  3. Make sure your rolloff is 1f on the source
  4. Set the reference and max distances however you want on the source
  5. MAKE SURE the listener gain is not 0f or 1f, only in between. This does not count for sounds though, they can be 0f and 1f. 0f means "master sound is 0" and 1f means "no attenuation" for the listener.

That should be it.

Also, I've seen some talk during my studies of having to normalize your coordinates. It actually doesn't matter, as OpenAL doesn't expect you to do this (you can find this in the documentation around the bottom of page 32)

I hope I've helped someone else by clarifying all of these. Good luck on your own work, internet strangers.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top