views:

211

answers:

5

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...

+4  A: 

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

LBushkin
+1, looks very promising! Giving it a try right now...
mdb
+1  A: 

If you want to try a DirectX based sound solution you can use SlimDX. It supports DirectSound and XAudio interfaces.

Ron Warholic
Thanks, another promising solution that my weak Google-fu somehow overlooked
mdb
+1  A: 

I've been a fan of the BASS library which has a .NET API.

Dean J
Its license is somewhat suboptimal for me. Still, bookmarked...
mdb
+1  A: 

Another is FMOD.

DanStory
Thanks -- a tad expensive for commercial use, though. Another one I found in the meantime is http://www.ambiera.com/irrklang/irrklang_pro.html, which also suffers from strange licensing
mdb
I don't think IrrKlang's licensing is that strange... the developer is giving you the option to select the license which is most appropriate for your situation.
emddudley
+1  A: 

Please try http://alvas.net/alvas.audio.aspx Have samples in c# and VB

ava