Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Recommended way to work with audio in .NET applications?

I'm trying to get started with a simple audio application under .NET 3.5 (preferably in VB.NET, but will happily use C#). What I'd like to do is:

  • Continuously record audio from (the default) Windows audio input device in 8-bits-per-sample PCM format
  • For every N bytes captured, do some analysis on the raw audio (some RMS and/or SPL calculations -- basically what you'd need for a pretty VU bar graph thingy)
  • If the audio fragment is found interesting after analysis, save it using a compressed file format (e.g. MP3)

First thing I noticed is that audio support in the basic .NET Framework is pretty much nonexistent. Googling around a bit found some sample code, mostly using Managed DirectX. However, the lack of MSDN documentation, vintage of the libraries (2004) and the following menacing MDA exception in VS.NET 2008, convinced me this is a dead end:

Message: DLL 'Microsoft.DirectX.dll' is attempting managed execution inside 
OS Loader lock. Do not attempt to run managed code inside a DllMain or image
initialization function since doing so can cause the application to hang.

...which I think loosely translates as "don't even try to use this stuff." Am I missing something here, or is Managed DirectX really dead? Another StackOverlow question suggests that XNA is a replacement for Managed DirectX, but it lacks the kind of low-level functionality I need.

So, which API or third-party library is actually useful for audio development under .NET? Using COM interop or P/Invoke is acceptable, as long as there's some decent .NET example code available to get started with...

like image 517
mdb Avatar asked Dec 10 '09 16:12

mdb


1 Answers

Have you looked into NAudio on CodePlex? It looks like it has the features you need.

like image 77
LBushkin Avatar answered Sep 27 '22 23:09

LBushkin