Skip to content

Commit

Permalink
fix alsa_mixer volume calculations
Browse files Browse the repository at this point in the history
  • Loading branch information
eladyn committed Oct 15, 2023
1 parent 0a15027 commit 53b57c2
Showing 1 changed file with 4 additions and 4 deletions.
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_value())) * volume_steps) as i64 + min
(((volume as f64) / (u16::max_value() as f64)) * volume_steps) as i64 + min
} else {
(f64::from(volume).log(f64::from(u16::max_value())) * 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
})
}) {
Some(vol) => vol,
Expand Down

0 comments on commit 53b57c2

Please sign in to comment.