I’m looking for solution to tune mic’s level in my VoIP app. I can get a level of sound, but also want to tune the mic’s “volume” when it too low or too high in real-time. Like in Skype…
It looks easy ex facte, but I think the algorithm should be a bit smarter then just turning the volume when level comes over high/low limits.
I’m using .Net 2.0 on Win platform. Are there any ready libraries for .Net or even on C (so I can port it) or even just description of such methods/algorithms? I’ve tried to google but with no luck.
Thank you!
There are two parts to this.
First, you need to start capturing audio from the microphone and measure its signal intensity. If a person is speaking into the microphone to calibrate it, you could simply look for the highest peak over the previous few seconds. If it is below -6dB (say), raise the gain a bit, if it is above -3dB, reduce it a bit. The point is that you want high signal to noise ratio, but at all costs you want to avoid clipping or distortion with a signal too loud.
The second part is to work out which of the multitude of mixer controls returned by the mixer APIs is the one controlling the microphone gain. This turns out to be much harder than it ought to be, particularly if you want it to work with all sound cards and on XP and Vista/Win 7. See this question for some suggested solutions.
You can use NAudio for both parts. It has wrappers for the waveIn and mixer APIs.