Skip to content

Commit

Permalink
Fix: AudioManager not clamping values (#176)
Browse files Browse the repository at this point in the history
* fixed command ignoring payload and not properly parsing integers with ".0"

* added clamp function around volume calculation

* tweaked log to include clamped scalar
  • Loading branch information
amadeo-alex authored Oct 4, 2024
1 parent 2dd00f2 commit 5fc4112
Showing 1 changed file with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -378,9 +378,9 @@ private static void SetDeviceProperties(MMDevice device, int volume, bool? mute)

if (volume != -1)
{
var volumeScalar = volume / 100f;
var volumeScalar = Math.Clamp(volume / 100f, 0, 1);
device.AudioEndpointVolume.MasterVolumeLevelScalar = volumeScalar;
Log.Debug($"[AUDIOMGR] volume for '{_devices[device.ID]}' set to '{volume}'");
Log.Debug($"[AUDIOMGR] volume for '{_devices[device.ID]}' set to '{volume}'/'{volumeScalar}'");
}
}

Expand Down Expand Up @@ -455,9 +455,9 @@ private static void SetSessionProperties(InternalAudioSession internalAudioSessi
if (volume == -1)
return;

var volumeScalar = volume / 100f;
var volumeScalar = Math.Clamp(volume / 100f, 0, 1);
internalAudioSession.Volume.Volume = volumeScalar;
Log.Debug("[AUDIOMGR] volume for '{sessionName}' ({sessionId}) set to '{vol}'", displayName, internalAudioSession.Control.GetSessionInstanceIdentifier, volume);
Log.Debug("[AUDIOMGR] volume for '{sessionName}' ({sessionId}) set to '{vol}'/'{volScal}'", displayName, internalAudioSession.Control.GetSessionInstanceIdentifier, volume, volumeScalar);
}

public static void Shutdown()
Expand Down

0 comments on commit 5fc4112

Please sign in to comment.