Getting peak meters and volume settings for all apps and audio devices on the system

Getting peak meters and volume settings for all apps and audio devices on the system

  • Comments 3

A few previous posts have touched on how to get peak meter readings on the device, and per-app

Let's put it all together and write a single command-line tool which enumerates:
  1. All active audio devices (both playback and recording)
  2. Dumps the peak meter and volume levels for each device
  3. All active audio applications (audio sessions) per device
  4. Dumps the peak meter and volume levels for each audio session
Note there is no API for enumerating individual streams within a session.
Pseudocode:
For each flow in (render, capture)
    For each device in IMMDeviceEnumerator::EnumAudioEndpoints(flow)
        Display the name of the device
        Get and display IAudioMeterInformation::GetPeakValue for the device
        Get and display IAudioEndpointVolume data for the device
        For each session in IAudioSessionManager2::GetSessionEnumerator
            Skip the session unless the state is "active"
            Get and display IAudioMeterInformation::GetPeakValue for the session
            Display session information
            Get and display ISimpleAudioVolume information
            Get and display IChannelAudioVolume information

Sample output:

>meters.exe
-- Playback devices --
Line out (High Definition Audio Device)
    Peak: 0.404736
    Mute: 0
    Volume range: 0% to 100% (-46.5 dB to 0 dB in steps of 1.5 dB)
    Master: 74% (-4.32831 dB)
    Channel 1 of 2: 74% (-4.32831 dB)
    Channel 2 of 2: 74% (-4.32831 dB)

    Active session #1
        Peak value: 0.240089
        Icon path:
        Display name:
        Grouping parameter: {98710e41-6535-4cf0-b9b3-4181a0b7103e}
        Process ID: 3496 (single-process)
        Session identifier: {0.0.0.00000000}.{b3d96927-adc1-4d0f-a83d-bda63ad41843}|\Device\HarddiskVolume1\Windows\System32\WWAHost.exe%b{00000000-0000-0000-0000-000000000000}
        Session instance identifier: {0.0.0.00000000}.{b3d96927-adc1-4d0f-a83d-bda63ad41843}|\Device\HarddiskVolume1\Windows\System32\WWAHost.exe%b{00000000-0000-0000-0000-000000000000}|1%b3496
        System sounds session: no
        Package full name: Microsoft.ZuneMusic_2.2.41.0_x64__8wekyb3d8bbwe
        Master volume: 1 (0 dB FS)
        Not muted
        Channel #1 volume: 1 (0 dB FS)
        Channel #2 volume: 1 (0 dB FS)

    Active session #2
        Peak value: 0.329753
        Icon path:
        Display name:
        Grouping parameter: {fc078096-d2fc-4883-8b0d-af4619266c02}
        Process ID: 6720 (multi-process)
        Session identifier: {0.0.0.00000000}.{b3d96927-adc1-4d0f-a83d-bda63ad41843}|#%b{726CF207-6167-47C4-A745-55691DBD84A1}
        Session instance identifier: {0.0.0.00000000}.{b3d96927-adc1-4d0f-a83d-bda63ad41843}|#%b{726CF207-6167-47C4-A745-55691DBD84A1}|1%b#
        System sounds session: no
        HWND: 0x00000000000D1390 Windows Media Player
        Master volume: 1 (0 dB FS)
        Not muted
        Channel #1 volume: 1 (0 dB FS)
        Channel #2 volume: 1 (0 dB FS)

Internal speakers (High Definition Audio Device)
    Peak: 0
    Mute: 1
    Volume range: 0% to 100% (-46.5 dB to 0 dB in steps of 1.5 dB)
    Master: 65.7804% (-6 dB)
    Channel 1 of 1: 65.7804% (-6 dB)

-- Recording devices --
Microphone (High Definition Audio Device)
    Peak: 0.000274658
    Mute: 0
    Volume range: 0% to 100% (-34.5 dB to 12 dB in steps of 1.5 dB)
    Master: 84.7652% (6 dB)
    Channel 1 of 2: 84.7652% (6 dB)
    Channel 2 of 2: 84.7652% (6 dB)

    Active session #1
        Peak value: 0.000274658
        Icon path:
        Display name:
        Grouping parameter: {cee77f5a-d651-4392-8ffc-232c6eecdf51}
        Process ID: 8212 (single-process)
        Session identifier: {0.0.1.00000000}.{878a0979-89d6-43ec-9cff-e3f70dac2618}|\Device\HarddiskVolume1\Program Files\WindowsApps\Microsoft.WindowsSoundRecorder_6.3.9600.16384_x64__8wekyb3d8bbwe\soundrec.exe%b{00000000-0000-0000-0000-000000000000}
        Session instance identifier: {0.0.1.00000000}.{878a0979-89d6-43ec-9cff-e3f70dac2618}|\Device\HarddiskVolume1\Program Files\WindowsApps\Microsoft.WindowsSoundRecorder_6.3.9600.16384_x64__8wekyb3d8bbwe\soundrec.exe%b{00000000-0000-0000-0000-000000000000}|1%b8212
        System sounds session: no
        Package full name: Microsoft.WindowsSoundRecorder_6.3.9600.16384_x64__8wekyb3d8bbwe
        Master volume: 0.847652 (-1.43565 dB FS)
        Not muted
        Channel #1 volume: 1 (0 dB FS)
        Channel #2 volume: 1 (0 dB FS)

    Active session #2
        Peak value: 0.000274658
        Icon path:
        Display name:
        Grouping parameter: {c346e9e3-a37e-427b-a2be-1feb2c81b469}
        Process ID: 2608 (single-process)
        Session identifier: {0.0.1.00000000}.{878a0979-89d6-43ec-9cff-e3f70dac2618}|\Device\HarddiskVolume1\Windows\System32\SoundRecorder.exe%b{00000000-0000-0000-0000-000000000000}
        Session instance identifier: {0.0.1.00000000}.{878a0979-89d6-43ec-9cff-e3f70dac2618}|\Device\HarddiskVolume1\Windows\System32\SoundRecorder.exe%b{00000000-0000-0000-0000-000000000000}|1%b2608
        System sounds session: no
        HWND: 0x00000000004611FA Sound Recorder
        Master volume: 0.847652 (-1.43565 dB FS)
        Not muted
        Channel #1 volume: 1 (0 dB FS)
        Channel #2 volume: 1 (0 dB FS)

 Source and binaries attached.

Attachment: meters.zip
Leave a Comment
  • Please add 8 and 1 and type the answer here:
  • Post
  • Hey. I uses this code for my delphi appication and have one problem. For speakers i can get peaks values in any moment. For stereo mix i cant. This device must be active (active recording or just open audio settings in Widnows). How to get values for this device in any moment?

  • If a device has hardware peak metering, then the meter value is always accurate. There is a convenience method IAudioMeterInformation::QueryHardwareSupport which will tell you.

    If there are no active streams on a device without hardware peak metering, the meter value is always 0. For playback devices this is correct! But for recording devices this is a pain.

  • thank You for answer

Page 1 of 1 (3 items)