From what i understand, Wavein will run on the main thread, and WaveinEvent will run on a separate thread.
But i noticed, that if i use Waveinevent, i need to increase the buffer from 4-5ms to 11-12ms.
Which increases the latency alot in the total buffer (got a waveprovider also).
And i don´t see the reason for it, if Waveinevent is run on a separate thread, shouldn´t it be able to do the same as Wavein, or perhaps even better as it´s not limited by the GUI thread?
Thanks
Only thing is that if i move the GUI(Windows Form) it will stop for a while, then continue, as it runs on the GUI Thrad.
But i noticed, that if i use Waveinevent, i need to increase the buffer from 4-5ms to 11-12ms.
Which increases the latency alot in the total buffer (got a waveprovider also).
And i don´t see the reason for it, if Waveinevent is run on a separate thread, shouldn´t it be able to do the same as Wavein, or perhaps even better as it´s not limited by the GUI thread?
Thanks
void Sending(object sender, NAudio.Wave.WaveInEventArgs e)
{
if (connect == true && MuteMic.Checked == false)
{
udpClient.Send(e.Buffer, e.BytesRecorded, otherPartyIP.Address.ToString(), 1500);
// waveWriterRam.Write(e.Buffer, 0, e.BytesRecorded);
}
}
SendStream = new WaveInEvent();
SendStream.BufferMilliseconds = 4;
SendStream.WaveFormat = new WaveFormat(48000, 16, 2);
SendStream.DeviceNumber = waveInDevice;
SendStream.StartRecording();
SendStream.DataAvailable += Sending;
Runs vey bad (need to set 11ms). sourceStream.DataAvailable -= new EventHandler<NAudio.Wave.WaveInEventArgs>(sourceStream_DataAvailable);
sourceStream.StopRecording();
sourceStream = new WaveIn();
sourceStream.BufferMilliseconds = 4;
sourceStream.WaveFormat = new NAudio.Wave.WaveFormat(48000, 16, 2);
sourceStream.DeviceNumber = waveInDevice;
SendStream.StartRecording();
void sourceStream_DataAvailable(object sender, NAudio.Wave.WaveInEventArgs e)
{
if (connect == true && MuteMic.Checked == false)
{
udpClient.Send(e.Buffer, e.BytesRecorded, otherPartyIP.Address.ToString(), 1500);
}
}
This runs much much better.Only thing is that if i move the GUI(Windows Form) it will stop for a while, then continue, as it runs on the GUI Thrad.