Based on this question made by me: How to record and playback with NAudio using AsioOut
With this code:
[DllImport("Kernel32.dll", EntryPoint = "RtlMoveMemory", SetLastError = false)]
private static unsafe extern void MoveMemory(IntPtr dest, IntPtr src, int size);
private void OnAudioAvailable(object sender, AsioAudioAvailableEventArgs e)
{
for (int i = 0; i < e.InputBuffers.Length; i++)
{
MoveMemory(e.OutputBuffers[i], e.InputBuffers[i], e.SamplesPerBuffer * e.InputBuffers.Length);
}
e.WrittenToOutputBuffers = true;
}
Doing like this feels a bit latency and a bit of echo and I don't know how to solve them.
I searched the libraries on the web that allow me to eliminate the echo (AEC) but have not found anything useful for C#. Does anyone know how to help me?
EDIT 1: My AsioOut.PlaybackLatency
is 2048ms. It's a bit too high..
EDIT 2: I tried with headphones and I noticed that the echo is only due to the proximity between the microphone and speakers, so it is not a problem although it would be interesting to have an AEC.
PROBLEM SOLVED: I solved the latency problem. It was a problem of my ASIO drivers, I uninstalled Cubase and I installed the ASIO4ALL driver and now it works fine.
PS: I had to add a *2 in the last parameter of the MoveMemory
. I don't know why, but without it you hear the sound in spurts.