cancel
Showing results for 
Search instead for 
Did you mean: 

Enable / Disable Audio Sources During Runtime

Colton-Vitruviu
Protege
Hi All,

In our largest scene we have approx. 50 ambient audio sources (enemies walking around, music, etc.) in addition to many audio sources for NPCs talking (that only play while interacting with them). Currently we are enabling/disabling ambient audio sources based on distance to the main camera (greatly reduces DSP load and prior to implementing this we were having audio sources not playing) but we are finding that when/if you return to the exact same spot on the map after the audio sources in that spot have been enabled/disabled, they are quieter (25-50% reduction in volume, i.e go to one end of the map and come back, the sound will not be the same). We are using the native Oculus Audio plugin and I'm not sure what this problem is stemming from? Is there a problem with enabling/disabling audio source with regards to the mixer or onspaudiosource.cs?

Is anyone else finding this? Is there a better way to manage a large number of audio sources?

Cheers,
Colton
14 REPLIES 14

petergiokaris
Protege
Hi Colton,

This is something that we have not encountered before. Does this happen when you disable spatialization globally in audio project settings?

If you can send us a unitypackage with a repro (or repro steps that we can test here) we can work on figuring out what going on.

Thanks,
Peter Giokaris Senior Software Engineer

Colton-Vitruviu
Protege
Hey Peter, thanks for the reply

Disabling spatialization globally had no effect. I turned on Early Reflections in the audio mixer and then turned off Disable Reflections in the ONSPAudioSource component, this seemed to fix my problem. I was unable to reproduce the problem in a new project, so maybe the problem was having some sources with disable reflections and some without?

Let me know if there is anything I can do to help you see if this is actually a problem or just something with my setup.

Cheers,
Colton

*EDIT*

While the above solution fixed the problem it increased our DSP load from 10% to 60% and caused approx. 10-40 fps drop. We have since disabled reflections again and the problem is still present but less noticeable.

petergiokaris
Protege
Hi Colton,

Thanks for this info. To be clear, do you mean the problem still persisted when you disabled spatialization completely? The reason I ask is that if it still problematic, then it might be an issue with the way the new Unity audio is handling the scenario you described.

If you are not encountering this with spatialization disabled globally, then this is something we definitely need to investigate.

It may very well be that having some sources disable reflections could be attenuating the sound, while sources that have reflections on may sound louder. This is due to the accumulative effect of the reflections influencing overall volume on the source. One thing to look at is the room size you are using along with the reflection values. If your room size is small and reflection values are large, each bounce will have more strength due to the fact that there is less air dampening occurring on the bounce (as well as less absorption into the wall). It's easy to overload the reflection system with small room sizes and large reflection values (which represent less absorption into the wall).
Peter Giokaris Senior Software Engineer

Colton-Vitruviu
Protege
The problem has since resolved itself by changing pretty well every audio source in the scene around and trying different settings, not sure which combination actually worked. I now have all audio sources with reflections turned off as well as reflections disabled in the mixer. As far as I recall every time I disabled the Oculus plugin there was not a significant change (i.e. problem still persisted).

Cheers,
Colton

petergiokaris
Protege
Hi Colton,

Thanks for the update. It sounds like this might be a Unity audio engine issue. I will bring this to their attention. In the meantime I'm glad that it's working out now (although I will follow up to see if I can provide you any more insight on this).
Peter Giokaris Senior Software Engineer

Colton-Vitruviu
Protege
Would you like me to send you a build which has the issue present so you can check it out? Not sure if it'll be much help though..

petergiokaris
Protege
Please do, send be a dropbox link (or whichever means of file transfer that you use).
Peter Giokaris Senior Software Engineer

Colton-Vitruviu
Protege
Hey Peter,

Looks like the save files on that last build have been corrupted and I am unable to send you the built version (without the files you cannot load far enough into the game where the problem is), sorry. Looks like everything is working fine now though.

Cheers,
Colton

petergiokaris
Protege
No worries, I have found the potential problem and have a fix!

In ONSPAudioSource.cs, replace the Update function with this one:

void Update()
{
// We might iterate through multiple sources / game object
var source = GetComponent<AudioSource>();
SetParameters(ref source);
}


It appears as if enabling/disabling audio sources to not update the SetParameter call properly, so we can remove the dirtyFlag that is set and keep setting these values (this will not incur a hit, since we are only setting a handful of parameters in the spatialier audio source).

Let me know if this fixes your problem. We will be pushing this fix out along with a few more in our next patch release.
Peter Giokaris Senior Software Engineer