What is the simplest way to continuously sample from the line-in using C#

拜拜、爱过 提交于 2019-12-21 09:23:04

问题


I want to continuously sample from my PC's audio line in using C# (then process that data). What is the best way to do the sampling?


回答1:


You can do some (basic) audio capture using the open source NAudio .NET Audio Library. Have a look at the NAudioDemo project to see a simple example of recording to a WAV file using the WaveIn functions. NAudio also now includes the ability to capture audio using WASAPI (Windows Vista and above) and ASIO (if your soundcard has an ASIO driver).




回答2:


There is the Alvas Audio library as well, not free, has a nagging screen if you don't pay, but works beautifully. And the documentation is nice and, if you find a bug or something, the support is fine too.




回答3:


There are no built-in libraries in the .NET framework for dealing with sound, but if you're on Win32, you can use an unmanaged library like DirectSound to do it.

Ianier Munoz shows how to write a full-duplex audio player in C# using waveIn via P/Invoke on CodeProject. He mentions Managed DirectSound as a more general method.




回答4:


Managed DirectX supports direct capture of audio and is very easy to use, but is no longer supported and was removed from the DirectX SDK last year. It's still possible to get it by installing an SDK version from before August 2007.

While not strictly meeting your requirements, a more robust approach would be to create a C++/CLI wrapper assembly around the native C++ DirectSound API, again from the DirectX SDK. This could then be called directly from C# code. This is definitely a more powerful and maintainable approach, despite requiring some knowledge of C++ and COM.

I have used both of these techniques in the past and they both work well.



来源:https://stackoverflow.com/questions/228659/what-is-the-simplest-way-to-continuously-sample-from-the-line-in-using-c-sharp

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