Matthew van Eerde's web log

  • Matthew van Eerde's web log

    Muting all audio outputs with IAudioEndpointVolume

    • 0 Comments

    I have a selfhost tool that I use to mute all audio outputs programmatically.

    Pseudocode:

    IMMDeviceEnumerator::EnumAudioEndpoints
    for each device:
        IMMDevice::Activate(IAudioEndpointVolume)
        IAudioEndpointVolume::SetMute(TRUE)

    Source and binaries attached.

  • Matthew van Eerde's web log

    Getting audio peak meter values for all active audio sessions

    • 4 Comments

    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
    }

Page 1 of 1 (2 items)

June, 2012