Set audio to not "Decompress On Load", when pulling from WWW

I am pulling in OGG music files via WWW, and have noticed that each time it switches to a new track, there is a really nasty performance hiccup. I’m assuming the problem is that Unity is attempting to “decompress on load” this entire file, right then and there? So I’d like to change that to either “compress in memory” or “stream from disc”, I believe…feel free to tell me if I’m wrong on any of this :smile: Otherwise, I can’t seem to find how to set this via script, only editor classes, which I assume won’t work, and would really appreciate help figuring this one out.

Currently, my code goes thusly:

function Start()
{
   //Begin pulling in music
   GetMusic();
   //--
}

function GetMusic()
{
	var url : String;
	var www = new WWW(url);

	//print("Getting Music:");
	while(musicTracks.length < musicLinks.length)
	{
		url = musicLinks[musicTracks.length];
		//print("url: "+musicLinks[musicTracks.length]);
		www = new WWW(url);
		var tempClip : AudioClip = www.GetAudioClip(false, false); //non-3d, non-streaming;
		//print("downloading...");
		yield www;
		
		//print("done!");
		musicTracks.Add(tempClip);
		//print("got "+musicTracks.length+" of "+musicLinks.length+" total tracks");
		if(audio.clip == starterLoop)
		{
			//print("Switching from starter loop to real music!");
			audio.loop = false;
			audio.clip = musicTracks[0];
			audio.Play();
		}
	}
}

function NextMusicTrack()
{
	//print("Checking the stacks...");
	if(currentTrackIndex == musicTracks.length-1)
	{
		//print("Last track reached, going back to zero!");
		audio.clip = musicTracks[0];
		audio.Play();
	}
	else
	{
		//print("We've got more music, on to the next!");
		currentTrackIndex++;
		audio.clip = musicTracks[currentTrackIndex];
		audio.Play();
	}
}

One point, I’m not using stream because it just doesn’t seem to work, and research here on the forums seemed to show that I simply can’t- I’ll try to find the threads I was reading on that. However, if anyone can point me toward a way to get streaming working properly, that would be great!

More importantly, the current method is working fine, other than the performance hit I’m hoping to solve here, via “compress in memory”/etc.

Any help much appreciated, thanks!

nothing? :frowning:
still trying to figure my way around this, urg…

:frowning: one more bump…I can’t come up with a solution to this it seems. Anyone else ran into this, or am I just doing something terribly wrong? :frowning:

Not that I can help, but I’m surprised that unity will even let you load directly from disk.

I assumed that you had to import audio assets before loading up the scene …

Hi Keithsoulasa-

Thanks for the reply! “stream from disc” is just one of the options available, not sure if it’s the best, but anything seems better, in this case, than “decompress on load”.

As for importing the audio assets, they just load in as the game runs, there is no wait time for them to download. Makes the game load up a lot quicker! :slight_smile: Once the first track has fully downloaded, it starts playing, and the next one starts downloading. Each time a track finishes downloading, it checks if there are any more to download, and starts the next if so. When the track finishes playing, I swap to the next track and play it- it is at this point that Unity massively chokes for a full .5-1 second, which is a big deal in my game!

Try using AudioClip.isReadyToPlay?

Hmm, so did you just import the audio asset into your game .

Like for the little game I’m making I import all the audio I need before hand .

Now I reckon that if you have a game with a very very large amount of audio content( like 50 mb plus) then you’d need to pull it in from disk.
I don’t know if Apple allows that type of thing and I want to keep my game portable to Iphone…

I believe it has to be a bug, since using the deprecated WWW OggVorbis statement will work woithout any issues, except that you wont be able to get the AudioClip as a 2D Sound.