0

I implemented to change microphone volume using wasapi.
https://learn.microsoft.com/en-us/windows/win32/api/_coreaudio/

The program will get default mic device, and initialize IAudioClient.
IAudioCaptureClient will be set from IAudioClient (use GetService()), the audio session will be start by IAudioClient.Start()

In this, I change the mic volume using ISimpleAudioVolume.
ISimpleAudioVolume->SetMasterVolume(0.5, NULL);

How to get ISimpleAudioVolume?
IAudioSessionControl->QueryInterface(&ISimpleAudioVolume)
The AudioSession can be get from IAudioSessionEnumerator

But it will change system settings' mic volume also. How to change the mic volume on application, only? (using wasapi)

The below is the my logs.

[2022-07-11 12:44:44:711] STARTED
[2022-07-11 12:44:44:711] Version=0.0.1
[2022-07-11 12:44:45:198] -- Recording devices --
[2022-07-11 12:44:45:199] Microphone(High Definition Audio Device)
    Peak: 0.0169555
    Mute: 0
    Volume range: 0% to 100% (0 dB to 37.5 dB in steps of 1.25 dB)
    Master: 100% (37.5 dB)
[2022-07-11 12:44:45:200]     Channel 1 of 2: 100% (37.5 dB)
[2022-07-11 12:44:45:200]     Channel 2 of 2: 100% (37.5 dB)
[2022-07-11 12:44:45:200] 
[2022-07-11 12:44:45:222]     Active session #0  (Active) 
        Peak value: 0.0169555
        Icon path: 
        Display name: 
        Grouping parameter: {caeb8dc6-a910-403e-9d68-2d38d5117bf7}
        Process ID: 27464 (single-process)
        Session identifier: {0.0.1.00000000}.{40177a8c-deca-4796-a08e-c0c093158d8e}|\Device\HarddiskVolume4\Windows\ImmersiveControlPanel\SystemSettings.exe%b{00000000-0000-0000-0000-000000000000}
        Session instance identifier: {0.0.1.00000000}.{40177a8c-deca-4796-a08e-c0c093158d8e}|\Device\HarddiskVolume4\Windows\ImmersiveControlPanel\SystemSettings.exe%b{00000000-0000-0000-0000-000000000000}|1%b27464
        System sounds session: no
[2022-07-11 12:44:45:222]         Master volume: 100 (0 dB FS)
[2022-07-11 12:44:45:222]         Not muted
[2022-07-11 12:44:45:223]         Channel #1 volume: 100 (0 dB FS)
[2022-07-11 12:44:45:223]         Channel #2 volume: 100 (0 dB FS)
[2022-07-11 12:44:45:223] 
[2022-07-11 12:44:45:223]     Active session #1  (DeActive) 
        Peak value: 0
        Icon path: @%SystemRoot%\System32\AudioSrv.Dll,-203
        Display name: @%SystemRoot%\System32\AudioSrv.Dll,-202
        Grouping parameter: {396d3088-eb5e-4c55-a2d0-0f83ad4da70f}
        Process ID: 0 (multi-process)
        Session identifier: {0.0.1.00000000}.{40177a8c-deca-4796-a08e-c0c093158d8e}|#%b{A9EF3FD9-4240-455E-A4D5-F2B3301887B2}
        Session instance identifier: {0.0.1.00000000}.{40177a8c-deca-4796-a08e-c0c093158d8e}|#%b{A9EF3FD9-4240-455E-A4D5-F2B3301887B2}|1%b#
        System sounds session: yes
[2022-07-11 12:44:45:223]         Master volume: 0 (-inf dB FS)
[2022-07-11 12:44:45:223]         Not muted
[2022-07-11 12:44:45:223]         Channel #1 volume: 100 (0 dB FS)
[2022-07-11 12:44:45:223]         Channel #2 volume: 100 (0 dB FS)
[2022-07-11 12:44:45:223] 
[2022-07-11 12:44:45:224]     Active session #2  (Active) 
        Peak value: 0.00734672
        Icon path: 
        Display name: 
        Grouping parameter: {8d5bcf46-5a2e-4e14-815e-8acea3308c0d}
        Process ID: 73404 (single-process)
        Session identifier: {0.0.1.00000000}.{40177a8c-deca-4796-a08e-c0c093158d8e}|\Device\HarddiskVolume4\workspace\WinMicTest\AudioTest\x64\Debug\AudioTest.exe%b{00000000-0000-0000-0000-000000000000}
        Session instance identifier: {0.0.1.00000000}.{40177a8c-deca-4796-a08e-c0c093158d8e}|\Device\HarddiskVolume4\workspace\WinMicTest\AudioTest\x64\Debug\AudioTest.exe%b{00000000-0000-0000-0000-000000000000}|1%b73404
        System sounds session: no
[2022-07-11 12:44:45:224]         Master volume: 100 (0 dB FS)
[2022-07-11 12:44:45:224]         Not muted
[2022-07-11 12:44:45:224]         Channel #1 volume: 100 (0 dB FS)
[2022-07-11 12:44:45:224]         Channel #2 volume: 100 (0 dB FS)
[2022-07-11 12:44:45:224] 
[2022-07-11 12:44:45:224] 
[2022-07-11 12:44:45:224] ------------------------
[2022-07-11 12:44:49:326] It is AudioTest.. Get ISimpleAudioVolume
[2022-07-11 12:44:49:329] Volume is changed=50
[2022-07-11 12:44:45:335] ------------------------
[2022-07-11 12:44:50:427] -- Recording devices --
[2022-07-11 12:44:50:428] Microphone(High Definition Audio Device)
    Peak: 0.00055478
    Mute: 0
    Volume range: 0% to 100% (0 dB to 37.5 dB in steps of 1.25 dB)
    Master: 50% (9.29833 dB)
[2022-07-11 12:44:50:428]     Channel 1 of 2: 50% (9.29833 dB)
[2022-07-11 12:44:50:428]     Channel 2 of 2: 50% (9.29833 dB)
[2022-07-11 12:44:50:428] 
[2022-07-11 12:44:50:429]     Active session #0  (Active) 
        Peak value: 0.00055478
        Icon path: 
        Display name: 
        Grouping parameter: {caeb8dc6-a910-403e-9d68-2d38d5117bf7}
        Process ID: 27464 (single-process)
        Session identifier: {0.0.1.00000000}.{40177a8c-deca-4796-a08e-c0c093158d8e}|\Device\HarddiskVolume4\Windows\ImmersiveControlPanel\SystemSettings.exe%b{00000000-0000-0000-0000-000000000000}
        Session instance identifier: {0.0.1.00000000}.{40177a8c-deca-4796-a08e-c0c093158d8e}|\Device\HarddiskVolume4\Windows\ImmersiveControlPanel\SystemSettings.exe%b{00000000-0000-0000-0000-000000000000}|1%b27464
        System sounds session: no
[2022-07-11 12:44:50:429]         Master volume: 50 (-6.0206 dB FS)
[2022-07-11 12:44:50:429]         Not muted
[2022-07-11 12:44:50:429]         Channel #1 volume: 100 (0 dB FS)
[2022-07-11 12:44:50:429]         Channel #2 volume: 100 (0 dB FS)
[2022-07-11 12:44:50:429] 
[2022-07-11 12:44:50:429]     Active session #1  (DeActive) 
        Peak value: 0
        Icon path: @%SystemRoot%\System32\AudioSrv.Dll,-203
        Display name: @%SystemRoot%\System32\AudioSrv.Dll,-202
        Grouping parameter: {396d3088-eb5e-4c55-a2d0-0f83ad4da70f}
        Process ID: 0 (multi-process)
        Session identifier: {0.0.1.00000000}.{40177a8c-deca-4796-a08e-c0c093158d8e}|#%b{A9EF3FD9-4240-455E-A4D5-F2B3301887B2}
        Session instance identifier: {0.0.1.00000000}.{40177a8c-deca-4796-a08e-c0c093158d8e}|#%b{A9EF3FD9-4240-455E-A4D5-F2B3301887B2}|1%b#
        System sounds session: yes
[2022-07-11 12:44:50:429]         Master volume: 0 (-inf dB FS)
[2022-07-11 12:44:50:429]         Not muted
[2022-07-11 12:44:50:429]         Channel #1 volume: 100 (0 dB FS)
[2022-07-11 12:44:50:429]         Channel #2 volume: 100 (0 dB FS)
[2022-07-11 12:44:50:429] 
[2022-07-11 12:44:50:430]     Active session #2  (Active) 
        Peak value: 0.00055478
        Icon path: 
        Display name: 
        Grouping parameter: {8d5bcf46-5a2e-4e14-815e-8acea3308c0d}
        Process ID: 73404 (single-process)
        Session identifier: {0.0.1.00000000}.{40177a8c-deca-4796-a08e-c0c093158d8e}|\Device\HarddiskVolume4\workspace\WinMicTest\AudioTest\x64\Debug\AudioTest.exe%b{00000000-0000-0000-0000-000000000000}
        Session instance identifier: {0.0.1.00000000}.{40177a8c-deca-4796-a08e-c0c093158d8e}|\Device\HarddiskVolume4\workspace\WinMicTest\AudioTest\x64\Debug\AudioTest.exe%b{00000000-0000-0000-0000-000000000000}|1%b73404
        System sounds session: no
[2022-07-11 12:44:50:430]         Master volume: 50 (-6.0206 dB FS)
[2022-07-11 12:44:50:430]         Not muted
[2022-07-11 12:44:50:430]         Channel #1 volume: 100 (0 dB FS)
[2022-07-11 12:44:50:430]         Channel #2 volume: 100 (0 dB FS)
[2022-07-11 12:44:50:430] 
[2022-07-11 12:44:50:430] 
[2022-07-11 12:44:50:430] ------------------------

I'm using c/c++/c#

1 Answers1

0

You can query ISimpleAudioVolume from IAudioSessionControl as well and in this case it would be session specific volume.

Roman R.
  • 68,205
  • 6
  • 94
  • 158