- Home /
What are some ways to prevent audio flanging and phase cancellation when using a lot of voices?
I'm working on a game which plays a large number of short, one-shot sound effects in very rapid succession: weapons fire, weapon impacts, unit deaths, building destruction, and so on. Part of the point of the game is that the amount of onscreen chaos can grow to absurd levels. As that happens, the number of active sounds skyrockets. This presents a few problems:
- Audio overload and unusually loud sounds due to like sounds stacking within the same frame
- Audio flanging due to like sounds playing almost, but not quite, in time with each other
- Phase cancellation due to like sounds playing almost exactly out of phase with each other
My question is: what are some ways to address these issues? I'm having a hard time finding discussion of techniques for these things.
So far, I've implemented a custom AudioMixer class which allocates a fixed-size pool of AudioSources for each unique AudioClip, and cycles through that pool as requests for that sound come in. There's also a voice-limiting mechanism on that pool which prevents a given sound from being triggered more than once every N seconds. This effectively addressed the "audio overload" issue by preventing like sounds stacking in a single frame. The flanging and phase cancellation issues seem rather trickier.
Has anyone dealt with this sort of thing before? Any ideas or suggestions?
Answer by Nicolaj Schweitz · Mar 30, 2011 at 08:38 PM
I don't think there is one good answer to this problem, but please, everyone, share your ideas!
Let's take it on the forum: http://forum.unity3d.com/threads/83830-Audio-mixing-in-Unity?p=538319#post538319
Answer by Kilometers · Sep 23, 2011 at 07:21 AM
Simple. Let's say I have Sound A. Using the high precision system timer I can track the last time Sound A was played. I figure out a minimum amount of milliseconds that prevents most phase issues (let's say 60 ms), then I add an if statement determining whether or not 60 ms have elapsed. If so, allow the sound to play again if needed.
You can also add effects to simulate the clutter and chaos, without the phasing. Let's say Unity3d tries to play 5 instances of Sound A within 50 milliseconds of one another. Instead of just cancelling all but one of them, you could add a distortion filter that reacts to how many Sound A's are trying to be played.
Also, I do not remember if Unity3d has a pitch filter, but if so you could use the filter to randomly (and slightly) stretch and squish Sound A, further reducing phase issues.