Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix alsa mixer calculations #1229

Merged
merged 5 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
8 changes: 4 additions & 4 deletions src/alsa_mixer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
Expand Down Expand Up @@ -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 {
Expand Down
Loading