MonoGame / MonoGame

One framework for creating powerful cross-platform games.
http://www.monogame.net
Other
11.28k stars 2.9k forks source link

Missing ability to set rolloff factor in OpenAL #7532

Open Ellpeck opened 3 years ago

Ellpeck commented 3 years ago

MonoGame's SoundEffect class provides the DistanceScale value that claims to "get or set the scale of distance calculations", and that "higher values reduce the rate of falloff between the sound and listener." However, in the OpenAL implementation, it actually sets the reference distance property to this value. According to the OpenAL documentation, the reference distance is "the distance under which the volume for the source would normally drop by half (before being influenced by rolloff factor or AL_MAX_DISTANCE)."

It seems that a more fitting OpenAL property to use for DistanceScale would be the AL_ROLLOFF_FACTOR, which is used in calculations as a sort of distance scale property:

The AL_INVERSE_DISTANCE_CLAMPED model works according to the following formula:

distance = min(distance,AL_MAX_DISTANCE);
gain = AL_REFERENCE_DISTANCE / (AL_REFERENCE_DISTANCE +
AL_ROLLOFF_FACTOR *
(distance – AL_REFERENCE_DISTANCE)); 

Since OpenAL's reference distance has a different effect from the rolloff factor, and the latter cannot be changed in the current implementation, it doesn't seem like there is currently a way to change OpenAL's actual distance scale.

What version of MonoGame does the bug occur on:

What operating system are you using:

What MonoGame platform are you using:

mrhelmut commented 3 years ago

I've been looking into the OpenAL code lately, and there are definitely some caveats in regard to Apply3D() and ApplyFilters(). I'm expecting to look into improving the accuracy toward WindowsDX/XNA soon.

mrhelmut commented 2 years ago

OpenAL definitely is a dead-end when it comes to match the effect behaviors of WindowsDX/XNA. The best route of action is to replace OpenAL with a library which would allows that. As far as I've looked into that, FAudio seems to be the only candidate.