Got a problem with how Unity does audio. Why doesn’t the volume parameter in the audio source do anything past 1? When I try to increase the volume, it does nothing, but the volume can go from 1 to 0 and the sound will go silent, as it should.
How come the volume can’t increase past 1 so I can make my sound louder? :?
I’ve got a bounce sound loaded into the assets and setup properly with audio source and a listener. But I can hear the sound from all the way across the map, which I don’t want. So I increase the rolloff factor to make the sound silent at long distance. Which also works.
The problem with this though is that for some reason when I increase the rolloff factor, the loudness of the sound (even when up close) is low. What gives?
Use Vector3.Distance (or use (a-b).sqrMagnitude for the square distance, which is faster) to get the distance between the positions of two objects, and then do your own math based on that. What sort of math depends on what you want to do exactly.
Although this script is useful for setting an overall volume manually, the built-in Volume control is more useful for rolloffs, because sound pressure level varies inversely with distance from the source. I’ve never tried to code a rolloff before - does anyone around here know what the standard is? Here’s some information on what XNA does:
In a game world, I would think the most useful thing to do would be to set a small distance range, within which, the audio would play at maximum level, and attenuate it linearly over distance outside of that range. Any thoughts? What is Unity doing as it is?
As you mentioned previously sound pressure in the real world attenuates at 1/R, I always had the feeling that Unity attenuates at 1/R^2 which is why it feels wrong. Being that the sound pressure equation is fixed, I haven’t a clue what the roll-off value is even there for!
There’s also the issue that in the real world many sound sources are not true isometric radiators. A piano might come close, a trumpet, human voice or an acoustic guitar far from it. I don’t think any game audio layer accounts for this as it would be very difficult to do. Normal maps for audio?
Here’s what the ones we use for wave propagation in Ham Radio look like. I’d sure hate to have to plot one for every audio source! Let’s get realistic and have all the standing waves generated because of our moving geometry done on the GPU!
Just like in audio, there’s really no such thing as an isometric radiator when it comes to antennas either.
It’s not doing what it should be doing in terms of sound volume over distance. How Unity uses the rolloff factor is not right.
What Unity does is, instead of decreasing the distance (spherically) that you can hear sound with a higher rolloff factor, Unity simply decreases the volume (internally) of the sound when you make the rolloff factor higher so that when you move away it gets quieter (but up close, the volume is quieter than it would be at 1). :?
You can try it out for yourselves and you’ll see what I mean.