From e4deb5ddcdf8ec6683c1441ae0fb956bce8eae5a Mon Sep 17 00:00:00 2001 From: JasonLG1979 Date: Sat, 28 May 2022 09:08:50 -0500 Subject: [PATCH] Fix fixed volume with hardware mixer. fixes https://github.com/librespot-org/librespot/issues/1008 --- CHANGELOG.md | 1 + playback/src/mixer/alsamixer.rs | 32 +++++++++++++++++++++----------- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4e975209..24885534 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added ### Fixed +- [playback] `alsamixer`: make `--volume-ctrl fixed` work as expected when combined with `--mixer alsa` ### Removed diff --git a/playback/src/mixer/alsamixer.rs b/playback/src/mixer/alsamixer.rs index f03af958..a930d168 100644 --- a/playback/src/mixer/alsamixer.rs +++ b/playback/src/mixer/alsamixer.rs @@ -104,23 +104,33 @@ impl Mixer for AlsaMixer { let min_db = min_millibel.to_db() as f64; let max_db = max_millibel.to_db() as f64; - let mut db_range = f64::abs(max_db - min_db); + let reported_db_range = f64::abs(max_db - min_db); // Synchronize the volume control dB range with the mixer control, // unless it was already set with a command line option. - if !config.volume_ctrl.range_ok() { - if db_range > 100.0 { - debug!("Alsa mixer reported dB range > 100, which is suspect"); - warn!("Please manually set `--volume-range` if this is incorrect"); - } - config.volume_ctrl.set_db_range(db_range); - } else { + let db_range = if config.volume_ctrl.range_ok() { let db_range_override = config.volume_ctrl.db_range(); + if db_range_override.is_normal() { + db_range_override + } else { + reported_db_range + } + } else { + config.volume_ctrl.set_db_range(reported_db_range); + reported_db_range + }; + + if reported_db_range == db_range { + debug!("Alsa dB volume range was reported as {}", reported_db_range); + if reported_db_range > 100.0 { + debug!("Alsa mixer reported dB range > 100, which is suspect"); + debug!("Please manually set `--volume-range` if this is incorrect"); + } + } else { debug!( - "Alsa dB volume range was detected as {} but overridden as {}", - db_range, db_range_override + "Alsa dB volume range was reported as {} but overridden to {}", + reported_db_range, db_range ); - db_range = db_range_override; } // For hardware controls with a small range (24 dB or less),