diff --git a/CHANGELOG.md b/CHANGELOG.md index a8081550..17d887d6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,7 +12,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - Credential caching has been re-enabled. ([#1214]) +### Fixed +- alsa mixer: volume calculation has been fixed ([#1229]) + [#1214]: https://github.com/Spotifyd/spotifyd/pull/1214 +[#1229]: https://github.com/Spotifyd/spotifyd/pull/1229 [#1228]: https://github.com/Spotifyd/spotifyd/pull/1228 ## [0.3.5] diff --git a/src/alsa_mixer.rs b/src/alsa_mixer.rs index 09c40ebf..ed7f1b70 100644 --- a/src/alsa_mixer.rs +++ b/src/alsa_mixer.rs @@ -25,9 +25,9 @@ impl AlsaMixer { let volume_steps = (max - min) as f64; let normalised_volume = if self.linear_scaling { - ((f64::from(volume) / f64::from(u16::MAX)) * volume_steps) as i64 + min + (((volume as f64) / (u16::MAX as f64)) * volume_steps) as i64 + min } else { - (f64::from(volume).log(f64::from(u16::MAX)) * volume_steps).floor() as i64 + min + ((volume as f64 + 1.0).log((u16::MAX as f64) + 1.0) * volume_steps).floor() as i64 + min }; elem.set_playback_volume_all(normalised_volume)?; @@ -55,8 +55,8 @@ impl Mixer for AlsaMixer { elem.get_playback_volume(alsa::mixer::SelemChannelId::mono()) .ok() .map(|volume| { - let volume_steps = max - min + 1; - ((volume - min) * (0xFFFF / volume_steps)) as u16 + (((volume - min) as f64 / (max - min) as f64) * (u16::MAX as f64)).floor() + as u16 }) }); match vol {