How to Determine the Microphone Input Level

Hi Everyone. My problem is this: I'd like to get the input level of a signal coming into a microphone. That is to say, i'd like to be able to call a method that will return an integer or string value that will increase and decrease with the volume of the input signal.

So, if I were to start speaking into my microphone, the value might report a 50. If I start yelling, maybe it would be closer to 100.

The point is that I want to be able to react to different levels of noise in my user's physical environment. Does anyone have any ideas on how to get this value?

I am using C# with Visual Studio 2005 and the DirectX 10 SDK December 2006 and have had no luck, to date.

Thanks in advance!
-Matt

[725 byte] By [MattPolichany] at [2007-12-29]
# 1
To get the volume of a signal you can make a loop wich take a little chunk of samples (for ex. 1024) and calculate the average. Then to map the volume from 0 to 100 just divide the average for 655 (if you record at 16 bit!)

long Average;
int Volume;

DO
Average = Sample(i) + Sample(i+1)...+Sample(i+1023);
Average = Average \ 1024;
Volume = Average \ 655;
LOOP

it should be right...hope that helps! Adapt the code to take the samples of the input signal

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