Getting audio peak meter values for all active audio sessions

Getting audio peak meter values for all active audio sessions

  • Comments 7

The Windows Vista volume mixer shows a peak meter for the device.  In Windows 7 we added a peak meter for each application.

The audio interface for both is IAudioMeterInformation; I've used this before in my post about the linearity of Windows volume APIs.  This post showed how an application can get the peak meter reading for the device meter.

In Windows 7 we also added APIs to allow applications to get a list of audio sessions.  I wrote up a quick app which shows how to get a list of all audio sessions, filter it down to the active ones (sessions which have an active audio client), and then get a peak meter reading.

>meters.exe
{0.0.0.00000000}.{c05f2f54-7294-422a-bb0d-8d690c365b73}|#%b{917F8618-9C57-4720-9B7C-88CA45FC983B}: 0.215705
Active sessions: 1

{0.0.0.00000000}.{c05f2f54-7294-422a-bb0d-8d690c365b73}|#%b{917F8618-9C57-4720-9B7C-88CA45FC983B} is the session identifier, which should be considered opaque.  0.215705 is the value of the peak meter, ranging from 0 to 1 linearly in amplitude.  If you are populating a visual peak meter with this information, you will need to apply a curve.

Source and binaries attached.  Pseudocode follows:

CoCreate(IMMDeviceEnumerator);
IMMDeviceEnumerator::GetDefaultAudioEndpoint;
IMMDevice::Activate(IAudioSessionManager2);
IAudioSessionManager2::GetSessionEnumerator;
for (each session) {
    IAudioSessionEnumerator::GetSession
    IAudioSessionControl::GetState
    if the state is anything but "active", skip to the next session
    QI IAudioSessionControl to IAudioSessionControl2
    IAudioSessionControl2::GetSessionIdentifier
    QI IAudioSessionControl to IAudioMeterInformation
    IAudioMeterInformation::GetPeakValue
    Log the session identifier and the peak value
}

Attachment: meters.zip
Leave a Comment
  • Please add 6 and 4 and type the answer here:
  • Post
  • Will a pseudolocalised MUI be released for Windows?

  • Good question for Michael Kaplan: blogs.msdn.com/.../michkap

  • Can not run on vista, for I****2 interfaces supported since win 7.

    but how to do it on vista?

  • You can't do this in Vista.

  • Cannot run in Win7, say "not a valid win32 application"

    do you have the same error?

  • Are you maybe running the amd64 .exe on an x86 install of Windows 7?

  • hi,

    it works now.

Page 1 of 1 (7 items)