- Home /
[Unity 3] Logarithmic volume curve
In the AudioSource inspector, changing the distances for rolloff relative to the defaults can result in the logarithmic curve having a 'y' value of significant magnitude at the max distance, which means the sound will stop abruptly when it goes out of range rather than fading out smoothly.
In the inspector you can adjust the curve to match the new distances, but if you modify the distances via scripting, it seems in some cases you'll be stuck with a volume curve that causes the sound to stop abruptly when it goes out of range. Is this correct, or am I missing something?
This may be user error, and in any case it's certainly not that big a deal. But, I just wanted to make sure I wasn't missing anything before implementing a workaround.
Did you ever get your implementation working? If not, an example of the attempt or some kind of problem to solve would be helpful if you'd like an answer on it.
Answer by jakehawken · Mar 05, 2014 at 04:31 AM
I've been struggling with this exact issue for the last couple days.
I think the problem is that Unity uses amplitude and the human ear hears dB. Amp (the 0 to 1 volume system in Unity) is linear, while dB is logarithmic, so a linear fadeout in amp sounds like an inverse logarithmic curve to our ears.
Converting to dB with math also causes a problem because while Amp has 1 as full volume and 0 as complete silence, dB has 0 as full volume and negative infinity as complete silence (because silence is something that can only be approached asymptotically in dB). So if you're converting to dB, then when Amp hits 0, dB will return -∞, and Unity will throw an error.
I haven't yet solved this problem, so I'll be eagerly following this question.