Alex Rivera | Logout

How to programmatically get the current audio level?

Asked 2010-10-21T23:27:03.183
14

Basically, what I need is a way to tap into the current audio output and check the sound level, i.e. I need to be able to check whether there is something playing on the audio device or not.

I do not need to check the volume setting, but the actual playing audio stream's sound level.

Sorry, I was asking about how to do it in Windows, on Visual Studio 2008.

@mikerobi: That forms a part of my reasoning - if it is being displayed on the system volume meter, there must be a system call that can get it back

Edit
Report

1 Answer

2

This is a good question. The answer, for 32-bit Windows apps, is to hook into winmm.dll and other low-level audio control DLLs. In C# I'd create a wrapper class containing extern method prototypes:

public class MyAudioWrapper
{
   [DllImport("winmm.dll", EntryPoint = "waveOutGetVolume")]
   public extern void GetWaveVolume(IntPtr devicehandle, out int Volume);

   ...
}

Have a look at this link for a list of Windows audio methods; you can use the mixer, or just the wave-out controller, to set volume. What you want to use will dictate what libraries to import. You'll have to research how best to define the prototype, and how to get the handle to the audio/mixer device.

answered 2010-10-21T23:52:59.787

Your Answer