title: Recommended way to work with audio in .NET applications?
body: <p>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:</p>
  
  <ul>
  <li>Continuously record audio from (the default) Windows audio input device in 8-bits-per-sample PCM format</li>
  <li>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)</li>
  <li>If the audio fragment is found interesting after analysis, save it using a compressed file format (e.g. MP3)</li>
  </ul>
  
  <p>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:</p>
  
  <pre><code>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.
  </code></pre>
  
  <p>...which I think loosely translates as "don't even <i>try</i> to use this stuff." Am I missing something here, or is Managed DirectX really dead? <a href="https://stackoverflow.com/questions/1502390/does-xna-effectively-replace-managed-directx">Another StackOverlow question</a> suggests that XNA is a replacement for Managed DirectX, but it lacks the kind of low-level functionality I need.</p>
  
  <p>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...</p>