Hi to all!
Hi to all! Tried posting this on the forum, and not getting any love… . I still have the following issue: I am trying to play an audioclip exactly at sample 0 of another looping one. This works fine in an empty scene, but not in my application. To try to narrow down the problem, I made the following test, which reveals (on my machine at least) that Play(offsetInSamples) will be inaccurate if there is as much as a Print in the same function… Details of my test are below, any help would be greatly appreciated!
The scene contains a camera, and 3 GameObjects with 1 AudioSource each : metronome, met2 and met3. They all have the same AudioClip, which is a .25s click (precisely 11025 samples at 44100 hz). All sources set to loop, metronome audio source to PlayOnAwake.
Metronome has the following script attached to it:
var met2 : GameObject;
var met3 : GameObject;
private var offset : int;
function Update(){
if(Input.GetKeyDown("2")){
offset = audio.clip.samples - audio.timeSamples;
if(met2.audio.isPlaying == false){
met2.audio.Play(offset);
print("anything"); //The Culprit
}
else{
met2.audio.Stop();
}
}
if(Input.GetKeyDown("3")){
offset = audio.clip.samples-audio.timeSamples;
if(met3.audio.isPlaying == false){
met3.audio.Play(offset);
}
else{
met3.audio.Stop();
}
}
}
When I hit 3, sync is perfect, but if I hit 2, the metronomes are out of sync at least 10% of the times, and once in a while seriously out of sync (50ms) a few times in a row. It seems printing a string is enough to trigger this inaccuracy…
I’m using Unity 3.5, Windows XP, audio settings to best latency, decompress on load, file is a wav (2d sound, but the same applies to 3d sounds).