How to monitor microphone input level?


I'm using VB.net with Framework 2.0.

How to monitor the mic level of the default soundcard? I would like to be able to set a threshold value (0-100%) and when the mic level is greater than that a message box would appear. It would be important that the detection would be fast (with as short delay as possible) and consume CPU resources as little as possible. Is this possible without DirectX SDK?

I found some code in VB6 and C but could not translate them in VB.net.

Thank you!

[492 byte] By [reinfecta] at [2007-12-25]
# 1

I don't believe that the .NET classes include such implementation, DirectX would be the best way for this as it contains everything you need in regards to multimedia (video and audio)

I will move this thread to the DirectX forums where they will be able to respond to your query better. My apologies if the thread has been moved into the incorrect DirectX subforum

Thanks

ahmedilyas at 2007-9-3 > top of Msdn Tech,Game Technologies: DirectX, XNA, XACT, etc.,Game Technologies: DirectX 101...
# 2
DirectX SDK will do just fine if it solves this problem. All help is welcome!
reinfecta at 2007-9-3 > top of Msdn Tech,Game Technologies: DirectX, XNA, XACT, etc.,Game Technologies: DirectX 101...
# 3

With the DirectSoundCapture interfaces you can retrieve input sound from the default input device set on the Windows Multimedia options. Then you can read the input results from there and compare them against the threshold that you want...

For more information, look at IDirectSoundCapture8 and IDirectSoundCaptureBuffer8 interfaces...

On the other hand, this is also perfectly achievable with the Win32 multimedia APIs. Look at the waveIn* APIs on MSDN... Note that these use a different approach than that of DSound's. (IMO DSound is easier)

WessamBahnassi at 2007-9-3 > top of Msdn Tech,Game Technologies: DirectX, XNA, XACT, etc.,Game Technologies: DirectX 101...
# 4
If this is possible to with Win32 APIs, I would prefer that way. I have googled and googled but found nothing but C code or VB6.0 code. I'm a beginner and would need very basic step-by-step instructions how to solve this problem... I would be most grateful, if someone could help me and give me simple enough guidance. Thanks!
reinfecta at 2007-9-3 > top of Msdn Tech,Game Technologies: DirectX, XNA, XACT, etc.,Game Technologies: DirectX 101...
# 5

Well, it's starting to get off the topic of DirectX 101, but the first step is to learn how to call Win32 API functions in your C# app... It's not that hard to do, and you can start by looking here:

http://msdn.microsoft.com/msdnmag/issues/03/07/NET/

Then you can call the Win32 API functions as in C++...

There's also an implementation of a .NET lib that builds on waveIn which you can use directly:

http://www.codeproject.com/cs/media/cswavrec.asp?print=true

I hope this helps...

WessamBahnassi at 2007-9-3 > top of Msdn Tech,Game Technologies: DirectX, XNA, XACT, etc.,Game Technologies: DirectX 101...
# 6
Thanks, but I would need code in VB.net. I can't code in C++.
reinfecta at 2007-9-3 > top of Msdn Tech,Game Technologies: DirectX, XNA, XACT, etc.,Game Technologies: DirectX 101...
# 7

?!

The CodeProject's sample is a .NET lib. You can use that directly in your VB.NET project...

WessamBahnassi at 2007-9-3 > top of Msdn Tech,Game Technologies: DirectX, XNA, XACT, etc.,Game Technologies: DirectX 101...
# 8
I have to admit, I don't know how to use that source code. I think I should do something with the WaveInBuffer but that's all. Could you help me and give me more hints and advice? Thanks!
reinfecta at 2007-9-3 > top of Msdn Tech,Game Technologies: DirectX, XNA, XACT, etc.,Game Technologies: DirectX 101...
# 9
Learn more on VB.NET and the .NET framework in general. Not only this will help you solve this issue, but you'll definately need the information if you intend to do more serious apps.
WessamBahnassi at 2007-9-3 > top of Msdn Tech,Game Technologies: DirectX, XNA, XACT, etc.,Game Technologies: DirectX 101...
# 10
Of course it wouldn't hurt to read more literature. But considering my personal goals in the art of coding, a direct and fully-explained example would have been the best solution. I am a beginner and programming is more sort of a hobby. I learn best by manipulating working examples.

So, I still kindly ask for help...

reinfecta at 2007-9-3 > top of Msdn Tech,Game Technologies: DirectX, XNA, XACT, etc.,Game Technologies: DirectX 101...
# 11

re infecta wrote:
a direct and fully-explained example would have been the best solution

And you already have it in the CodeProject sample...

WessamBahnassi at 2007-9-3 > top of Msdn Tech,Game Technologies: DirectX, XNA, XACT, etc.,Game Technologies: DirectX 101...