- Home /
Editor freezes while playing audio loop.
Hi there. Recenty my unity editor started crashing. It freezes kompletely and I need to use the task manager to terminate it. It happens during testing my scene at random points and more frequent when I quit testing. I dug up the log in AppData\Local\Unity\Editor but nothing related to the crash appears there.
The problem occured first after I added background audio loops and never appeared when the corresponding gameobject was deactivated (so far). The audio loops are in the it format and the preview shows: 32bit, 48000Hz, stereo, unlimited, 167,7 kb (it). The script which manages the audio clips works as intended (see below).
I have no idea what causes those crashes. Any help is appreciated.
BackgroundMusic.js :
var clips : AudioClip[];
private var _audio : AudioSource;
function Start () {
_audio = GetComponent(AudioSource);
if(clips.Length == 0) Debug.Log("No AudioClip assigned!");
_audio.loop = true;
PickRandom();
_audio.Play();
}
function Update () {
if(Input.GetKeyDown(KeyCode.M)){
_audio.mute = !_audio.mute;
}
if(Input.GetKeyDown(KeyCode.N)){
PickNext();
}
}
function PickRandom() : void {
var rand : int = Random.Range(0, clips.length);
_audio.clip = clips[rand];
Debug.Log("currently playing " + _audio.clip.name);
_audio.Play();
}
function GetIndex() : int {
for(var j : int = 0; j < clips.length ; j++){
if(_audio.clip.name == clips[j].name){
return j + 1 ;
}
}
Debug.Log("BackgroundMusic: GetIndex() failed. return 0");
return 0;
}
function PickNext() : void {
var index = GetIndex();
if(index == clips.Length) index = 0;
_audio.clip = clips[index];
Debug.Log("currently playing " + _audio.clip.name);
_audio.Play();
}
@script RequireComponent(AudioSource)
I've been experimenting with this issue a bit and seems like unity does not like the it format, even though the docs state it is supported. I converted a track to .wav and used the builtin compression format Ogg Vorbis. Afterwards the crash did not occur anylonger (until now).
Hey Lockstep,
I have had Unity crash out before when dealing with some of the higher bit / freq files. I generally convert them to 44.1khz 16bit Stereo when importing WAVS. Besides, the extra 'sound quality' on files that are 48khz or 96khz, and the extra work Unity has to do just isn't worth it in my opinion, especially when they get converted to OGG. Also when converting 48khz/96khz files to OGG, you can find that sometimes the audio gets 'distorted' and cause all sorts of headaches. Sorry I don't have an answer as such, but hopefully it may give further insight leading to one.
Paul
Thank you for your comment. It was bretty much what i was hoping for. Expecting a 100% explanation for such a vague problem would kinda illusive.
The wav i have tested crash free was 16bit 8khz which fits your statement. I'll have a closer eye on the sample rate when konverting/importing audio from now.
Upvoted comment as you made sure the question was updated and marked as answered ;)
Answer by code-blep · Sep 23, 2012 at 09:53 PM
Hey Lockstep,
I have had Unity crash out before when dealing with some of the higher bit / freq files. I generally convert them to 44.1khz 16bit Stereo when importing WAVS. Besides, the extra 'sound quality' on files that are 48khz or 96khz, and the extra work Unity has to do just isn't worth it in my opinion, especially when they get converted to OGG. Also when converting 48khz/96khz files to OGG, you can find that sometimes the audio gets 'distorted' and cause all sorts of headaches. Sorry I don't have an answer as such, but hopefully it may give further insight leading to one.
Paul
Sorry I should have posted it as an answer. $$anonymous$$y bad Lockstep! ;)
Your answer
Follow this Question
Related Questions
How can I find editor log file? 5 Answers
Unity build freezing after same number of Debug.Logs 0 Answers
Xbox UWP Game Crashing Upon Loading 0 Answers