AudioSource - Anyone else had this?

Hello,

I’ve been having all manner of issues using the AudioSource component. My understanding is that it’s used in conjunction with AudioClips and the AudioListener to play sound, be it music, ambient or sfx. All of that is quite straightforward - my problems come about from getting things to sound good in respects to volume level and the distance to the player.

The Unity docs talk about min/max being how quickly the sound fades so it will never be less than min or more than max, they don’t appear to do anything over 1 however. Volume additionally is the sound when 1m away, also doesn’t do anything over 1 and the main value is rolloff factor, which is how fast the sound fades - seems like it’s similar to min/max.

Now I’ve been reading this: http://www.unifycommunity.com/wiki/index.php?title=Audio which details the sound stuff a lot more and my issues - aside from the Unity docs being a bit misleading - are:

  1. The sound clips in Unity play at a very reasonable volume. In game, they play at a fraction of that volume, the loudest I can get it is probably about 1/2 the volume of when I play it in the project view.
  2. The fade in/out doesn’t scale very well. For sounds I wish to fade in very quickly, one would think given the descriptions, to use a high rolloff factor, but that just means you need to get -very- close, and then the sound is barely audible, even if you are hugging the source.
  3. There is no way to stop sounds playing - am I right in thinking that currently, all sounds will be playing all the time? I’ve got a burning ship sfx that I’ve set to a lowish rolloff factor, around 0.1, and I can hear it playing from about 700m away. If the min volume is 0 which it was in that test, surely it should not be audible?

So basically, I’m either totally misunderstanding how all these things interact, or it just seems like a really uncontrollable system. Has anyone else had this? My current plan is to script my own audio stuff that forces the AudioSource to do as I desire like the script I linked above.

I want things audible when close, not audible -at all- when far away and have them fade reasonably.

Have you tried setting Rolloff Factor to zero and Volume to 1? That should play in-game at exactly the same level in game as previewing in the editor, unless you have changed the Audio Listener’s or Audio Manager’s volume.

I think the default algorithm works well enough if you are working with the scale for which it was intended. Not having a Rolloff Threshold is really a terrible oversight, which is why I included that in the wiki script. Are you dealing with movement on a massive scale? Like giant robots or something? If so, what you’re describing would definitely happen.

No, you can use Pause() or Stop() whenever you like. Sounds that are not set to loop will not be playing after they finish.

Use a high Rolloff Factor, not a low one. A value of 1 represents “outdoors” reality. Kick it up further to quiet everything down at greater distances. Sound doesn’t just die. It only gets quieter over distance. At some point, however, it will be so quiet that you won’t be able to hear it over the ambient noise wherever you are.

I try to use as little as I need to - just little pieces parts from that script as appropriate. The less you script, the faster the game can run, but the audio system just isn’t robust enough to handle a lot of simple tasks.

Yes I can get it to work by doing that, but I wish the sound to fade/grow over distance rather than be a set 100% volume all the time. The reason I gave that as an issue is because in game, I can never seem to get them to play at 100% volume via the rolloff and min/max settings.

Not really on a very large scale like that, basically the player objects are ships, as are enemies, and the smallest ones are around 20m x 8m. This would mean at most, you can get 2 x 4m to the audio source assuming the listener is dead center of the ship - which it is. This is assuming you are literally hugging the other ship, not something that is advised or really required that players do. I really liked the threshold stuff you included, and setting that to around 50 means that the ambient sounds are pretty good. For example, we are making an isometric game, and lets say we have some ambient chatter/sfx around a building. That building is likely 20m in size by itself, and so the default Volume of 1 unit at 1m really wasn’t doing much.

Ah not like that, I mean based on distance or something similar. It seems like I need my own trigger system to start/stop - I’m not sure which will cost more, constantly playing audio or a trigger checking the player’s position all the time?

What I mean is, in order to have it play at a decent level when up close, the rolloff neads to be at ~0.1 but that means at distance it can still be heard. Thus my dilemma.

Yeah perhaps it’s up to us to script a lot of this, I’m just wary about too much stuff checking things, because it will get a little hectic. It’s also on a dreaded 1:1 ratio too, each new thing you add, requires it’s own check and so on.

You can scale down your game, but you have to account for that in the physics system. Otherwise, the audio system really can’t help you in terms of fading.

No, nothing like that is built in.

I’d recommend that you use triggers, but disable them when appropriate. You can use a coroutine to check to see if it’s worth turning them, and run that every few seconds, or however long makes sense for your game.

Yeah I think I’m on top of this pretty much atm. We just scaled things up a bit as everything was too small, if we are going by 1 Unity Unit being 1m.

does anyone know a way to insert audio zones without using a collider as trigger?

the audio triggers don’t allow my NPCs to walk though the space because they see it as a collider…

i want to create a city with different audio zones.

thank you!!!

There is a checkbox for this in the Inspector for every collider.

hi there, thanks for the quick response! i do always select the “as trigger”, but the npcs still walk around the collider… and it prevents my waypoints from being visible to each other…

i attach a simple script to the trigger:

function OnTriggerEnter (col : Collider)
{
    audio.Play();      
}

im sure it must be a simple fix! would be grateful for any advice…

I ran into this a while ago trying to play multiple clips at once and yes, it was nearly impossible to get a clip to play loudly.

There really needs to be a “volume” that changes the base volume of the audio clip. I also found that moving up min volume really makes little difference. From 1 to 10 I noticed a very small change instead of a 10x change that I would expect.

That’s exactly what “Volume” does. As long as your game is at the scale that Unity expects, it works well.

Whether you noticed it or not, it didn’t happen. There is actually NO difference between Min Volume at 1 or 10. Isn’t it funny how our senses can fool us? :wink:

I’m not mocking you. We can make ourselves believe anything. I can’t tell you how many times, when I was in school, somebody would go over to the mixing console, and painstakingly dial in an EQ curve, until it was “just right”. Then someone would point out to them that the signal wasn’t even running through the EQ. My method to attempt to avoid this is to always first make some giganticly ridiculous modification to something, and make sure that a ridiculous change happened. Obviously, this isn’t a surefire method, because that’s exactly what you did that too, but you came to the conclusion that it just wasn’t making enough of a change. I guess it takes a certain level of familiarity to know when something is broken?

Here’s an explanation of what Min Volume actually does:
http://www.unifycommunity.com/wiki/index.php?title=Audio#Why_I_find_it_necessary_to_use_this

I meant volume in the Audio Clip not the Audio Source, actually. There is no volume for the clip.

I was always setting Min Volume = Volume of the Source so that’s why I noticed some change and I stand by my “makes very little difference”. I’ll do some more tests, though. It was a week or two ago (and I’m suffering a cold right now) that I spend a weekend banging my head on the desk dealing with trying to get one sound louder than another (which was pretty much impossible since I could never get one sound actually ‘loud’).

EDIT: Thanks for the link … I didn’t realize it was a 0…1 range. That helps a lot and still speaks to your point about perceptions :slight_smile: So there’s actually no way in Unity to turn up the volume of a sound (only make it ‘quieter’ <1)?

I guess in a way it’s understandable: we’re expected to set all the volume levels correctly via a third party audio app but would definitely be nice to have Unity with this in the box.