From 7121ecb1910f3afab555799bf53a2fdd12b127af Mon Sep 17 00:00:00 2001 From: XangelMusic <22012301+XangelMusic@users.noreply.github.com> Date: Fri, 2 Feb 2024 03:59:20 +0800 Subject: [PATCH] fix(volume): Volume levels across dual-audio channels now kept for keep volume option (#1371) --- SoundSwitch.Audio.Manager/AudioSwitcher.cs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/SoundSwitch.Audio.Manager/AudioSwitcher.cs b/SoundSwitch.Audio.Manager/AudioSwitcher.cs index 54c9c9c72f..291ab27c2d 100644 --- a/SoundSwitch.Audio.Manager/AudioSwitcher.cs +++ b/SoundSwitch.Audio.Manager/AudioSwitcher.cs @@ -200,6 +200,7 @@ public void SetVolumeFromDefaultDevice(DeviceInfo device) var currentDefault = GetMmDefaultAudioEndpoint((EDataFlow)device.Type, ERole.eConsole); if (currentDefault == null) return; + var audioInfo = InteractWithMmDevice(currentDefault, mmDevice => { var defaultDeviceAudioEndpointVolume = mmDevice.AudioEndpointVolume; @@ -222,7 +223,15 @@ public void SetVolumeFromDefaultDevice(DeviceInfo device) if (mmDevice.AudioEndpointVolume == null) return nextDevice; - mmDevice.AudioEndpointVolume.MasterVolumeLevelScalar = audioInfo.Volume; + if (mmDevice.AudioEndpointVolume.Channels.Count == 2) + { + mmDevice.AudioEndpointVolume.Channels[0].VolumeLevelScalar = audioInfo.Volume; + mmDevice.AudioEndpointVolume.Channels[1].VolumeLevelScalar = audioInfo.Volume; + } + else + { + mmDevice.AudioEndpointVolume.MasterVolumeLevelScalar = audioInfo.Volume; + } mmDevice.AudioEndpointVolume.Mute = audioInfo.IsMuted; return mmDevice; });