I currently have 2 Background music audio clips which I want to play immediately one after another (intro followed by a loop when the intro is done playing).
However, no matter what I try, there seems to me a noticeable gap(especially on mobiles) when transitioning from one track to an other… Is there any way around this (other than crossfading)
Both my audio clips are set to ‘stream from source’ in import settings
Below is what I have come up with so far:::
-Notice that I add some latency to the first playTime to make sure that the engine has time to preload and schedule the clip. This is especially important for streaming clips.
Alternatively the plugin I made called Introloop will solve the problem, and the background music does not have to be cut up to 2 clips.
I used AudioSettings.dspTime and audio scheduling instead of PlayDelayed/coroutine for accuracy internally, since normal game time method is subject to lag in the game. If interested you could see it here : http://forum.unity3d.com/threads/378370/
I don’t think this guarantees a more smooth fade, actually. At least not universally…
As I understand it, volume adjustments are applied when the Audio Mix thread requests more samples to render. This is a separate thread from the Main thread where scripts generally do their work. And given how Unity’s main thread works, you might actually be calling “volume = x” multiple times without the samples ever being actually updated (this partially depends on the size of your dspBufferSize).
Of course, the framerate (and any hitches you’re receiving) will play a huge factor in how all of this works…
I know about the audio thread thing, but my reasoning was that continuous changes should still ideally be set frequently and in small steps to not sound jumpy. After testing a bunch of things, I guess you’re totally right tho. I had misunderstood the nature of FixedUpdate and thought it was spread out over time equally, rather than how it actually works (skipping frames / running multiple times in one frame, if needed).