Hello.
I’m writing a VoIP-like system in unity, and I already got the voice data chunks sent from the client to the server, and the server routing it to all the clients.
My client has an infinite clip being played in an AudioSource, like this:
mainClip = AudioClip.Create("voice", 44100, 1, 44100, true, OnAudioRead);
So this is basically a 1-second clip that is looped (and stream is set to true as well), and should be fed data according to the OnAudioRead delegate:
private void OnAudioRead(float[] data)
{
Array.Copy(samples.GetRange(0, data.Length).ToArray(), 0, data, 0, data.Length);
samples.RemoveRange(0, data.Length);
}
The problem is: whenever I receive the audio and play it, it has a lot of stuttering, every second or so you can hear the sound getting stuck in a loop, sounding like a very poor quality phone call.
I even tried adding some delay to see if the quality improves, but it doesn’t really, you can still hear the audio repeating the samples every now and then.
I already checked the individual chunks of data by recording them into a file, and the audio being played from the file is completely seamless, which leads me to believe there’s either something wrong with the way I’m feeding the data into the clip, or the AudioClip.Create isn’t supposed to be used in this way.
Any ideas?