how to eliminate latency and echo from the direct-monitoring using AsioOut (NAudio)

删除回忆录丶 提交于 2020-02-05 04:43:04

问题


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.


回答1:


What buffer size are you using? Remember it is completely impossible to eliminate all latency if you are recording and playing back the audio. Most ASIO drivers allow you to go to quite low latencies (sub 10ms), but you also need to make sure that any direct monitoring feature of your soundcard is turned off, or you will hear an echo.



来源:https://stackoverflow.com/questions/22746418/how-to-eliminate-latency-and-echo-from-the-direct-monitoring-using-asioout-naud

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!