Getting audio peak meter values for all active audio sessions

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

meters

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.

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
}

Browse source

Download meters.exe

2 thoughts on “Getting audio peak meter values for all active audio sessions

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s