Quantcast
Channel: MSDN Blogs
Viewing all articles
Browse latest Browse all 35736

Getting audio peak meter values for all active audio sessions

$
0
0

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
}


Viewing all articles
Browse latest Browse all 35736

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>