I had a problem when the received audio data played stuttering, so I came up with the idea to linger a bit before it starts playing, so the application will have more time to collect audio sections before it starts playing. The idea is that it will play through the collected sound, as the rest comes to the application before it is needed.
void udpClient_DataReceived(byte[] bytes)
{
audioQueue.Enqueue (bytes);
if (audioQueue.Count > 10 && !playing) {
playing = true;
PlayQueue ();
}
}
private void PlayQueue()
{
byte[] a;
while (audioQueue.Count > 0) {
audioQueue.TryDequeue (out a);
audIn.PlayAudio (a);
}
playing = false;
}
However, the code has 2 problems:
1) If the sound length is shorter than the set limit, it will not be played until more audio is collected. Therefore, I need some kind of delay that does not require a minimum amount of data to run it.
2) . while PlayQueue. , .
, , .